Java Code Examples for com.linecorp.armeria.common.HttpHeaders#of()
The following examples show how to use
com.linecorp.armeria.common.HttpHeaders#of() .
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 File: ArmeriaServerCallTest.java From armeria with Apache License 2.0 | 6 votes |
@Test public void messageRead_wrappedByteBuf() { tearDown(); call = new ArmeriaServerCall<>( HttpHeaders.of(), TestServiceGrpc.getUnaryCallMethod(), CompressorRegistry.getDefaultInstance(), DecompressorRegistry.getDefaultInstance(), res, MAX_MESSAGE_BYTES, MAX_MESSAGE_BYTES, ctx, GrpcSerializationFormats.PROTO, new DefaultJsonMarshaller(MessageMarshaller.builder().build()), true, false, ResponseHeaders.builder(HttpStatus.OK) .contentType(GrpcSerializationFormats.PROTO.mediaType()) .build()); final ByteBuf buf = GrpcTestUtil.requestByteBuf(); call.messageRead(new DeframedMessage(buf, 0)); verify(buffersAttr).put(any(), same(buf)); }
Example 2
Source File: JacksonResponseConverterFunctionTest.java From armeria with Apache License 2.0 | 6 votes |
@Test void aggregatedJson() throws Exception { expectAggregatedJson(Stream.of(TEST_STRINGS)) .expectComplete() .verify(); expectAggregatedJson(Flux.fromArray(TEST_STRINGS)) .expectComplete() .verify(); // Iterable with trailers. final HttpHeaders trailer = HttpHeaders.of(AsciiString.of("x-trailer"), "value"); expectAggregatedJson(Arrays.asList(TEST_STRINGS), JSON_HEADERS, trailer) .expectNext(trailer) .expectComplete() .verify(); }
Example 3
Source File: JacksonResponseConverterFunctionTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void jsonTextSequences_publisher() throws Exception { expectJsonSeqContents(Flux.fromArray(TEST_STRINGS)) .expectComplete() .verify(); // With trailers. final HttpHeaders trailer = HttpHeaders.of(AsciiString.of("x-trailer"), "value"); expectJsonSeqContents(Flux.fromArray(TEST_STRINGS), JSON_SEQ_HEADERS, trailer) .expectNext(trailer) .expectComplete() .verify(); }
Example 4
Source File: ArmeriaServerCallTest.java From armeria with Apache License 2.0 | 5 votes |
@Before public void setUp() { completionFuture = new CompletableFuture<>(); when(res.whenComplete()).thenReturn(completionFuture); ctx = ServiceRequestContext.builder(HttpRequest.of(HttpMethod.POST, "/")) .eventLoop(eventLoop.get()) .build(); call = new ArmeriaServerCall<>( HttpHeaders.of(), TestServiceGrpc.getUnaryCallMethod(), CompressorRegistry.getDefaultInstance(), DecompressorRegistry.getDefaultInstance(), res, MAX_MESSAGE_BYTES, MAX_MESSAGE_BYTES, ctx, GrpcSerializationFormats.PROTO, new DefaultJsonMarshaller(MessageMarshaller.builder().build()), false, false, ResponseHeaders.builder(HttpStatus.OK) .contentType(GrpcSerializationFormats.PROTO.mediaType()) .build()); call.setListener(listener); call.messageReader().onSubscribe(subscription); ctx.setAttr(GrpcUnsafeBufferUtil.BUFFERS, buffersAttr); }
Example 5
Source File: DefaultServiceRequestContextTest.java From armeria with Apache License 2.0 | 5 votes |
private static void mutateAdditionalTrailers(ServiceRequestContext originalCtx) { originalCtx.mutateAdditionalResponseTrailers( mutator -> mutator.add(HttpHeaderNames.of("my-trailer#2"), "value#2")); final HttpHeaders trailers2 = HttpHeaders.of(HttpHeaderNames.of("my-trailer#3"), "value#3"); originalCtx.mutateAdditionalResponseTrailers(mutator -> mutator.add(trailers2)); originalCtx.mutateAdditionalResponseTrailers( mutator -> mutator.add(HttpHeaderNames.of("my-trailer#4"), "value#4")); }
Example 6
Source File: DefaultServiceRequestContextTest.java From armeria with Apache License 2.0 | 5 votes |
private static void mutateAdditionalHeaders(ServiceRequestContext originalCtx) { originalCtx.mutateAdditionalResponseHeaders( mutator -> mutator.add(HttpHeaderNames.of("my-header#2"), "value#2")); final HttpHeaders headers2 = HttpHeaders.of(HttpHeaderNames.of("my-header#3"), "value#3"); originalCtx.mutateAdditionalResponseHeaders(mutator -> mutator.add(headers2)); originalCtx.mutateAdditionalResponseHeaders( mutator -> mutator.add(HttpHeaderNames.of("my-header#4"), "value#4")); }
Example 7
Source File: DefaultClientRequestContextTest.java From armeria with Apache License 2.0 | 5 votes |
private static void mutateAdditionalHeaders(ClientRequestContext originalCtx) { final HttpHeaders headers1 = HttpHeaders.of(HttpHeaderNames.of("my-header#1"), "value#1"); originalCtx.mutateAdditionalRequestHeaders(mutator -> mutator.add(headers1)); originalCtx.mutateAdditionalRequestHeaders( mutator -> mutator.add(HttpHeaderNames.of("my-header#2"), "value#2")); final HttpHeaders headers2 = HttpHeaders.of(HttpHeaderNames.of("my-header#3"), "value#3"); originalCtx.mutateAdditionalRequestHeaders(mutator -> mutator.add(headers2)); originalCtx.mutateAdditionalRequestHeaders( mutator -> mutator.add(HttpHeaderNames.of("my-header#4"), "value#4")); // Remove the first one. originalCtx.mutateAdditionalRequestHeaders( mutator -> mutator.remove(HttpHeaderNames.of("my-header#1"))); }
Example 8
Source File: ClientOptionsTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void testSetHttpHeader() { final HttpHeaders httpHeader = HttpHeaders.of(HttpHeaderNames.of("x-user-defined"), "HEADER_VALUE"); final ClientOptions options = ClientOptions.of(HTTP_HEADERS.newValue(httpHeader)); assertThat(options.get(HTTP_HEADERS)).isEqualTo(httpHeader); final ClientOptions options2 = ClientOptions.of(); assertThat(options2.get(HTTP_HEADERS)).isEqualTo(HttpHeaders.of()); }
Example 9
Source File: ClientOptionsTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void testAsMap() { final HttpHeaders httpHeader = HttpHeaders.of(HttpHeaderNames.of("x-user-defined"), "HEADER_VALUE"); final ClientOptions options = ClientOptions.of(HTTP_HEADERS.newValue(httpHeader)); final Map<ClientOption<Object>, ClientOptionValue<Object>> map = options.asMap(); assertThat(map).hasSize(1); assertThat(map.get(HTTP_HEADERS).value()).isEqualTo(httpHeader); }
Example 10
Source File: RoutingContextTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void testAcceptTypes() { final HttpHeaders headers = HttpHeaders.of( HttpHeaderNames.ACCEPT, "application/xml;q=0.9, " + "*/*;q=0.8, " + "text/html;charset=UTF-8, " + "application/xhtml+xml;charset=utf-8"); final List<MediaType> acceptTypes = extractAcceptTypes(headers); assertThat(acceptTypes).containsExactly(MediaType.XHTML_UTF_8, MediaType.HTML_UTF_8, MediaType.parse("application/xml;q=0.9"), MediaType.parse("*/*;q=0.8")); }
Example 11
Source File: HttpRequestAggregator.java From armeria with Apache License 2.0 | 4 votes |
public HttpRequestAggregator(HttpRequest request, CompletableFuture<AggregatedHttpRequest> future, @Nullable ByteBufAllocator alloc) { super(future, alloc); this.request = request; trailers = HttpHeaders.of(); }
Example 12
Source File: HttpRequestAggregator.java From armeria with Apache License 2.0 | 4 votes |
@Override protected void onFailure() { trailers = HttpHeaders.of(); }
Example 13
Source File: HttpResponseAggregator.java From armeria with Apache License 2.0 | 4 votes |
@Override protected void onFailure() { headers = null; trailers = HttpHeaders.of(); }
Example 14
Source File: ContentPreviewerTest.java From armeria with Apache License 2.0 | 4 votes |
ContentPreviewer hexDumpContentPreviewer() { return new ProducerBasedContentPreviewer(100, HttpHeaders.of(), hexDumpProducer()); }
Example 15
Source File: DefaultHttpResult.java From armeria with Apache License 2.0 | 4 votes |
DefaultHttpResult(HttpHeaders headers, T content) { this(headers, requireNonNull(content, "content"), HttpHeaders.of()); }
Example 16
Source File: DefaultHttpResult.java From armeria with Apache License 2.0 | 4 votes |
DefaultHttpResult(HttpHeaders headers) { this(headers, null, HttpHeaders.of()); }
Example 17
Source File: HttpResult.java From armeria with Apache License 2.0 | 4 votes |
/** * Returns the HTTP trailers of a response. */ default HttpHeaders trailers() { return HttpHeaders.of(); }
Example 18
Source File: DefaultServiceRequestContext.java From armeria with Apache License 2.0 | 3 votes |
/** * Creates a new instance. * * @param cfg the {@link ServiceConfig} * @param ch the {@link Channel} that handles the invocation * @param meterRegistry the {@link MeterRegistry} that collects various stats * @param sessionProtocol the {@link SessionProtocol} of the invocation * @param id the {@link RequestId} that represents the identifier of the current {@link Request} * and {@link Response} pair. * @param routingContext the parameters which are used when finding a matched {@link Route} * @param routingResult the result of finding a matched {@link Route} * @param req the request associated with this context * @param sslSession the {@link SSLSession} for this invocation if it is over TLS * @param proxiedAddresses source and destination addresses delivered through proxy servers * @param clientAddress the address of a client who initiated the request * @param requestStartTimeNanos {@link System#nanoTime()} value when the request started. * @param requestStartTimeMicros the number of microseconds since the epoch, * e.g. {@code System.currentTimeMillis() * 1000}. */ public DefaultServiceRequestContext( ServiceConfig cfg, Channel ch, MeterRegistry meterRegistry, SessionProtocol sessionProtocol, RequestId id, RoutingContext routingContext, RoutingResult routingResult, HttpRequest req, @Nullable SSLSession sslSession, ProxiedAddresses proxiedAddresses, InetAddress clientAddress, long requestStartTimeNanos, long requestStartTimeMicros) { this(cfg, ch, meterRegistry, sessionProtocol, id, routingContext, routingResult, req, sslSession, proxiedAddresses, clientAddress, requestStartTimeNanos, requestStartTimeMicros, HttpHeaders.of(), HttpHeaders.of()); }
Example 19
Source File: FileServiceBuilder.java From armeria with Apache License 2.0 | 2 votes |
/** * Returns the immutable additional {@link HttpHeaders} which will be set when building an * {@link HttpResponse}. */ HttpHeaders buildHeaders() { return headers != null ? headers.build() : HttpHeaders.of(); }
Example 20
Source File: AbstractHttpFileBuilder.java From armeria with Apache License 2.0 | 2 votes |
/** * Returns the immutable additional {@link HttpHeaders} which will be set when building an * {@link HttpResponse}. */ protected final HttpHeaders buildHeaders() { return headers != null ? headers.build() : HttpHeaders.of(); }