All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arangodb.shaded.vertx.ext.web.client.impl.WebClientSessionAware Maven / Gradle / Ivy

There is a newer version: 7.8.0
Show newest version
/*
 * Copyright (c) 2011-2018 Contributors to the Eclipse Foundation
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
 * which is available at https://www.apache.org/licenses/LICENSE-2.0.
 *
 * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
 */
package com.arangodb.shaded.vertx.ext.web.client.impl;

import com.arangodb.shaded.vertx.core.AsyncResult;
import com.arangodb.shaded.vertx.core.Handler;
import com.arangodb.shaded.vertx.core.MultiMap;
import com.arangodb.shaded.vertx.core.http.HttpHeaders;
import com.arangodb.shaded.vertx.ext.web.client.HttpResponse;
import com.arangodb.shaded.vertx.ext.web.client.WebClient;
import com.arangodb.shaded.vertx.ext.web.client.WebClientSession;
import com.arangodb.shaded.vertx.ext.web.client.spi.CacheStore;
import com.arangodb.shaded.vertx.ext.web.client.spi.CookieStore;

/**
 * @author Tommaso Nolli
 */
public class WebClientSessionAware extends WebClientBase implements WebClientSession {

  private final CookieStore cookieStore;
  private final CacheStore cacheStore;
  private MultiMap headers;

  public WebClientSessionAware(WebClient webClient, CookieStore cookieStore) {
    super((WebClientBase) webClient);
    this.cookieStore = cookieStore;
    this.cacheStore = CacheStore.localStore();
    addInterceptor(new SessionAwareInterceptor(this));
  }

  public CookieStore cookieStore() {
    return cookieStore;
  }

  protected MultiMap headers() {
    if (headers == null) {
      headers = HttpHeaders.headers();
    }
    return headers;
  }

  @Override
  public WebClientSession addHeader(CharSequence name, CharSequence value) {
    headers().add(name, value);
    return this;
  }

  @Override
  public WebClientSession addHeader(String name, String value) {
    headers().add(name, value);
    return this;
  }

  @Override
  public WebClientSession addHeader(CharSequence name, Iterable values) {
    headers().add(name, values);
    return this;
  }

  @Override
  public WebClientSession addHeader(String name, Iterable values) {
    headers().add(name, values);
    return this;
  }

  @Override
  public WebClientSession removeHeader(CharSequence name) {
    headers().remove(name);
    return this;
  }

  @Override
  public WebClientSession removeHeader(String name) {
    headers().remove(name);
    return this;
  }

  @Override
  public  HttpContext createContext(Handler>> handler) {
    return super.createContext(handler).privateCacheStore(cacheStore);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy