Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Servlets and the fly likes Limit to number of  HTTP Response Headers? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Limit to number of  HTTP Response Headers?" Watch "Limit to number of  HTTP Response Headers?" New topic

Limit to number of HTTP Response Headers?

dave taubler
Ranch Hand

Joined: May 15, 2001
Posts: 132
This is a mixed-topic question (part HTTP, part Servlet, part J2ME) but I figured this forum is the best one to post in.

Anyhow, I have a MIDP app that regularly talks with a Servlet that is running on the Orion app server. Occasionally, information changes on the server, and that info needs to be synched in the MIDlet. So in such a situation, when the MIDlet pings the server, I pass a custom HTTP response header during the response to the MIDlet to tell it to change some internal value. Works like a champ.

In fact, this approach works so well that I want to expand its use, so that anytime a user makes a data entry/deletion/modification on the Web site (the Orion app server), that entry/deletion/modification gets sent as a header to the MIDlet. My concern is that, if the user decides to go hog-wild on the Web site in between MIDlet pings to the server, there could wind up being a lot of response headers that I need to send back to the MIDlet once it does ping. So my question: is there a hard limit to the number of HTTP headers that can be sent in an HTTP response? Or some theoretical limit? I'm looking online to see if I can find some limit defined either in the HTTP protocol, Servlet spec, or MIDP spec, but I can't find an answer either way.

Thanks in advance!
[ February 09, 2005: Message edited by: dave taubler ]

Dave Taubler<br />Specializing in <a href="" target="_blank" rel="nofollow">Java and Web Development</a>
Rigel Kentaurus

Joined: Feb 09, 2005
Posts: 11
I assume you are using HTTP 1.1, and doing several requests in the same connection.

HTTP does not define a limit, but your webserver does, for example apache in its configuration has something about how many requests could be made in the same connection, and how much idle time until he disconnects the client, I have not seen something similar in Orion.

Either way relying on this would be a bad idea since the webserver can change, it would be better if your midlet were smart enough to "reconnect" to the server in the event that his connection has been closed because of too many requests.
dave taubler
Ranch Hand

Joined: May 15, 2001
Posts: 132
Actually, I'm talking about a single request in this case, in which I would be adding multiple headers via

response.setHeader(key, value);

I'm just curious as to whether there is a max number of headers I can expect to successfully set in that manner.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

I don't think you're going to run into a finite number of headers allowed but I think you might run into a limit in the overall size of the header.

A google search on HTTP HEADER SIZE brings up articles like this:;en-us;310156&sd=tech
which indicate a fixed buffer size for headers which can vary from server to server.

There may be something in the HTTP specs concerning a minumum size.
You'd have to poke around a bit.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: Limit to number of HTTP Response Headers?
It's not a secret anymore!