/** * Creates a builder with an HTTP method and URI. * * @param method HTTP method * @param uri URI */ public Builder(HttpMethod method, String uri) { this.method = method; this.url = Url.Builder.url(uri).build(); this.secure = url.isSecure(); headers(new HttpHeaders.Builder()); }
public static LiveHttpRequest doOnComplete(LiveHttpRequest request, Runnable action) { return request.newBuilder() .body(it -> it.doOnEnd(ifSuccessful(action))) .build(); }
public static LiveHttpResponse doOnError(LiveHttpResponse response, Consumer<Throwable> action) { return response.newBuilder() .body(it -> it.doOnEnd(ifError(action))) .build(); }
@Override public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain) { LiveHttpRequest newRequest = request.newBuilder() .header(VIA, viaHeader(request)) .build(); return chain.proceed(newRequest) .map(response -> response.newBuilder() .header(VIA, viaHeader(response)) .build()); }
private static HttpResponse responseWithoutBody(HttpResponse response) { return response.newBuilder() .header(CONTENT_LENGTH, 0) .removeHeader(TRANSFER_ENCODING) .removeBody() .build(); }
public SELF headers(HttpHeader... headers) { for (HttpHeader header : headers) { checkNotCookie(header.name()); this.headers.set(header.name(), header.value()); } return (SELF) this; }
private static HttpRequest addUserAgent(HttpRequest request, String userAgent) { return request.newBuilder() .addHeader(USER_AGENT, userAgent) .build(); }
/** * Returns the value of the header with the specified {@code name}. * If there is more than one header value for the specified header name, the first value is returned. * * @return the value of the header with the specified {@code name} if present */ default Optional<String> header(CharSequence name) { return headers().get(name); }
public static LiveHttpRequest doOnError(LiveHttpRequest request, Consumer<Throwable> action) { return request.newBuilder() .body(it -> it.doOnEnd(ifError(action))) .build(); }
public static LiveHttpResponse doOnComplete(LiveHttpResponse response, Runnable action) { return response.newBuilder() .body(it -> it.doOnEnd(ifSuccessful(action))) .build(); }
public static LiveHttpRequest doFinally(LiveHttpRequest request, Consumer<Optional<Throwable>> action) { return request.newBuilder() .body(it -> it.doOnEnd(action)) .build(); }
public static LiveHttpResponse doFinally(LiveHttpResponse response, Consumer<Optional<Throwable>> action) { return response.newBuilder() .body(it -> it.doOnEnd(action::accept)) .build(); }