Jaikiran Pai wrote:You have to be patient, it's just been 3 hours since you asked the question and it's a weekend too. If anyone knows the answer they'll reply.
As for the question, I'm not sure what the spec says about duplicate request headers. If those are allowed, then your application probably should consider what it means to have different values for the same header. For example, how do you decide which header value is more appropriate?
aries dimagiba wrote:As for the specs, duplicate request header names are not allowed
Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma. The order in which header fields with the same field-name are received is therefore significant to the interpretation of the combined field value, and thus a proxy MUST NOT change the order of these field values when a message is forwarded.
Ulf Dittmer wrote:
aries dimagiba wrote:As for the specs, duplicate request header names are not allowed
That's not correct. According to the HTTP spec,
Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma. The order in which header fields with the same field-name are received is therefore significant to the interpretation of the combined field value, and thus a proxy MUST NOT change the order of these field values when a message is forwarded.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
Richard Tookey wrote:The interface ServletRequest deleclares a method
aries dimagiba wrote:
Richard Tookey wrote:The interface ServletRequest deleclares a method
Thanks for the reply Sir. Can I extract the duplicated headers with that method?
Richard Tookey wrote:
How about reading the Javadoc for the method and then writing a quick test Servlet if you are still not sure.
Jaikiran Pai wrote:Please read the text that Ulf has quoted. It clearly explains how those values will be represented, the delimiter and even the order of those values. All you have to do is parse it as per your needs.
aries dimagiba wrote:
Richard Tookey wrote:
How about reading the Javadoc for the method and then writing a quick test Servlet if you are still not sure.
I've tried that Sir but I think that method is concerned only on parameters being passed, not on the request headers.
Richard Tookey wrote:
aries dimagiba wrote:
Richard Tookey wrote:
How about reading the Javadoc for the method and then writing a quick test Servlet if you are still not sure.
I've tried that Sir but I think that method is concerned only on parameters being passed, not on the request headers.
Sorry I misunderstood your requirement. Please ignore everything I posted on this.
aries dimagiba wrote:
Jaikiran Pai wrote:Please read the text that Ulf has quoted. It clearly explains how those values will be represented, the delimiter and even the order of those values. All you have to do is parse it as per your needs.
I see Sir, however, i dont know how to parse that using Java. Can you show me how? Thanks.
Jaikiran Pai wrote:
aries dimagiba wrote:
Jaikiran Pai wrote:Please read the text that Ulf has quoted. It clearly explains how those values will be represented, the delimiter and even the order of those values. All you have to do is parse it as per your needs.
I see Sir, however, i dont know how to parse that using Java. Can you show me how? Thanks.
I just spent a few seconds to see if there are already available APIs for this. Guess what http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getHeaders%28java.lang.String%29
Jaikiran Pai wrote:Are you saying the other value for the header name isn't being passed on to your application at all?
Jaikiran Pai wrote:How are those duplicates headers being added?
Jaikiran Pai wrote:By the way, you asked the same question here http://stackoverflow.com/questions/12652182/catching-duplicate-request-headers-with-httpservletrequest which is fine, but when asking the same question in multiple different forums, please do let others know about it.
Header name: host header value: localhost:8080
Header name: accept header value: */*
Header name: foo header value: bar
Header name: foo header value: baragain
Header name: abc header value: xyz
Jaikiran Pai wrote:I just did a quick test with my local Tomcat installation and used curl as the client to send those duplicate headers. It worked fine. The server side (Tomcat) application received those duplicate headers and printed both the values. It's the same code as yours:
The curl client invocation was:
The output was:
Printing headers:
Header name: host header value: localhost:8080
Header name: accept header value: */*
Header name: foo header value: bar
Header name: foo header value: baragain
Header name: abc header value: xyz
As you can see the "foo" header was received with 2 different values. So I believe this isn't a Tomcat issue. I'm on Tomcat 5.5.x by the way. You'll have to check with the cocoa-rest-client to make sure the headers are indeed being passed with different values.
aries dimagiba wrote: i did test it using curl command and the duplicate headers were really detected and my application threw the error I expected
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |