I see lots of information about enabling http compression for server responses but what about for incoming requests. Wouldn't it make sense for the browsers to compress large form posts before sending them to the server?
Another example is a REST web service that we use. We have to send frequent PUT requests with large XML files (10+ MB) and would definitely see some bandwidth/speed benefits on both sides.
So is this a solved problem on the server side or does each web application have to handle it individually?
To
PUT
data to the server compressed you must compress the request body and set theContent-Encoding: gzip
header. The header itself must be uncompressed. It's documented in mod_deflate:And an article describing it is here:
Separately, a browser can request server response content to be compressed by setting
Accept-Encoding
header as per here:This will return compressed data to the browser.
Answering the part about compressed requests, not responses: yes, it is possible, even if it does not seem in widespread usage. The client-side app needs to set the appropriate content-encoding header. As for the server-side app, there are 2 choices:
the app supports reinflating the request body by itself. An example library which can do this is the phpxmlrpc one.
the webserver inflates the response body before passing it to the app. This is possible using f.e. the mod_deflate filter of Apache and setting up an inputFilter
Not natively from any browser I know of, you'd have to find a plugin that would do it for you. You basically have to set the content-encoding HTTP header to let the server know how the request is coming in. The server, of course, needs to be able to handle that encoding.
Below code is setup the custom header and pass this header in api call as http options :
After that while you calling the API to get the data , pass the options with url:
This is NOT allowed. According to the HTTP specification (RFC 2616),
Content-Encoding
is NOT one of the possible request header fields, therefore it is not possible to compress the request entity body as there is no legal way to let the server know this has occurred. Any compression of the request body is done only as a non-standard extension.