/** * Adds an array of {@link Cookie HTTP cookies}. Cookies are added individually and * in the given array order. If any of the given cookies has already expired it will * not be added, but existing values will still be removed. * * @param cookies the {@link Cookie cookies} to be added * * @see #addCookie(Cookie) * * */ public synchronized void addCookies(Cookie[] cookies) { LOG.trace("enter HttpState.addCookies(Cookie[])"); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { this.addCookie(cookies[i]); } } }
conn.isSecure(), cookie); state.addCookie(cookie); if (LOG.isDebugEnabled()) { LOG.debug("Cookie accepted: \""
public void addCookie(Cookie cookie) { httpState.addCookie(cookie); }
public void addCookie(Cookie cookie) { httpState.addCookie(cookie); }
/** * Adds an array of {@link Cookie HTTP cookies}. Cookies are added individually and * in the given array order. If any of the given cookies has already expired it will * not be added, but existing values will still be removed. * * @param cookies the {@link Cookie cookies} to be added * * @see #addCookie(Cookie) * * */ public synchronized void addCookies(Cookie[] cookies) { LOG.trace("enter HttpState.addCookies(Cookie[])"); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { this.addCookie(cookies[i]); } } }
/** * Adds an array of {@link Cookie HTTP cookies}. Cookies are added individually and * in the given array order. If any of the given cookies has already expired it will * not be added, but existing values will still be removed. * * @param cookies the {@link Cookie cookies} to be added * * @see #addCookie(Cookie) * * */ public synchronized void addCookies(Cookie[] cookies) { LOG.trace("enter HttpState.addCookies(Cookie[])"); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { this.addCookie(cookies[i]); } } }
/** * add cookie to state * @param state * @param cookie */ private void addCookie(HttpState state, String cookie,String host, String path, boolean secure) { int index = cookie.indexOf('='); state.addCookie(new Cookie(host, cookie.substring(0, index), cookie.substring(index + 1), path, null, secure)); }
/** * add cookie to state * @param state * @param cookie */ private void addCookie(HttpState state, String cookie,String host, String path, boolean secure) { int index = cookie.indexOf('='); state.addCookie(new Cookie(host, cookie.substring(0, index), cookie.substring(index + 1), path, null, secure)); }
/** * Manually add cookies */ public AbderaClient addCookies(Cookie cookie) { client.getState().addCookie(cookie); return this; }
/** * add cookie to state * @param state * @param cookie */ private void addCookie(HttpState state, String cookie,String host, String path, boolean secure) { int index = cookie.indexOf('='); state.addCookie(new Cookie(host, cookie.substring(0, index), cookie.substring(index + 1), path, null, secure)); }
/** * Updates the specified HTTP state's cookie configuration according to the current cookie settings. * @param state the HTTP state to update * @see #updateFromState(HttpState) */ protected synchronized void updateState(final HttpState state) { if (!cookiesEnabled_) { return; } state.clearCookies(); for (Cookie cookie : cookies_) { state.addCookie(cookie); } }
/** * Updates the specified HTTP state's cookie configuration according to the current cookie settings. * @param state the HTTP state to update * @see #updateFromState(HttpState) */ protected synchronized void updateState(final HttpState state) { if (!cookiesEnabled_) { return; } state.clearCookies(); for (Cookie cookie : cookies_) { state.addCookie(cookie); } }
/** * Updates the specified HTTP state's cookie configuration according to the current cookie settings. * @param state the HTTP state to update * @see #updateFromState(HttpState) */ protected synchronized void updateState(final HttpState state) { if (!cookiesEnabled_) { return; } state.clearCookies(); for (Cookie cookie : cookies_) { state.addCookie(cookie); } }
/** * Manually add cookies */ public AbderaClient addCookie(String domain, String name, String value) { Cookie cookie = new Cookie(domain, name, value); client.getState().addCookie(cookie); return this; }
/** * Manually add cookies */ public AbderaClient addCookie(String domain, String name, String value, String path, Date expires, boolean secure) { Cookie cookie = new Cookie(domain, name, value, path, expires, secure); client.getState().addCookie(cookie); return this; }
/** * Manually add cookies */ public AbderaClient addCookie(String domain, String name, String value, String path, int maxAge, boolean secure) { Cookie cookie = new Cookie(domain, name, value, path, maxAge, secure); client.getState().addCookie(cookie); return this; }
HttpState state = new HttpState(); state.addCookie(new Cookie(".example.com", "name", "value")); HttpClient client = new HttpClient(); client.setState(state); // ...
public MockBrowser(HttpClient httpClient) { _httpClient = httpClient; HttpConnectionManager connectionManager = httpClient.getHttpConnectionManager(); if (connectionManager instanceof MultiThreadedHttpConnectionManager) { _threadPool = Executors.newFixedThreadPool(10); } else { LOG.warn("The configured HttpClient does not use a MultiThreadedHttpConnectionManager, will only use 1 thread (instead of 10) for downloading CSS files and checking image URLs ..."); _threadPool = Executors.newFixedThreadPool(1); } HttpState httpState = new HttpState(); WebDriver driver = _webPage.getDriver(); for (org.openqa.selenium.Cookie cookie : driver.manage().getCookies()) { httpState.addCookie(new Cookie(cookie.getDomain(), cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getExpiry(), cookie.isSecure())); } _httpClient.setState(httpState); }
@Override public WebSession extractWebSession(HttpMessage msg) { if (msg.getRequestingUser() != null) return msg.getRequestingUser().getAuthenticatedSession(); else { // Make sure any cookies in the message are put in the session CookieBasedSession session = new CookieBasedSession(); for (HttpCookie c : msg.getRequestHeader().getHttpCookies()) session.getHttpState().addCookie(convertCookie(c)); // Use the messages hostname as default domain when generating SET cookies for (HttpCookie c : msg.getResponseHeader().getHttpCookies(msg.getRequestHeader().getHostName())) session.getHttpState().addCookie(convertCookie(c)); return session; } }
/** * Load in all the cookies WebDriver currently knows about so that we can mimic the browser cookie state * * @param seleniumCookieSet * @return */ private HttpState mimicCookieState(Set<org.openqa.selenium.Cookie> seleniumCookieSet) { HttpState mimicWebDriverCookieState = new HttpState(); for (org.openqa.selenium.Cookie seleniumCookie : seleniumCookieSet) { Cookie httpClientCookie = new Cookie(seleniumCookie.getDomain(), seleniumCookie.getName(), seleniumCookie.getValue(), seleniumCookie.getPath(), seleniumCookie.getExpiry(), seleniumCookie.isSecure()); mimicWebDriverCookieState.addCookie(httpClientCookie); } return mimicWebDriverCookieState; }