Angus & co

I have enabled content encoding on my THTTPServer:

    SizeCompressMin      = 5000;
    SizeCompressMax      = 5000000;
    Options              = Options << hoContentEncoding;

And return content to my client using AnswerString

    String sResponseHeader =
        pClientCnx->Version +
        "\r\nPragma: no-cache\r\n"
        "Expires: -1\r\n"
        "Access-Control-Allow-Origin: " + sReferer + "\r\n";

    pClientCnx->AnswerString(Flags,
                             "200 OK",
                             "application/json",
                             sResponseHeader,
                             sResponseBody);


However if my client includes "Accept-Encoding: gzip" in its request header the OnHttpContentEncode event is not called.

Looking in the source I see:

{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} function THttpConnection.CheckContentEncoding(const ContType : String): boolean; { V7.21 are we allowed to compress content }
begin
    Result := False;
if NOT (hoContentEncoding in FServer.Options) then exit; { V7.20 are we allowed to compress content } if (ContType = '') or (Pos ('text/', ContType) > 0) or (Pos ('xml', ContType) > 0) then begin { only compress textual stuff } if (FDocStream.Size < FServer.SizeCompressMin) then exit; { too small a waste of time } if (FDocStream.Size > FServer.SizeCompressMax) then exit; { too large will block server and use a lot of memory }
       Result := True;
    end;
end;


What is the recommended way to correctly return gzip json content? Or is it intended I should be performing the gzip logic before calling AnswerString?



--

Regards

Paul Read
Partner

Find us on Facebook: http://www.facebook.com/nSolve

nSolve Ltd
33-35 Daws Lane
London NW7 4SD
England

www.nsolve.com
www.ntasktic.com

Tel: +44 (0) 1993 40 20 11
Tel(US): +1 617 273 2304

--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to