@Override public boolean contains(AsciiString name) { return delegate.contains(name); }
@Override public boolean contains(AsciiString name, String value) { return delegate.contains(name, value); }
private static void setDefaultRequestHeaders(HttpHeaders headers) { if (!headers.contains(HttpHeaderNames.ACCEPT)) { headers.add(HttpHeaderNames.ACCEPT, "*/*"); } } }
/** * Returns {@code true} if the specified {@code request} is a CORS preflight request. */ public static boolean isCorsPreflightRequest(com.linecorp.armeria.common.HttpRequest request) { requireNonNull(request, "request"); return request.method() == HttpMethod.OPTIONS && request.headers().contains(HttpHeaderNames.ORIGIN) && request.headers().contains(HttpHeaderNames.ACCESS_CONTROL_REQUEST_METHOD); }
private static HttpHeaders filterHttpHeaders(HttpHeaders headers) { requireNonNull(headers, "headers"); for (AsciiString name : BLACKLISTED_HEADER_NAMES) { if (headers.contains(name)) { throw new IllegalArgumentException("unallowed header name: " + name); } } return new DefaultHttpHeaders().add(headers).asImmutable(); }
private boolean shouldEncodeResponse(HttpHeaders headers) { if (headers.contains(HttpHeaderNames.CONTENT_ENCODING)) { // We don't do automatic encoding if the user-supplied headers contain // Content-Encoding. return false; } if (headers.contentType() != null) { // Make sure the content type is worth encoding. try { final MediaType contentType = headers.contentType(); if (!encodableContentTypePredicate.test(contentType)) { return false; } } catch (IllegalArgumentException e) { // Don't know content type of response, don't encode. return false; } } if (headers.contains(HttpHeaderNames.CONTENT_LENGTH)) { // We switch to chunked encoding and compress the response if it's reasonably // large as the compression savings should outweigh the chunked encoding // overhead. if (headers.getInt(HttpHeaderNames.CONTENT_LENGTH) < minBytesToForceChunkedAndEncoding) { return false; } } return true; } }
/** * Copies the entries missing in this headers from the specified {@link Headers}. * This method is a shortcut of the following code: * <pre>{@code * headers.names().forEach(name -> { * if (!contains(name)) { * set(name, headers.getAll(name)); * } * }); * }</pre> */ default HttpHeaders setAllIfAbsent(Headers<AsciiString, String, ?> headers) { requireNonNull(headers, "headers"); if (!headers.isEmpty()) { headers.names().forEach(name -> { if (!contains(name)) { set(name, headers.getAll(name)); } }); } return this; }
if (!requestHeaders.contains(HttpHeaderNames.USER_AGENT)) { requestHeaders.set(HttpHeaderNames.USER_AGENT, HttpHeaderUtil.USER_AGENT.toString());
if (headers.contains(HttpHeaderNames.CONTENT_LENGTH)) { final HttpHeaders mutable = headers.toMutable(); mutable.remove(HttpHeaderNames.CONTENT_LENGTH); if (headers.contains(HttpHeaderNames.CONTENT_LENGTH)) { final HttpHeaders mutable = headers.toMutable(); mutable.remove(HttpHeaderNames.CONTENT_LENGTH); if (!headers.contains(HttpHeaderNames.CONTENT_LENGTH) || !content.isEmpty()) { final HttpHeaders mutable = headers.toMutable(); mutable.setInt(HttpHeaderNames.CONTENT_LENGTH, content.length());
@Override public HttpResponse execute(ClientRequestContext ctx, HttpRequest req) throws Exception { if (req.headers().contains(HttpHeaderNames.ACCEPT_ENCODING)) { // Client specified encoding, so we don't do anything automatically. return delegate().execute(ctx, req); } req.headers().set(HttpHeaderNames.ACCEPT_ENCODING, acceptEncodingHeader); final HttpResponse res = delegate().execute(ctx, req); return new HttpDecodedResponse(res, decoderFactories); } }
} else if (!headers.contains(HttpHeaderNames.CONTENT_LENGTH)) {
/** * Returns a newly-created {@link CentralDogma} instance. * * @throws UnknownHostException if failed to resolve the host names from the DNS servers */ public CentralDogma build() throws UnknownHostException { final Endpoint endpoint = endpoint(); final String scheme = "tbinary+" + (isUseTls() ? "https" : "http") + "://"; final String uri = scheme + endpoint.authority() + "/cd/thrift/v1"; final ClientBuilder builder = new ClientBuilder(uri) .factory(clientFactory()) .rpcDecorator(CentralDogmaClientTimeoutScheduler::new); clientConfigurator().configure(builder); builder.decorator((delegate, ctx, req) -> { if (!req.headers().contains(HttpHeaderNames.AUTHORIZATION)) { // To prevent CSRF attack, we add 'Authorization' header to every request. req.headers().set(HttpHeaderNames.AUTHORIZATION, "bearer " + CsrfToken.ANONYMOUS); } return delegate.execute(ctx, req); }); return new LegacyCentralDogma(clientFactory(), builder.build(CentralDogmaService.AsyncIface.class)); } }
/** * Returns a newly-created {@link CentralDogma} instance. * * @throws UnknownHostException if failed to resolve the host names from the DNS servers */ public CentralDogma build() throws UnknownHostException { final Endpoint endpoint = endpoint(); final String scheme = "tbinary+" + (isUseTls() ? "https" : "http") + "://"; final String uri = scheme + endpoint.authority() + "/cd/thrift/v1"; final ClientBuilder builder = new ClientBuilder(uri) .factory(clientFactory()) .rpcDecorator(CentralDogmaClientTimeoutScheduler::new); clientConfigurator().configure(builder); builder.decorator((delegate, ctx, req) -> { if (!req.headers().contains(HttpHeaderNames.AUTHORIZATION)) { // To prevent CSRF attack, we add 'Authorization' header to every request. req.headers().set(HttpHeaderNames.AUTHORIZATION, "bearer " + CsrfToken.ANONYMOUS); } return delegate.execute(ctx, req); }); return new LegacyCentralDogma(clientFactory(), builder.build(CentralDogmaService.AsyncIface.class)); } }
/** * Returns a newly-created {@link CentralDogma} instance. * * @throws UnknownHostException if failed to resolve the host names from the DNS servers */ public CentralDogma build() throws UnknownHostException { final Endpoint endpoint = endpoint(); final String scheme = "tbinary+" + (isUseTls() ? "https" : "http") + "://"; final String uri = scheme + endpoint.authority() + "/cd/thrift/v1"; final ClientBuilder builder = new ClientBuilder(uri) .factory(clientFactory()) .decorator(RpcRequest.class, RpcResponse.class, CentralDogmaClientTimeoutScheduler::new); clientConfigurator().configure(builder); builder.decorator(HttpRequest.class, HttpResponse.class, (delegate, ctx, req) -> { if (!req.headers().contains(HttpHeaderNames.AUTHORIZATION)) { // To prevent CSRF attack, we add 'Authorization' header to every request. req.headers().set(HttpHeaderNames.AUTHORIZATION, "bearer " + CsrfToken.ANONYMOUS); } return delegate.execute(ctx, req); }); return new LegacyCentralDogma(clientFactory(), builder.build(CentralDogmaService.AsyncIface.class)); } }