org.apache.http.impl.cookie.DefaultCookieSpec Java Examples
The following examples show how to use
org.apache.http.impl.cookie.DefaultCookieSpec.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CookieManager3Test.java From htmlunit with Apache License 2.0 | 5 votes |
/** * Test that " are not discarded. * Once this test passes, our hack in HttpWebConnection.HtmlUnitBrowserCompatCookieSpec can safely be removed. * @see <a href="https://issues.apache.org/jira/browse/HTTPCLIENT-1006">HttpClient bug 1006</a> * @throws Exception if the test fails */ @Test public void httpClientParsesCookiesQuotedValuesCorrectly() throws Exception { final Header header = new BasicHeader("Set-Cookie", "first=\"hello world\""); final DefaultCookieSpec spec = new DefaultCookieSpec(); final CookieOrigin origin = new CookieOrigin("localhost", 80, "/", false); final List<org.apache.http.cookie.Cookie> list = spec.parse(header, origin); assertEquals(1, list.size()); assertEquals("\"hello world\"", list.get(0).getValue()); }
Example #2
Source File: HttpResponseUtils.java From esigate with Apache License 2.0 | 5 votes |
/** * Removes ";jsessionid=<id>" from the url, if the session id is also set in "httpResponse". * <p> * This methods first looks for the following header : * * <pre> * Set-Cookie: JSESSIONID= * </pre> * * If found and perfectly matches the jsessionid value in url, the complete jsessionid definition is removed from * the url. * * @param uri * original uri, may contains a jsessionid. * @param httpResponse * the response which set the jsessionId * @return uri, without jsession */ public static String removeSessionId(String uri, HttpResponse httpResponse) { CookieSpec cookieSpec = new DefaultCookieSpec(); // Dummy origin, used only by CookieSpec for setting the domain for the // cookie but we don't need it CookieOrigin cookieOrigin = new CookieOrigin("dummy", Http.DEFAULT_HTTP_PORT, "/", false); Header[] responseHeaders = httpResponse.getHeaders("Set-cookie"); String jsessionid = null; for (Header header : responseHeaders) { try { List<Cookie> cookies = cookieSpec.parse(header, cookieOrigin); for (Cookie cookie : cookies) { if ("JSESSIONID".equalsIgnoreCase(cookie.getName())) { jsessionid = cookie.getValue(); } break; } } catch (MalformedCookieException ex) { LOG.warn("Malformed header: " + header.getName() + ": " + header.getValue()); } if (jsessionid != null) { break; } } if (jsessionid == null) { return uri; } return UriUtils.removeSessionId(jsessionid, uri); }