2

I try to create an application in web2py framework. By default web2py server has Transfer-Encoding: Chunked header for response, but in that case when target remote web application sends GET request to my app it could get only first string of text from requested page (from file's content that displayed on page). If to use Content-Length instead, for example, with value of 1000 it will get 1000 bytes of data from page... But if I expect to response with huge range of data, how to set Content-Length parameter to infinity or by file (like here but with web2py syntax instead of php )?

Community
  • 1
  • 1
  • Why do you now know the size of your response in the first place? Not sure I understand – Pekka Aug 07 '15 at 07:32
  • files could be various with different sizes, so I don't know what size of response will actually be, so I need to response with all data, that file contain, no matter what size is – Alehandro Ramoz Rodrigez Aug 07 '15 at 07:39
  • Then I suppose the solution is not to send a `content-length` header in the first place. (Edit: this Wikipedia article seems to suggest the same: https://en.wikipedia.org/wiki/Chunked_transfer_encoding) – Pekka Aug 07 '15 at 07:41
  • Original question answered [here](http://stackoverflow.com/a/31882961/440323). In short, use `response.stream` rather than `Expose` to serve the files, in which case, the Content-Length header will be set. – Anthony Aug 07 '15 at 17:13

1 Answers1

0

If you are serving web2py via the built-in development server and serving files via the Expose functionality, then the files will be served via chunked transfer encoding.

However, if you instead use response.stream to serve files, the Content-Length header will be set automatically.

Anthony
  • 25,466
  • 3
  • 28
  • 57