How does GMail implement Comet?
Asked Answered
D

1

14

With the help of HttpWatch, I tried to figure out how GMail implements Comet.

I login in to GMail with two accounts, one in IE and the other in Firefox. Chatting in GTalk in GMail with some magic words like "WASSUP". Then, I logoff both GMail accounts, filter any http content without "WASSUP" string. The result shows which HTTP request is the streaming channel. (Note: I have to logoff. Otherwise, never-ending HTTP would not show content in HttpWatch.)

The result is interesting. The URL for stream channel is like:

https://mail/channel/bind?VER=8&at=xn3j33vcvk39lkfq.....

There is no surprise that GMail do Comet in IE with IFRAME. The Http content starts with "<html><body>".

Originally, I guessed that GMail does Comet in Firefox with multipart XmlHttpRequest. To my surprise, the response header doesn't have "multipart/x-mixed-replace" header. The response headers are as below:

HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Sat, 20 Mar 2010 01:52:39 GMT
X-Frame-Options: ALLOWALL
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
Server: GSE
X-XSS-Protection: 0

Unfortunately, the HttpWatch doesn't tell whether a HTTP request is from XmlHttpRequest or not. The content is not HTML but JSON. It looks like a response for XHR, but that would not work for Comet without multipart/x-mixed-replace, right?

Is there any way else to figure out how GMail implements Comet?

Update: After further investigation, I believe GMail implements Comet this way: 1) in IE, it use a forever-hidden-iframe; 2) in Firefox, it use forever-XHR without multipart/x-mixed-replace header. The client will response in conditon (readyState == 3) OR (readyState == 4). That is, in both interactive state and complete state.

Duck answered 20/3, 2010 at 2:39 Comment(0)
T
15

Per this article,

So what is the solution used by Google Gmail?

The solution is really simple, straight forward and very portable! What Gmail did is requesting an endless html page that contains streams of Javascript portions. Give it a try, It’s very powerful. So, we will have on the client side a js file that processes the responses, and another endless html that contains the Javascript Streams.

The rest of the article goes into much more detail, including an exploration of alternatives as well as the specific one picked by GMail.

Tannatannage answered 20/3, 2010 at 2:50 Comment(5)
It is a good article. But, it still doesn't explain why GMail choose JSON as response in Firefox.Duck
@Morgan, JSON's a nice way indeed to package data, especially though not exclusively for Javascript's use -- cfr ajaxian.com/archives/json-vs-xml-the-debate and (esp.) the many links therefrom. With chunked transfer-encoding, it works fine... at least in decently standard-compliant browsers;-).Tannatannage
Hi, tried waybackmachine for the article because the article is down. Can you deliver another link? Thanks!!Quickfreeze
Not sure what you mean by "the article is down" -- just visited ajaxian.com/archives/json-vs-xml-the-debate and it's right there.Tannatannage
I think @DOCASAREL is referring to the link in the Answer.Ordinand

© 2022 - 2024 — McMap. All rights reserved.