Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does a http client associate an http response with a request (with Netty) or in general?

Tags:

http

nio

netty

Is a http end point suppose to respond to requests from a particular client in order that they are received?

What about if it doesn't make sense to in the case of requests handled by cluster behind a proxy or in requests handled with NIO where one request is finished faster than the other?

Is there a standard way of associating a unique id with each http request to associate with the response? How is this handled in clients like http componenets httpclient or curl?

The question comes down to the following case:

Suppose, I am downloading a file from a server and the request is not finished. Is a client capable of completing other requests on the same keep-alive connection?

like image 712
MetaChrome Avatar asked Sep 05 '11 10:09

MetaChrome


People also ask

What are the 3 parts to a HTTP response message?

An HTTP response contains: A status line. A series of HTTP headers, or header fields. A message body, which is usually needed.

What might cause your client to have to send several HTTP requests?

8.1. A client that supports persistent connections MAY "pipeline" its requests (i.e., send multiple requests without waiting for each response). A server MUST send its responses to those requests in the same order that the requests were received.

How is an HTTP connection established?

In client-server protocols, it is the client which establishes the connection. Opening a connection in HTTP means initiating a connection in the underlying transport layer, usually this is TCP. With TCP the default port, for an HTTP server on a computer, is port 80. Other ports can also be used, like 8000 or 8080.

Which request header will continue the client's session?

The HTTP keep-alive header maintains a connection between a client and your server, reducing the time needed to serve files.


1 Answers

Whenever a TCP connection is opened, the connection is recognized by the source and destination ports and IP addresses. So if I connect to www.google.com on destination port 80 (default for HTTP), I need a free source port which the OS will generate.

The reply of the web server is then sent to the source port (and IP). This is also how NAT works, remembering which source port belongs to which internal IP address (and vice versa for incoming connections).

As for your edit: no, a single http connection can execute one command (GET/POST/etc) at the same time. If you send another command while you are retreiving data from a previously issued command, the results may vary per client and server implementation. I guess that Apache, for example, will transmit the result of the second request after the data of the first request is sent.

like image 122
CodeCaster Avatar answered Sep 20 '22 19:09

CodeCaster