Server: post gzipped message and response (loooong post, sorry)

Malte Brill revolution at
Mon Jan 18 14:02:45 EST 2016

Hi all,

I am struggeling with something that used to work with the 5.x Server engine (on Mac but I need it X-Plat)

I am trying to POST compressed XML to Server and reply with compressed XML from there. With the 7.x engines of server this breaks:


local sPostDataCompressedFlag,sPostData
local sReply


command libServerReadIncomingData
  put $_POST_RAW into sPostData
  if sPostData is empty then
    exit libserverReadIncomingData
  end if
   --- if the data has been compressed, we need to decompress it
      put decompress(sPostData) into sPostData
      put TRUE into sPostDataCompressedFlag
   catch tErr
      put FALSE into sPostDataCompressedFlag
   end try
   --- parse out the XML data
   local tPostDataXml
   put revCreateXMLTree(sPostData, TRUE, TRUE, FALSE) into tPostDataXml
   local tPostDataRootNode,tPostDataActivity
   put revXmlRootNode(tPostDataXml) into tPostDataRootNode
   local tPostDataRequest
   put revXmlAttribute(tPostDataXml, tPostDataRootNode, "type") into tPostDataRequest
	switch (tPostDataRequest)
      	case "ping"
        	requestUnknown tPostDataXML
   end switch
end libServerReadIncomingData

command libServerReturnResponse
  if sReply is empty then
  	put "error: reply is empty" into sReply
  end if	
  if (sPostDataCompressedFlag) then
    put compress(sReply) into sReply
  end if
  put "Content-Type: text/xml" & CRLF into tHeader
  put "Content-Encoding: gzip" &CRLF after tHeader
  put "Content-Length:" && length(sReply) after tHeader
  put new header tHeader
  put sReply
end libServerReturnResponse

command libServerBuildReply pType, pData
  put "<?xml version=" & quote & "1.0" & quote && "encoding=" & quote & "UTF-8" & quote &"?>" into sReply
  put crlf & "<response type=" & quote & pType & quote &">DATA</response>" after sReply
  replace "DATA" with pData in sReply
end libServerBuildReply

command libServerRequestMethodError
  libServerBuildReply "error", "Requested method not supported"
end libServerRequestMethodError

command requestPing
  libServerBuildReply "ping", "<timestamp>" & the milliseconds & "</timestamp>" & CRLF & \
         "<info>ok</info>" & CRLF
end requestPing

command requestUnknown pRoot,pRequest
  libServerBuildReply "error", "<timestamp>" & the milliseconds & "</timestamp>" & CRLF & \
         "<error>unknown request:"&cr&pRoot&cr&length(sPostData)&"</error>" & CRLF
end requestUnknown


On The client Side I have:

on sendRequest pRequest,pCompress
   local tXML,tURL
   put "<?xml version=" & quote & "1.0" & quote && "encoding=" & quote & "UTF-8" & quote && "?>" into tXML
   put "<request type=" & quote & pRequest & quote &"/>" after tXML
   put fld "theURL" into tURL
   if pCompress then
      post compress(tXML) to URL tURL
      post tXML to URL tURL
   end if
   handleRequest it
end sendRequest

on handleRequest pResponse
      put decompress(pResponse) into fld "output"
   catch theErr
      put theErr & cr & cr & pResponse into fld "output"
   end try
end handleRequest

Now if I do a compressed version of my ping request:

      sendRequest "ping“,true

I get:

<?xml version="1.0" encoding=%UTF-8“?> — wrong here… Why the %???
<response type="ping"><timestamp>1453143362202</timestamp>

the uncompressed call:

<?xml version="1.0" encoding="UTF-8"?>
<response type="ping"><timestamp>1453143583747</timestamp>

works as expected. Even worse for:

      sendRequest "irgendwas“,true

Which comes back totally garbled most of the time…

Anybody got an idea what changed between 5.x and 7 that breaks compressed transfer? Anybody got a solution?



More information about the use-livecode mailing list