com.linecorp.armeria.common.HttpHeadersBuilder Java Examples

The following examples show how to use com.linecorp.armeria.common.HttpHeadersBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: armeria   Author: line   File: ArmeriaServerCall.java    License: Apache License 2.0 6 votes vote down vote up
static HttpHeaders statusToTrailers(
        ServiceRequestContext ctx, Status status, Metadata metadata, boolean headersSent) {
    final HttpHeadersBuilder trailers = GrpcTrailersUtil.statusToTrailers(
            status.getCode().value(), status.getDescription(), headersSent);

    MetadataUtil.fillHeaders(metadata, trailers);

    if (ctx.config().verboseResponses() && status.getCause() != null) {
        final ThrowableProto proto = GrpcStatus.serializeThrowable(status.getCause());
        trailers.add(GrpcHeaderNames.ARMERIA_GRPC_THROWABLEPROTO_BIN,
                     Base64.getEncoder().encodeToString(proto.toByteArray()));
    }

    final HttpHeaders additionalTrailers = ctx.additionalResponseTrailers();
    ctx.mutateAdditionalResponseTrailers(HttpHeadersBuilder::clear);
    trailers.add(additionalTrailers);
    return trailers.build();
}
 
Example #2
Source Project: armeria   Author: line   File: GrpcTrailersUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Converts the given gRPC status code, and optionally an error message, to headers. The headers will be
 * either trailers-only or normal trailers based on {@code headersSent}, whether leading headers have
 * already been sent to the client.
 */
public static HttpHeadersBuilder statusToTrailers(int code, @Nullable String message, boolean headersSent) {
    final HttpHeadersBuilder trailers;
    if (headersSent) {
        // Normal trailers.
        trailers = HttpHeaders.builder();
    } else {
        // Trailers only response
        trailers = ResponseHeaders.builder()
                                  .endOfStream(true)
                                  .add(HttpHeaderNames.STATUS, HttpStatus.OK.codeAsText())
                                  .add(HttpHeaderNames.CONTENT_TYPE, "application/grpc+proto");
    }
    trailers.add(GrpcHeaderNames.GRPC_STATUS, Integer.toString(code));

    if (message != null) {
        trailers.add(GrpcHeaderNames.GRPC_MESSAGE, StatusMessageEscaper.escape(message));
    }

    return trailers;
}
 
Example #3
Source Project: armeria   Author: line   File: HttpHeadersUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static HttpHeaders mergeTrailers(HttpHeaders headers, HttpHeaders additionalTrailers) {
    if (additionalTrailers.isEmpty()) {
        return headers;
    }
    if (headers.isEmpty()) {
        return additionalTrailers;
    }

    final HttpHeadersBuilder builder = headers.toBuilder();
    for (AsciiString name : additionalTrailers.names()) {
        if (!ADDITIONAL_RESPONSE_HEADER_BLACKLIST.contains(name) &&
            !isTrailerBlacklisted(name)) {
            builder.remove(name);
            additionalTrailers.forEachValue(name, value -> builder.add(name, value));
        }
    }
    return builder.build();
}
 
Example #4
Source Project: armeria   Author: line   File: ArmeriaHttpUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Filter the {@link HttpHeaderNames#TE} header according to the
 * <a href="https://tools.ietf.org/html/rfc7540#section-8.1.2.2">special rules in the HTTP/2 RFC</a>.
 *
 * @param entry the entry whose name is {@link HttpHeaderNames#TE}.
 * @param out the resulting HTTP/2 headers.
 */
private static void toHttp2HeadersFilterTE(Entry<CharSequence, CharSequence> entry,
                                           HttpHeadersBuilder out) {
    if (AsciiString.indexOf(entry.getValue(), ',', 0) == -1) {
        if (AsciiString.contentEqualsIgnoreCase(AsciiString.trim(entry.getValue()),
                                                HttpHeaderValues.TRAILERS)) {
            out.add(HttpHeaderNames.TE, HttpHeaderValues.TRAILERS.toString());
        }
    } else {
        final List<CharSequence> teValues = StringUtil.unescapeCsvFields(entry.getValue());
        for (CharSequence teValue : teValues) {
            if (AsciiString.contentEqualsIgnoreCase(AsciiString.trim(teValue),
                                                    HttpHeaderValues.TRAILERS)) {
                out.add(HttpHeaderNames.TE, HttpHeaderValues.TRAILERS.toString());
                break;
            }
        }
    }
}
 
Example #5
Source Project: skywalking   Author: apache   File: ArmeriaClientInterceptor.java    License: Apache License 2.0 6 votes vote down vote up
protected void beforeMethod(final URI uri, final HttpMethod httpMethod, final String path) {
    final ContextCarrier contextCarrier = new ContextCarrier();
    final String remotePeer = uri.getHost() + ":" + uri.getPort();

    final AbstractSpan exitSpan = ContextManager.createExitSpan(path, contextCarrier, remotePeer);

    exitSpan.setComponent(ComponentsDefine.ARMERIA);
    exitSpan.setLayer(SpanLayer.HTTP);
    Tags.HTTP.METHOD.set(exitSpan, httpMethod.name());

    ContextManager.getRuntimeContext().put(KEY_SAFE_CLOSEABLE, Clients.withHttpHeaders(headers -> {
        HttpHeadersBuilder builder = headers.toBuilder();
        for (CarrierItem item = contextCarrier.items(); item.hasNext(); ) {
            item = item.next();
            builder.add(AsciiString.of(item.getHeadKey()), item.getHeadValue());
        }
        return builder.build();
    }));
}
 
Example #6
Source Project: curiostack   Author: curioswitch   File: LoggingModule.java    License: MIT License 5 votes vote down vote up
@Provides
@Singleton
static Function<HttpService, LoggingService> loggingService(
    LoggingConfig config,
    @RequestHeaderSanitizer Set<Consumer<HttpHeadersBuilder>> requestHeaderSanitizers,
    @ResponseHeaderSanitizer Set<Consumer<HttpHeadersBuilder>> responseHeaderSanitizers) {
  LoggingServiceBuilder builder = LoggingService.builder();
  configureLoggingDecorator(builder, config, requestHeaderSanitizers, responseHeaderSanitizers);
  if (config.getLogAllServerRequests()) {
    builder.requestLogLevel(LogLevel.INFO);
    builder.successfulResponseLogLevel(LogLevel.INFO);
  }
  return builder::build;
}
 
Example #7
Source Project: curiostack   Author: curioswitch   File: LoggingModule.java    License: MIT License 5 votes vote down vote up
@Provides
@Singleton
static Function<HttpClient, LoggingClient> loggingClient(
    LoggingConfig config,
    @RequestHeaderSanitizer Set<Consumer<HttpHeadersBuilder>> requestHeaderSanitizers,
    @ResponseHeaderSanitizer Set<Consumer<HttpHeadersBuilder>> responseHeaderSanitizers) {
  LoggingClientBuilder builder = LoggingClient.builder();
  configureLoggingDecorator(builder, config, requestHeaderSanitizers, responseHeaderSanitizers);
  if (config.getLogAllClientRequests()) {
    builder.requestLogLevel(LogLevel.INFO);
    builder.successfulResponseLogLevel(LogLevel.INFO);
  }
  return builder::build;
}
 
Example #8
Source Project: curiostack   Author: curioswitch   File: LoggingModule.java    License: MIT License 5 votes vote down vote up
private static void configureLoggingDecorator(
    LoggingDecoratorBuilder builder,
    LoggingConfig config,
    @RequestHeaderSanitizer Set<Consumer<HttpHeadersBuilder>> requestHeaderSanitizers,
    @ResponseHeaderSanitizer Set<Consumer<HttpHeadersBuilder>> responseHeaderSanitizers) {
  if (!config.getBlacklistedRequestHeaders().isEmpty() || !requestHeaderSanitizers.isEmpty()) {
    builder.requestHeadersSanitizer(
        new HeaderSanitizer(requestHeaderSanitizers, config.getBlacklistedRequestHeaders()));
  }

  if (!config.getBlacklistedResponseHeaders().isEmpty() || !responseHeaderSanitizers.isEmpty()) {
    builder.responseHeadersSanitizer(
        new HeaderSanitizer(responseHeaderSanitizers, config.getBlacklistedResponseHeaders()));
  }
}
 
Example #9
Source Project: curiostack   Author: curioswitch   File: HeaderSanitizer.java    License: MIT License 5 votes vote down vote up
@Override
public HttpHeaders apply(HttpHeaders entries) {
  HttpHeadersBuilder builder = entries.toBuilder();
  blacklistedHeaders.forEach(builder::remove);
  customSanitizers.forEach(c -> c.accept(builder));
  return builder.build();
}
 
Example #10
Source Project: armeria   Author: line   File: ArmeriaClientCall.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private static HttpHeaders parseGrpcWebTrailers(ByteBuf buf) {
    final HttpHeadersBuilder trailers = HttpHeaders.builder();
    while (buf.readableBytes() > 0) {
        int start = buf.forEachByte(ByteProcessor.FIND_NON_LINEAR_WHITESPACE);
        if (start == -1) {
            return null;
        }
        int endExclusive;
        if (buf.getByte(start) == ':') {
            // We need to skip the pseudoheader colon when searching for the separator.
            buf.skipBytes(1);
            endExclusive = buf.forEachByte(FIND_COLON);
            buf.readerIndex(start);
        } else {
            endExclusive = buf.forEachByte(FIND_COLON);
        }
        if (endExclusive == -1) {
            return null;
        }
        final CharSequence name = buf.readCharSequence(endExclusive - start, StandardCharsets.UTF_8);
        buf.readerIndex(endExclusive + 1);
        start = buf.forEachByte(ByteProcessor.FIND_NON_LINEAR_WHITESPACE);
        buf.readerIndex(start);
        endExclusive = buf.forEachByte(ByteProcessor.FIND_CRLF);
        final CharSequence value = buf.readCharSequence(endExclusive - start, StandardCharsets.UTF_8);
        trailers.add(name, value.toString());
        start = buf.forEachByte(ByteProcessor.FIND_NON_CRLF);
        if (start != -1) {
            buf.readerIndex(start);
        } else {
            // Nothing but CRLF remaining, we're done.
            buf.skipBytes(buf.readableBytes());
        }
    }
    return trailers.build();
}
 
Example #11
Source Project: armeria   Author: line   File: MetadataUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Copies the headers in the gRPC {@link Metadata} to the Armeria {@link HttpHeadersBuilder}. Headers will
 * be added, without replacing any currently present in the {@link HttpHeaders}.
 */
public static void fillHeaders(Metadata metadata, HttpHeadersBuilder builder) {
    if (InternalMetadata.headerCount(metadata) == 0) {
        return;
    }

    final byte[][] serializedMetadata = InternalMetadata.serialize(metadata);
    assert serializedMetadata.length % 2 == 0;

    for (int i = 0; i < serializedMetadata.length; i += 2) {
        final AsciiString name = new AsciiString(serializedMetadata[i], false);

        if (STRIPPED_HEADERS.contains(name)) {
            continue;
        }

        final byte[] valueBytes = serializedMetadata[i + 1];

        final String value;
        if (isBinary(name)) {
            value = BASE64_ENCODING_OMIT_PADDING.encode(valueBytes);
        } else if (isGrpcAscii(valueBytes)) {
            value = new String(valueBytes, StandardCharsets.US_ASCII);
        } else {
            logger.warn("Metadata name=" + name + ", value=" + Arrays.toString(valueBytes) +
                        " contains invalid ASCII characters, skipping.");
            continue;
        }
        builder.add(name, value);
    }
}
 
Example #12
Source Project: armeria   Author: line   File: MetadataUtilTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void fillHeadersTest() {
    final HttpHeadersBuilder trailers =
            ResponseHeaders.builder()
                           .endOfStream(true)
                           .add(HttpHeaderNames.STATUS, HttpStatus.OK.codeAsText())
                           .add(HttpHeaderNames.CONTENT_TYPE, "application/grpc+proto")
                           .add(GrpcHeaderNames.GRPC_STATUS, "3")
                           .add(GrpcHeaderNames.GRPC_MESSAGE, "test_grpc_message");

    final Metadata metadata = new Metadata();
    // be copied into HttpHeaderBuilder trailers
    metadata.put(TEST_ASCII_KEY, "metadata_test_string");
    metadata.put(TEST_BIN_KEY, "metadata_test_string".getBytes());
    // must not be copied into HttpHeaderBuilder trailers
    metadata.put(STATUS_KEY, "200");
    metadata.put(InternalStatus.CODE_KEY, Status.OK);
    metadata.put(InternalStatus.MESSAGE_KEY, "grpc_message_must_not_be_copied");
    metadata.put(THROWABLE_PROTO_METADATA_KEY, THROWABLE_PROTO);

    MetadataUtil.fillHeaders(metadata, trailers);

    assertThat(trailers.getAll(TEST_ASCII_KEY.originalName())).containsExactly("metadata_test_string");
    assertThat(Base64.getDecoder().decode(trailers.get(TEST_BIN_KEY.originalName())))
            .containsExactly("metadata_test_string".getBytes());
    assertThat(trailers.getAll(HttpHeaderNames.STATUS)).containsExactly(HttpStatus.OK.codeAsText());
    assertThat(trailers.getAll(HttpHeaderNames.CONTENT_TYPE)).containsExactly("application/grpc+proto");
    assertThat(trailers.getAll(GrpcHeaderNames.GRPC_STATUS)).containsExactly("3");
    assertThat(trailers.getAll(GrpcHeaderNames.GRPC_MESSAGE)).containsOnly("test_grpc_message");
    assertThat(trailers.getAll(GrpcHeaderNames.ARMERIA_GRPC_THROWABLEPROTO_BIN)).isEmpty();
}
 
Example #13
Source Project: armeria   Author: line   File: AbstractUnsafeUnaryGrpcService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected final HttpResponse doPost(ServiceRequestContext ctx, PooledHttpRequest req) {
    final CompletableFuture<HttpResponse> responseFuture =
            req.aggregateWithPooledObjects(ctx.contextAwareEventLoop(), ctx.alloc())
               .thenCompose(msg -> deframeMessage(msg.content(), ctx.alloc()))
               .thenCompose(this::handleMessage)
               .thenApply(responseMessage -> {
                   final ArmeriaMessageFramer framer = new ArmeriaMessageFramer(
                           ctx.alloc(), Integer.MAX_VALUE);
                   final HttpData framed = framer.writePayload(responseMessage);
                   return HttpResponse.of(
                           RESPONSE_HEADERS,
                           framed,
                           GrpcTrailersUtil.statusToTrailers(StatusCodes.OK, null, true).build());
               })
               .exceptionally(t -> {
                   final HttpHeadersBuilder trailers;
                   if (t instanceof ArmeriaStatusException) {
                       final ArmeriaStatusException statusException = (ArmeriaStatusException) t;
                       trailers = GrpcTrailersUtil.statusToTrailers(
                               statusException.getCode(), statusException.getMessage(), false);
                   } else {
                       trailers = GrpcTrailersUtil.statusToTrailers(
                               StatusCodes.INTERNAL, t.getMessage(), false);
                   }
                   return HttpResponse.of(trailers.build());
               });

    return HttpResponse.from(responseFuture);
}
 
Example #14
Source Project: armeria   Author: line   File: DefaultClientRequestContext.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void mutateAdditionalRequestHeaders(Consumer<HttpHeadersBuilder> mutator) {
    requireNonNull(mutator, "mutator");
    for (;;) {
        final HttpHeaders oldValue = additionalRequestHeaders;
        final HttpHeadersBuilder builder = oldValue.toBuilder();
        mutator.accept(builder);
        final HttpHeaders newValue = builder.build();
        if (additionalRequestHeadersUpdater.compareAndSet(this, oldValue, newValue)) {
            return;
        }
    }
}
 
Example #15
Source Project: armeria   Author: line   File: DefaultServiceRequestContext.java    License: Apache License 2.0 5 votes vote down vote up
private void mutateAdditionalResponseHeaders(
        AtomicReferenceFieldUpdater<DefaultServiceRequestContext, HttpHeaders> atomicUpdater,
        Consumer<HttpHeadersBuilder> mutator) {
    for (;;) {
        final HttpHeaders oldValue = atomicUpdater.get(this);
        final HttpHeadersBuilder builder = oldValue.toBuilder();
        mutator.accept(builder);
        final HttpHeaders newValue = builder.build();
        if (atomicUpdater.compareAndSet(this, oldValue, newValue)) {
            return;
        }
    }
}
 
Example #16
Source Project: armeria   Author: line   File: CorsPolicy.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Generates immutable HTTP response headers that should be added to a CORS preflight response.
 *
 * @return {@link HttpHeaders} the HTTP response headers to be added.
 */
public HttpHeaders generatePreflightResponseHeaders() {
    final HttpHeadersBuilder headers = HttpHeaders.builder();
    preflightResponseHeaders.forEach((key, value) -> {
        final Object val = getValue(value);
        if (val instanceof Iterable) {
            headers.addObject(key, (Iterable<?>) val);
        } else {
            headers.addObject(key, val);
        }
    });
    return headers.build();
}
 
Example #17
Source Project: armeria   Author: line   File: AnnotatedServiceFactory.java    License: Apache License 2.0 5 votes vote down vote up
private static <T extends Annotation> void setAdditionalHeader(HttpHeadersBuilder headers,
                                                               AnnotatedElement element,
                                                               String clsAlias,
                                                               String elementAlias,
                                                               String level,
                                                               Class<T> annotation,
                                                               Function<T, String> nameGetter,
                                                               Function<T, String[]> valueGetter) {
    requireNonNull(headers, "headers");
    requireNonNull(element, "element");
    requireNonNull(level, "level");

    final Set<String> addedHeaderSets = new HashSet<>();
    AnnotationUtil.findAll(element, annotation).forEach(header -> {
        final String name = nameGetter.apply(header);
        final String[] value = valueGetter.apply(header);

        if (addedHeaderSets.contains(name)) {
            logger.warn("The additional {} named '{}' at '{}' is set at the same {} level already;" +
                        "ignoring.",
                        clsAlias, name, elementAlias, level);
            return;
        }
        headers.set(HttpHeaderNames.of(name), value);
        addedHeaderSets.add(name);
    });
}
 
Example #18
Source Project: armeria   Author: line   File: ArmeriaHttpUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Converts the specified Netty HTTP/2 into Armeria HTTP/2 headers.
 */
public static HttpHeaders toArmeria(Http2Headers headers, boolean request, boolean endOfStream) {
    final HttpHeadersBuilder builder;
    if (request) {
        builder = headers.contains(HttpHeaderNames.METHOD) ? RequestHeaders.builder()
                                                           : HttpHeaders.builder();
    } else {
        builder = headers.contains(HttpHeaderNames.STATUS) ? ResponseHeaders.builder()
                                                           : HttpHeaders.builder();
    }

    toArmeria(builder, headers, endOfStream);
    return builder.build();
}
 
Example #19
Source Project: armeria   Author: line   File: ArmeriaHttpUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Converts the specified Netty HTTP/1 headers into Armeria HTTP/2 headers.
 */
public static HttpHeaders toArmeria(io.netty.handler.codec.http.HttpHeaders inHeaders) {
    if (inHeaders.isEmpty()) {
        return HttpHeaders.of();
    }

    final HttpHeadersBuilder out = HttpHeaders.builder();
    out.sizeHint(inHeaders.size());
    toArmeria(inHeaders, out);
    return out.build();
}
 
Example #20
Source Project: armeria   Author: line   File: ArmeriaHttpUtilTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void inboundCookiesMustBeMergedForHttp1() {
    final io.netty.handler.codec.http.HttpHeaders in = new DefaultHttpHeaders();
    in.add(HttpHeaderNames.COOKIE, "a=b; c=d");
    in.add(HttpHeaderNames.COOKIE, "e=f;g=h");
    in.add(HttpHeaderNames.CONTENT_TYPE, MediaType.PLAIN_TEXT_UTF_8);
    in.add(HttpHeaderNames.COOKIE, "i=j");
    in.add(HttpHeaderNames.COOKIE, "k=l;");

    final HttpHeadersBuilder out = HttpHeaders.builder();
    toArmeria(in, out);

    assertThat(out.getAll(HttpHeaderNames.COOKIE))
            .containsExactly("a=b; c=d; e=f; g=h; i=j; k=l");
}
 
Example #21
Source Project: armeria   Author: line   File: ArmeriaHttpUtilTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void stripTEHeaders() {
    final io.netty.handler.codec.http.HttpHeaders in = new DefaultHttpHeaders();
    in.add(HttpHeaderNames.TE, HttpHeaderValues.GZIP);
    final HttpHeadersBuilder out = HttpHeaders.builder();
    toArmeria(in, out);
    assertThat(out).isEmpty();
}
 
Example #22
Source Project: armeria   Author: line   File: ArmeriaHttpUtilTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void stripTEHeadersExcludingTrailers() {
    final io.netty.handler.codec.http.HttpHeaders in = new DefaultHttpHeaders();
    in.add(HttpHeaderNames.TE, HttpHeaderValues.GZIP);
    in.add(HttpHeaderNames.TE, HttpHeaderValues.TRAILERS);
    final HttpHeadersBuilder out = HttpHeaders.builder();
    toArmeria(in, out);
    assertThat(out.get(HttpHeaderNames.TE)).isEqualTo(HttpHeaderValues.TRAILERS.toString());
}
 
Example #23
Source Project: armeria   Author: line   File: ArmeriaHttpUtilTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void stripTEHeadersCsvSeparatedExcludingTrailers() {
    final io.netty.handler.codec.http.HttpHeaders in = new DefaultHttpHeaders();
    in.add(HttpHeaderNames.TE, HttpHeaderValues.GZIP + "," + HttpHeaderValues.TRAILERS);
    final HttpHeadersBuilder out = HttpHeaders.builder();
    toArmeria(in, out);
    assertThat(out.get(HttpHeaderNames.TE)).isEqualTo(HttpHeaderValues.TRAILERS.toString());
}
 
Example #24
Source Project: armeria   Author: line   File: ArmeriaHttpUtilTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void stripTEHeadersCsvSeparatedAccountsForValueSimilarToTrailers() {
    final io.netty.handler.codec.http.HttpHeaders in = new DefaultHttpHeaders();
    in.add(HttpHeaderNames.TE, HttpHeaderValues.GZIP + "," + HttpHeaderValues.TRAILERS + "foo");
    final HttpHeadersBuilder out = HttpHeaders.builder();
    toArmeria(in, out);
    assertThat(out.contains(HttpHeaderNames.TE)).isFalse();
}
 
Example #25
Source Project: armeria   Author: line   File: ArmeriaHttpUtilTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void stripTEHeadersAccountsForValueSimilarToTrailers() {
    final io.netty.handler.codec.http.HttpHeaders in = new DefaultHttpHeaders();
    in.add(HttpHeaderNames.TE, HttpHeaderValues.TRAILERS + "foo");
    final HttpHeadersBuilder out = HttpHeaders.builder();
    toArmeria(in, out);
    assertThat(out.contains(HttpHeaderNames.TE)).isFalse();
}
 
Example #26
Source Project: armeria   Author: line   File: ArmeriaHttpUtilTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void stripTEHeadersAccountsForOWS() {
    final io.netty.handler.codec.http.HttpHeaders in = new DefaultHttpHeaders();
    in.add(HttpHeaderNames.TE, " " + HttpHeaderValues.TRAILERS + ' ');
    final HttpHeadersBuilder out = HttpHeaders.builder();
    toArmeria(in, out);
    assertThat(out.get(HttpHeaderNames.TE)).isEqualTo(HttpHeaderValues.TRAILERS.toString());
}
 
Example #27
Source Project: armeria   Author: line   File: ArmeriaHttpUtilTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void stripConnectionHeadersAndNominees() {
    final io.netty.handler.codec.http.HttpHeaders in = new DefaultHttpHeaders();
    in.add(HttpHeaderNames.CONNECTION, "foo");
    in.add("foo", "bar");
    final HttpHeadersBuilder out = HttpHeaders.builder();
    toArmeria(in, out);
    assertThat(out).isEmpty();
}
 
Example #28
Source Project: armeria   Author: line   File: ArmeriaHttpUtilTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void stripConnectionNomineesWithCsv() {
    final io.netty.handler.codec.http.HttpHeaders in = new DefaultHttpHeaders();
    in.add(HttpHeaderNames.CONNECTION, "foo,  bar");
    in.add("foo", "baz");
    in.add("bar", "qux");
    in.add("hello", "world");
    final HttpHeadersBuilder out = HttpHeaders.builder();
    toArmeria(in, out);
    assertThat(out).hasSize(1);
    assertThat(out.get(HttpHeaderNames.of("hello"))).isEqualTo("world");
}
 
Example #29
Source Project: curiostack   Author: curioswitch   File: LoggingModule.java    License: MIT License 4 votes vote down vote up
@Multibinds
abstract @RequestHeaderSanitizer Set<Consumer<HttpHeadersBuilder>> requestHeaderSanitizers();
 
Example #30
Source Project: curiostack   Author: curioswitch   File: LoggingModule.java    License: MIT License 4 votes vote down vote up
@Multibinds
abstract @ResponseHeaderSanitizer Set<Consumer<HttpHeadersBuilder>> responseHeaderSanitizers();