Esempio n. 1
0
 public RequestImpl(Request prototype) {
   if (prototype != null) {
     this.method = prototype.getMethod();
     this.originalUri = prototype.getOriginalURI();
     this.address = prototype.getInetAddress();
     this.localAddress = prototype.getLocalAddress();
     this.headers = new FluentCaseInsensitiveStringsMap(prototype.getHeaders());
     this.cookies = new ArrayList<Cookie>(prototype.getCookies());
     this.byteData = prototype.getByteData();
     this.stringData = prototype.getStringData();
     this.streamData = prototype.getStreamData();
     this.bodyGenerator = prototype.getBodyGenerator();
     this.params =
         (prototype.getParams() == null ? null : new FluentStringsMap(prototype.getParams()));
     this.queryParams =
         (prototype.getQueryParams() == null
             ? null
             : new FluentStringsMap(prototype.getQueryParams()));
     this.parts =
         (prototype.getParts() == null ? null : new ArrayList<Part>(prototype.getParts()));
     this.virtualHost = prototype.getVirtualHost();
     this.length = prototype.getContentLength();
     this.proxyServer = prototype.getProxyServer();
     this.realm = prototype.getRealm();
     this.file = prototype.getFile();
     this.followRedirects =
         prototype.isRedirectOverrideSet() ? prototype.isRedirectEnabled() : null;
     this.requestTimeoutInMs = prototype.getRequestTimeoutInMs();
     this.rangeOffset = prototype.getRangeOffset();
     this.charset = prototype.getBodyEncoding();
     this.useRawUrl = prototype.isUseRawUrl();
     this.connectionPoolKeyStrategy = prototype.getConnectionPoolKeyStrategy();
   }
 }
Esempio n. 2
0
  private Response doRequest(final Request<?> request, final HttpRequestBase fetcher) {
    if (fetcher == null) {
      return null;
    }

    List<Parameter> headers = request.getHeaders();
    if (checkListOfParams(headers)) {
      for (Parameter parameter : headers) {
        Header header = new BasicHeader(parameter.getName(), parameter.getValue());
        fetcher.addHeader(header);
      }
    }

    final DefaultHttpClient httpClient = getHttpClient();
    List<Parameter> cookies = request.getCookies();
    if (checkListOfParams(cookies)) {
      CookieStore cookieStore = httpClient.getCookieStore();
      for (Parameter cookie : cookies) {
        cookieStore.addCookie(new BasicClientCookie(cookie.getName(), cookie.getValue()));
      }
      httpClient.setCookieStore(cookieStore);
    }

    return doRequest(fetcher, httpClient);
  }
Esempio n. 3
0
 public void updateCookies(final Request request) {
   if (request == null) {
     return;
   }
   final String host = Browser.getHost(request.getUrl());
   Cookies cookies = this.getCookies().get(host);
   if (cookies == null) {
     cookies = new Cookies();
     this.getCookies().put(host, cookies);
   }
   cookies.add(request.getCookies());
 }
Esempio n. 4
0
 @Override
 public Collection<Cookie> getRequestCookies() {
   final List<Cookie> newCookies = new ArrayList<>();
   final Set<io.netty.handler.codec.http.cookie.Cookie> cookies = request.getCookies();
   for (final io.netty.handler.codec.http.cookie.Cookie cookie : cookies) {
     final Cookie newCookie = new Cookie(cookie.name(), cookie.value());
     newCookie.setDomain(cookie.domain());
     newCookie.setPath(cookie.path());
     newCookie.setMaxAge((int) cookie.maxAge());
     newCookie.setSecure(cookie.isSecure());
     newCookie.setHttpOnly(cookie.isHttpOnly());
     newCookies.add(newCookie);
   }
   return newCookies;
 }
Esempio n. 5
0
  public void forwardCookies(final Request request) {
    if (request == null) {
      return;
    }
    final String host = Browser.getHost(request.getUrl());
    final Cookies cookies = this.getCookies().get(host);
    if (cookies == null) {
      return;
    }

    for (final Cookie cookie : cookies.getCookies()) {
      // Pfade sollten verarbeitet werden...TODO
      if (cookie.isExpired()) {
        continue;
      }
      request.getCookies().add(cookie);
    }
  }
Esempio n. 6
0
  /**
   * Creates a new GET request.
   *
   * @param string a string including an url
   * @param oldRequest the old request for forwarding cookies to the new request. Can be null, to
   *     ignore old cookies.
   * @return the created GET request
   * @throws IOException Signals that an I/O exception has occurred.
   */
  public Request createGetRequest(String string, final Request oldRequest) throws IOException {
    string = this.getURL(string);
    boolean sendref = true;
    if (this.currentURL == null) {
      sendref = false;
      this.currentURL = string;
    }

    final GetRequest request = new GetRequest(string);
    request.setCustomCharset(this.customCharset);

    // if old request is set, use it's cookies for the new request
    if (oldRequest != null && oldRequest.hasCookies()) {
      request.setCookies(oldRequest.getCookies());
    }

    // doAuth(request);
    /* set Timeouts */
    request.setConnectTimeout(this.getConnectTimeout());
    request.setReadTimeout(this.getReadTimeout());

    request.getHeaders().put("Accept-Language", this.acceptLanguage);
    // request.setFollowRedirects(doRedirects);
    this.forwardCookies(request);
    if (sendref) {
      request.getHeaders().put("Referer", this.currentURL.toString());
    }
    if (this.headers != null) {
      this.mergeHeaders(request);
    }

    // if (this.doRedirects && request.getLocation() != null) {
    // this.openGetConnection(null);
    // } else {
    //
    // currentURL = new URL(string);
    // }
    // return this.request.getHttpConnection();
    return request;
  }