Module org.htmlunit

Class HttpClientConverter

java.lang.Object
org.htmlunit.httpclient.HttpClientConverter

public final class HttpClientConverter extends Object
Helper methods to convert from/to HttpClient.
Author:
Ronald Brill
  • Method Details

    • buildCookieOrigin

      public static org.apache.http.cookie.CookieOrigin buildCookieOrigin(URL url)
      Helper that builds a CookieOrigin.
      Parameters:
      url - the url to be used
      Returns:
      the new CookieOrigin
    • replaceForCookieIfNecessary

      public static URL replaceForCookieIfNecessary(URL url)
      CookieOrigin doesn't like empty hosts and negative ports, but these things happen if we're dealing with a local file. This method allows us to work around this limitation in HttpClient by feeding it a bogus host and port.
      Parameters:
      url - the URL to replace if necessary
      Returns:
      the replacement URL, or the original URL if no replacement was necessary
    • parseCookie

      public static List<Cookie> parseCookie(String cookieString, URL pageUrl, BrowserVersion browserVersion) throws org.apache.http.cookie.MalformedCookieException
      Parameters:
      cookieString - the string to parse
      pageUrl - the page url as root
      browserVersion - the BrowserVersion
      Returns:
      a list of Cookie's
      Throws:
      org.apache.http.cookie.MalformedCookieException - in case the cookie does not conform to the spec
    • toHttpClient

      public static List<org.apache.http.cookie.Cookie> toHttpClient(Collection<Cookie> cookies)
      Converts the specified collection of cookies into a collection of HttpClient cookies.
      Parameters:
      cookies - the cookies to be converted
      Returns:
      the specified cookies, as HttpClient cookies
    • addMatching

      public static void addMatching(Set<Cookie> cookies, URL normalizedUrl, BrowserVersion browserVersion, Set<Cookie> matches)
      Adds all matching cookies to the provided set.
      Parameters:
      cookies - the cookies to select from
      normalizedUrl - the url to match against
      browserVersion - the BrowserVersion
      matches - the set to add