commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rodney Waldhoff" <rw...@hotmail.com>
Subject Re: HTTP Client API comment and Q about HttpException
Date Mon, 03 Dec 2001 01:20:30 GMT
>To get the value of a HTTP response header (e.g. 'text/html' part in 
>'Content-type: text/html' header) I have to do this:
>
>Header header = .... header.getValues()[0].getName();
>
>Wouldn't it make more sense to call getValue() instead of getName()?

Yes, and you can. What you want is:

Header header = ....
header.getValue();

The getValues() approach will coincidentally work but is provided to handle 
a more complex case, namely when a header has multiple (typically semi-colon 
separated) elements.  An example may help clarify:

(this is from memory, but I'm pretty sure it's accurate)

Given:

Set-Cookie: cname=cvalue;path=/;domain=.apache.org;secure

then header.getValue() will  return:

cname=cvalue;path=/;domain=.apache.org;secure

but header.getValues() will return an array of 4 HeaderElements:

header.getValues()[0].getName() => cname
header.getValues()[0].getValue() => cvalue
header.getValues()[1].getName() => path
header.getValues()[1].getValue() => /
header.getValues()[2].getName() => domain
header.getValues()[2].getValue() => .apache.org
header.getValues()[3].getName() => secure
header.getValues()[3].getValue() => null

>Also, it looks like HTTP Client is super strict and throws HttpException 
>when it encounters responses such as

>200 OK [...]

>What is it not getting that it needs?

I'm guessing that it is the "Reason-Phrase" part of the "Status-Line" 
production, which may be strictly required by the RFC, but I'd agree that we 
shouldn't choke on its absence.  That's a bug, I'll try to address it in the 
morning.

- Rod

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message