@Override public List<String> getAll(AsciiString name) { return delegate.getAll(name); }
@Override public void serialize(HttpHeaders headers, JsonGenerator gen, SerializerProvider serializers) throws IOException { gen.writeStartObject(); for (AsciiString name : headers.names()) { gen.writeFieldName(name.toString()); final List<String> values = headers.getAll(name); if (values.size() == 1) { gen.writeString(values.get(0)); } else { gen.writeStartArray(); for (String value : values) { gen.writeString(value); } gen.writeEndArray(); } } gen.writeEndObject(); } }
@Override protected MultiValueMap<String, HttpCookie> initCookies() { final MultiValueMap<String, HttpCookie> cookies = new LinkedMultiValueMap<>(); final List<String> values = req.headers().getAll(HttpHeaderNames.COOKIE); values.stream() .map(ServerCookieDecoder.LAX::decode) .flatMap(Collection::stream) .forEach(c -> cookies.add(c.name(), new HttpCookie(c.name(), c.value()))); return cookies; }
private static boolean validateAcceptHeaders(HttpRequest req, SerializationFormat serializationFormat) { // If accept header is present, make sure it is sane. Currently, we do not support accept // headers with a different format than the content type header. final List<String> acceptHeaders = req.headers().getAll(HttpHeaderNames.ACCEPT); if (!acceptHeaders.isEmpty() && !serializationFormat.mediaTypes().matchHeaders(acceptHeaders).isPresent()) { return false; } return true; }
final List<String> acceptHeaders = headers.getAll(HttpHeaderNames.ACCEPT); if (acceptHeaders == null || acceptHeaders.isEmpty()) {
@Override protected TTransport newTransport(String uri, HttpHeaders headers) throws TTransportException { final io.netty.handler.codec.http.HttpHeaders nettyDefaultHeaders = new DefaultHttpHeaders(); headers.names().forEach(name -> nettyDefaultHeaders.set(name, headers.getAll(name))); return new THttp2Client(uri, nettyDefaultHeaders); } }
private MultiValueMap<String, ResponseCookie> initCookies() { final MultiValueMap<String, ResponseCookie> cookies = new LinkedMultiValueMap<>(); headers.getAll(HttpHeaderNames.SET_COOKIE) .stream() .map(ClientCookieDecoder.LAX::decode) .forEach(c -> cookies.add(c.name(), ResponseCookie.from(c.name(), c.value()) .maxAge(c.maxAge()) .domain(c.domain()) .path(c.path()) .secure(c.isSecure()) .httpOnly(c.isHttpOnly()) .build())); return cookies; }
.supportOptional(true) .resolver((unused, ctx) -> { final List<String> values = ctx.request().headers().getAll(HttpHeaderNames.COOKIE); if (values.isEmpty()) { return Cookies.copyOf(ImmutableSet.of());
private static AnnotatedValueResolver ofHeader(String name, AnnotatedElement annotatedElement, AnnotatedElement typeElement, Class<?> type, @Nullable String description) { return builder(annotatedElement, type) .annotationType(Header.class) .httpElementName(name) .typeElement(typeElement) .supportOptional(true) .supportDefault(true) .supportContainer(true) .description(description) .resolver(resolver( ctx -> ctx.request().headers().getAll(HttpHeaderNames.of(name)), () -> "Cannot resolve a value from HTTP header: " + name)) .build(); }
@Override protected TTransport newTransport(String uri, HttpHeaders headers) throws TTransportException { final SSLContext sslContext; try { sslContext = SSLContextBuilder.create() .loadTrustMaterial((TrustStrategy) (chain, authType) -> true) .build(); } catch (GeneralSecurityException e) { throw new TTransportException("failed to initialize an SSL context", e); } final THttpClient client = new THttpClient( uri, HttpClientBuilder.create() .setSSLHostnameVerifier((hostname, session) -> true) .setSSLContext(sslContext) .build()); client.setCustomHeaders( headers.names().stream() .collect(toImmutableMap(AsciiString::toString, name -> String.join(", ", headers.getAll(name))))); return client; }
private static boolean validateAcceptHeaders(HttpRequest req, SerializationFormat serializationFormat) { // If accept header is present, make sure it is sane. Currently, we do not support accept // headers with a different format than the content type header. final List<String> acceptHeaders = req.headers().getAll(HttpHeaderNames.ACCEPT); if (!acceptHeaders.isEmpty() && !serializationFormat.mediaTypes().matchHeaders(acceptHeaders).isPresent()) { return false; } return true; }
private static boolean validateAcceptHeaders(HttpRequest req, SerializationFormat serializationFormat) { // If accept header is present, make sure it is sane. Currently, we do not support accept // headers with a different format than the content type header. final List<String> acceptHeaders = req.headers().getAll(HttpHeaderNames.ACCEPT); if (!acceptHeaders.isEmpty() && !serializationFormat.mediaTypes().matchHeaders(acceptHeaders).isPresent()) { return false; } return true; }
private static boolean validateAcceptHeaders(HttpRequest req, SerializationFormat serializationFormat) { // If accept header is present, make sure it is sane. Currently, we do not support accept // headers with a different format than the content type header. final List<String> acceptHeaders = req.headers().getAll(HttpHeaderNames.ACCEPT); if (!acceptHeaders.isEmpty() && !serializationFormat.mediaTypes().matchHeaders(acceptHeaders).isPresent()) { return false; } return true; }