views:

250

answers:

3

Although HTTP is ubiquitous it comes with its baggage of Headers which in my case is becoming more of a problem. My data to be transferred is an iota of the HTTP header size.

  • Is there another protocol that I can use which is still understood by the browsers and other networks and doesn't come with the baggage of HTTP?
  • Any other way to skip headers and add it at the destination so only a miniscule of data is transferred over the network?
+6  A: 
  1. No.
  2. No.

Many HTTP headers are optional. A typical browser request is much larger than a minimal request, which might look like:

GET /doc HTTP/1.1
Host: example.com
Connection: close

(I can say with confidence that requests of this form work because I use them all the time when testing Web server response via telnet example.com 80.)

Possibly you can get useful results simply by omitting some headers.

chaos
Wow! this looks good, could we get around with just that minimal header?
Kevin Boyd
Possibly. It all depends on what 'get around' means.
chaos
I am using Java ME to send requests, is there a mechanism to null out the other headers, or should we send empty strings for them?
Kevin Boyd
Sorry, I'm unfamiliar with Java ME. You'll need to look into its documentation or ask someone who knows what it does.
chaos
IIRC "connection" is "closed" by default and not necessary to specify.
some
@some: HTTP 1.0 defaults to `connection: close`, HTTP 1.1 defaults to `connection: keep-alive`.
Tim Sylvester
+2  A: 

WebSockets are coming in HTML5 and should suit your needs. A standard HTTP connection can be renegotiated to change protocol to websockets. But I suspect the specification might be a bit young, but it might fit the bill.

krosenvold
Has it already been implemented?
Kevin Boyd
I think so; I saw some guys from a company called kaazing demonstrate it. Don't expect much browser support yet though.
krosenvold
+4  A: 

HTTP requests can be quite small. As chaos points out in his answer, you don't really need to send many headers with a request. The only header that's essential is Host. I can simplify chaos' example a bit more by using HTTP 1.0, which doesn't feature persistent connections.

GET / HTTP/1.0
Host: example.com
                                       (blank line is necessary)

The reply can be similarly simple

HTTP/1.0 200 OK
Content-Type: text/html

data content

In this case, the overhead of HTTP is about 40 bytes in the request and the response. A standard TCP packet is 1500 bytes so you have plenty of room left over in the response packet for the actual data.

There are other HTTP headers, and they do have value. You can include cache information and do conditional GETs. You can use an HTTP/1.1 persistent socket to make subsequent requests faster. Etc, etc. You don't have to use any of this stuff if you don't want, but one nice thing about HTTP is there's a standard way to do more complicated protocols when you need it.

As for doing minimal HTTP in JavaME, if you really care about every byte you may be best off writing your own simple HTTP client by working with a plain TCP socket. If you're talking to a known server you don't need to implement much at all. (If you're talking to arbitrary servers, you need to pay more attention to error handling, redirects, etc).

Nelson
Although it is STRONGLY frowned upon by the HTTP RFC, you can get rid of the "Host" header in the request, too -- as long as the server you are contacting is not a multi-homed web server (i.e. multiple web sites/domains sharing a single IP address). See http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.6.1.1
Marc Novakowski