0

I am using cherrypy for a web server which is able to stream the output of some methods. Server uses yield to send lines of data and client uses onprogress event of $.ajax method.
But enabling 'tools.gzip' config of cherrypy caused the output not to be cached by the client. In fact the onprogress event of client is not called unless the server method is finished completely. It seems the cherrypy compression tool is not able to compress the output in streaming mode (it can compress the output only when get it completely).
Now my first question is how to fix this problem. If it is not fixable my second question is how to diable the cherrypy compression for a specific method.

mtoloo
  • 1,795
  • 3
  • 22
  • 28

1 Answers1

0

You have to enable the streaming capabilities of the request.

Set the following configuration:

{'response.stream': True}

The gzip tools inspect the current request and look for the stream and response accordingly.

For more information: http://docs.cherrypy.org/en/latest/advanced.html#streaming-the-response-body

cyraxjoe
  • 5,661
  • 3
  • 28
  • 42
  • The request is already streamed using `response.stream` configuration. The problem is on combining streaming and gzip features. – mtoloo Dec 31 '15 at 04:56
  • You're right. Apparently the gzip tool doesn't support streaming. I'll get more into the details tomorrow morning. – cyraxjoe Dec 31 '15 at 08:26
  • After some inspection into the gzip tool, it does seems that it should work with streaming. It returns a generator. Try to enable the debugging and see if something helpful gets in the log. `tools.gzip.debug: True` – cyraxjoe Jan 05 '16 at 07:09
  • 1
    I'm rather sure it doesn't wotk! I inspect the source code. In the `compress` method located at `encoding.py` file there's a `for` loop which compresses the body using `zobj` line by line and yield each line compressed. After the loop the `zobj.flush()` is yielded. Tracing the code, I found yields inside the `for` returns an empty string! But the yield out of `for` returns the whole data at once!! In the other word in practice the generator you mentioned does not work as expected. – mtoloo Jan 05 '16 at 12:12