Hi Jean-Marc, Oleg,
Thanks for your replies.
I think I found the relevant part of the spec:
rfc2616.pdf: page 17:
Many HTTP/1.1 header field values consist of words separated by LWS
or special characters. These special characters MUST be in a quoted
string to be used within a parameter value (as defined in section
3.6).
token = 1*<any CHAR except CTLs or separators>
separators = "(" | ")" | "<" | ">" | "@"
| "," | ";" | ":" | "\" | <">
| "/" | "[" | "]" | "?" | "="
| "{" | "}" | SP | HT
I noticed that GET request
http://www.livejasmin.com/listpage.php?tags=girl&type=40&openQuicklist
(not for the faint of heart: it's a porn website)
generates a response with a Set-Cookie where the ',' in the expires date
was not quoted.
Is this something that a client program must be aware of, and somehow take
care of?
Below my test program that tries to parse the expires date, and fails;
Does it contain any errors?
Kind regards,
Paul.
public class InvalidSetCookieProblem {
public static void main(String[] args) throws
ClientProtocolException, IOException {
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(
"http://www.livejasmin.com/listpage.php"
+ "?tags=girl&type=40&openQuicklist");
HttpResponse response = httpClient.execute(httpGet);
System.out.println(response.getStatusLine());
Header[] headers = response.getHeaders("Set-Cookie");
processHeaders0(headers);
processHeaders1(headers);
httpClient.getConnectionManager().shutdown();
}
private static void processHeaders0(Header[] headers) {
for(Header header : headers) {
System.out.println(""+header);
}
}
private static void processHeaders1(Header[] headers) {
for (Header header : headers) {
System.out.println("Header: " + header.getName() + " : "
+ header.getValue());
String hn = header.getName();
String hv = header.getValue();
BasicClientCookie2 bcc2 = new BasicClientCookie2(hn, hv);
HeaderElement[] elements = header.getElements();
for (HeaderElement elem : elements) {
NameValuePair[] pairs = elem.getParameters();
for (NameValuePair pair : pairs) {
System.out.println("NameValuePair: " + pair.getName() + " : "
+ pair.getValue());
String pn = pair.getName();
String pv = pair.getValue();
if (pn.equals("expires")) {
SimpleDateFormat sdf = new SimpleDateFormat(
"EEE, dd-MMM-yyy HH:mm:ss zzz",
DateFormatSymbols.getInstance(new Locale("en")));
Date d = null;
try {
d = sdf.parse(pv);
}
catch (ParseException e) {
System.out.println(e);
}
bcc2.setExpiryDate(d);
}
}
}
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]