public void testSendMultivaluedHeader() {
// Note: I am not sure how to retrieve multi valued headers. The
// problem is that I use
// URLConnection.setRequestProperty("testheader", "value1,value2") in
// JdkConnectionHelper to send the headers but request.getHeaders() does
// not seem to separate the different header values.
// The RFC 2616 says :
// message-header = field-name ":" [ field-value ]
// field-name = token
// field-value = *( field-content | LWS )
// field-content = < the OCTETs making up the field-value
// and consisting of either *TEXT or combinations
// of token, separators, and quoted-string >
// [...]
// 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.
// ... so it should be ok ...
assertEquals("value1,value2", request.getHeader("testheader"));
// Here is commented out what I would have thought I should have
// written to verify this test but it does not seem to work this way ...
/*
Enumeration values = request.getHeaders("testheader");
int count = 0;
while (values.hasMoreElements()) {
String value = (String)values.nextElement();
if (!(value.equals("value1") || value.equals("value2"))) {
fail("unknown value [" + value + "] for header [testheader]");
}
count++;
}
assertEquals("Should have received 2 values for header [testheader]",
2, count);
*/
}
Verify that we can simulate several HTTP header values with the same
header name. |