|
| 1 | +/* |
| 2 | + * Copyright 2025 LINE Corporation |
| 3 | + * |
| 4 | + * LINE Corporation licenses this file to you under the Apache License, |
| 5 | + * version 2.0 (the "License"); you may not use this file except in compliance |
| 6 | + * with the License. You may obtain a copy of the License at: |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | + * License for the specific language governing permissions and limitations |
| 14 | + * under the License. |
| 15 | + */ |
| 16 | +package com.linecorp.armeria.client; |
| 17 | + |
| 18 | +import static org.assertj.core.api.Assertions.assertThat; |
| 19 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 20 | + |
| 21 | +import java.time.Duration; |
| 22 | +import java.util.concurrent.CompletableFuture; |
| 23 | + |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 26 | + |
| 27 | +import com.google.common.base.Strings; |
| 28 | + |
| 29 | +import com.linecorp.armeria.common.AggregatedHttpResponse; |
| 30 | +import com.linecorp.armeria.common.HttpMethod; |
| 31 | +import com.linecorp.armeria.common.HttpResponse; |
| 32 | +import com.linecorp.armeria.common.HttpStatus; |
| 33 | +import com.linecorp.armeria.common.RequestHeaders; |
| 34 | +import com.linecorp.armeria.server.ServerBuilder; |
| 35 | +import com.linecorp.armeria.testing.junit5.server.ServerExtension; |
| 36 | + |
| 37 | +import io.netty.handler.codec.http2.Http2Exception.HeaderListSizeException; |
| 38 | + |
| 39 | +class HeaderListSizeExceptionTest { |
| 40 | + |
| 41 | + @RegisterExtension |
| 42 | + static ServerExtension server = new ServerExtension() { |
| 43 | + @Override |
| 44 | + protected void configure(ServerBuilder sb) { |
| 45 | + sb.service("/", (ctx, req) -> HttpResponse.delayed( |
| 46 | + () -> HttpResponse.of("OK"), Duration.ofMillis(100))); |
| 47 | + } |
| 48 | + }; |
| 49 | + |
| 50 | + @Test |
| 51 | + void doNotSendRstStreamWhenHeaderListSizeExceptionIsRaised() throws InterruptedException { |
| 52 | + final CompletableFuture<AggregatedHttpResponse> future = server.webClient().get("/").aggregate(); |
| 53 | + final String a = Strings.repeat("aa", 10000); |
| 54 | + final RequestHeaders headers = RequestHeaders.of(HttpMethod.GET, "/", "foo", "bar", |
| 55 | + "baz", a); |
| 56 | + assertThatThrownBy(() -> server.webClient().execute(headers).aggregate().join()) |
| 57 | + .hasCauseInstanceOf(UnprocessedRequestException.class) |
| 58 | + .cause() |
| 59 | + .hasCauseInstanceOf(HeaderListSizeException.class); |
| 60 | + // If the client sends RST_STREAM with invalid stream ID, the server will send GOAWAY back thus |
| 61 | + // the first request will be failed with ClosedSessionException. |
| 62 | + assertThat(future.join().status()).isSameAs(HttpStatus.OK); |
| 63 | + } |
| 64 | +} |
0 commit comments