Is there a way to decompress client's request body in nginx? - nginx

The client gzips post body, and I want the nginx decompress post body first, then passes the decompressed content to backend web server.
I can only find the way to compress response to client.
Any solution?
Thanks first!

Related

Do clients normally send http headers

Just a quick question, and probably a stupid one.
But usually when a client connects to an http server, the server sends them the header and the html, correct?
I'm packet sniffing a realtime-chat, and attempting to reverse engineer a plain text protocol, and it's connected to a http server. This is why I ask, for verification.
Basically, this is correct. Anyways, you have to differentiate between for example GET and POST Requests.
While POST Requests normally have a "real" body with information that they are delivering to the Server, the body of GET Requests is empty for most of the time.
For the responses, your Claim is correct. The Header is sent to tell how big the response is, which MIME Type is used, etc.

How is file content sent to browser after HTTP response returns?

When initiating a file download from the browser, I would send the server a request for the file. I know that the server then returns a response with content-type either as attachment or application/octect-stream. This lets the browser know that it should initiate the file download.
What I want to know is, how is the file data sent from the server to the client once the response has already be returned? Does it use a different protocol than http? is it always streamed from the server? or is the full file content sent in the response and then the browser just downloads it onto the client machine without maintaining a connection to the remote server?
Is there a way to know when this process has finished from either the server or the client?
The content of the the file being downloaded is included in the response. Response headers are followed by an empty line and then you have actual file data.

Is it legitimate http/rest to have requests that are compressed?

I asked this question a few days ago, and I didn't get a lot of activity on it. And it got me thinking that perhaps this was because my question was nonsensical.
My understanding of http is that a client (typical a browser) sends a request (get) to a server, in my case IIS. Part of this request is the accept-encoding header, which indicates to the server what type of encoding the client would like the resource returned in. Typically this could include gZip. And if the server is set up correctly it will return the resource requested in the requested encoding.
The response will include a Content-Encoding header indicating what compression has been applied to the resource. Also included in the response is the Content-Type header which indicates the mime type of the resource. So if the response includes both Content-Type : application/json and Content-Encoding: gzip, the client knows that resource is json that is has been compressed using gzip.
Now the scenario I am facing is that I am developing a web service for clients that are not browsers but mobile devices, and that instead of requesting resources, these devices will be posting data to the service to handle.
So i have implemented a Restfull service that accepts post request with json in the body. And my clients send their post requests with Content-Type:Application/json. But some of my clients have requested that they want to compress their request to speed up transmission. But my understanding is the there is no way to indicate in a request that the body of the request has been encoded using gZip.
That is to say there is no content-Encoding header for requests, only responses.
Is this the case?
Is it incorrect usage of http to attempt to compress requests?
According to another answer here on SO, it is within the HTTP standard to have a Content-Encoding header on the request and send the entity deflated.
It seems that no server automatically inflates the data for you, though, so you'll have to write the server-side code yourself (check the request header and act accordingly).

What HTTP request headers are important/commonly used?

I'm writing a web server, and I'd like to know what HTTP request headers (sent by the client) are the most common and thus that I should focus on implementing.
Right now, I only support Accept and Host.
Not sure on your scope but since you are interested in serving web browsers, you should have a look into the RFC (HTTP 1.1)
Read about what the server MUST process
The Cookie header might be a good idea, as would the Content-Length header; without Content-Length you won't be able to handle POST and PUT requests properly.

tomcat compression

If compression is setup on tomcat, will it also compress data that is uploaded by the client - via browser/applet ?
No, it won't. It only applies on the server response. The client has to compress the request data itself. It makes no sense to send the data from the client uncompressed over network to the server first and then compress over there. It won't have any benefits (i.e. saving network bandwidth and so on).
Compression of HTTP requests is however not part of the HTTP specification since a client can't know beforehand if a server would support it. It has to fire a whole request first. It's only specified for the HTTP responses. The server can determine based on the Accept-Encoding request header if the client supports compression or not and then handle accordingly.
In an applet, you can consider to send the data compressed using GZIPOutputStream. You'll only need to develop a specific servlet on the server side which listens on requests from the applet only and knows that it needs to decompress the HttpServletRequest#getInputStream() accordingly using GZIPInputStream

Resources