Re: HTTP ping pong
Roedy Green wrote:
Over time I have been learning how browsers and servers talk to each
other.
It seems to work like this:
Your browsers sets a GET or POST.
The server responds with web page.
In the web page are a number of images.
the browser then simultaneously sends some more get requests. I think
each one gets its own socket. data seems to flow back simultaneously
(interleaved packets).
Kind of. Generally what happens is the web-browser will fetch external
data (images, JS, CSS) a few at a time. Also, HTTP supports reusing a
connection, so it may be that your browser opens at most three
connections, and reuses them for all the page content.
Sometimes there is a redirect. I think it is normally up to the
browser to request the next leg and wait for the response. Other
times the server can handle the redirect itself and send something
with a note in the header where the new home is.
Either way, it is up to the "User Agent" to respect the Location header
There are two flavours of redirect, temporary and permanent. Temporary
ones are used for load balancing, redirecting to a backup server etc.
Permanent ones the server wants to you note, and use the new URL
instead. Temporary redirects will likely soon point nowhere.
You probably will benefit from reading the HTTP RFC's. I'm working
offline, or I'd fine the exact number/link for you. Google knows.
There are a couple of things I have not yet figured out.
1. If I login for example sometimes I see a page on the browser, then
that page is replaced by another page a few seconds like. I did not
touch the keyboard. What happened?
One answer: Javascript.
Another answer: The web-browser may decide to continue rendering the old
content until the new content is loaded.
2. Does the sever ever send more than one response to the same
request?
I believe there are ways to do this. I've heard the term "continuation"
in this regard, but I haven't looked into it myself.
3. How do popups work. How can a server send you something you did not
request?
The request is hidden in a regular page. Javascript is often involved.
4. At the Java HTTP level, does do you know when you have hit the end
of the data? an EOF exception or something else?
The HTTP protocol covers this. In chunked mode, it will tell you that
there are more chunks. In non-chunked mode, it will tell you the
content-length. Each of those are headers.
As you might guess, I am feeling an urge to write a little essay
called HTTP ping pong.
If you want to deep-dive, the HTTP RFC is a great resource, and also
look at commons-httpclient for a fully Java HTTP client solution.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>