Skip to content

Commit

Permalink
asf
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhee17 committed Dec 11, 2024
1 parent 533e8bd commit 7d629bf
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright 2021 LINE Corporation
*
* LINE Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package com.linecorp.armeria.server;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

import com.linecorp.armeria.client.ClientFactory;
import com.linecorp.armeria.client.WebClient;
import com.linecorp.armeria.common.AggregatedHttpResponse;
import com.linecorp.armeria.common.ClosedSessionException;
import com.linecorp.armeria.common.HttpData;
import com.linecorp.armeria.common.HttpHeaderNames;
import com.linecorp.armeria.common.HttpResponse;
import com.linecorp.armeria.common.HttpResponseWriter;
import com.linecorp.armeria.common.HttpStatus;
import com.linecorp.armeria.common.MediaType;
import com.linecorp.armeria.common.ResponseHeaders;
import com.linecorp.armeria.common.SessionProtocol;
import com.linecorp.armeria.testing.junit5.server.ServerExtension;

class HttpServerTooLargeContent2Test {

@RegisterExtension
static ServerExtension server = new ServerExtension() {
@Override
protected void configure(ServerBuilder sb) {
sb.tlsSelfSigned();
sb.https(0);
sb.http(0);
sb.maxRequestLength(5);
sb.decorator((delegate, ctx, req) -> {
if (req.headers().contentLength() > 5) {
return HttpResponse.of(HttpStatus.OK,
MediaType.PLAIN_TEXT_UTF_8, "custom response");
}
return delegate.serve(ctx, req);
});
sb.service("/", (ctx, req) -> {
final HttpResponseWriter streaming = HttpResponse.streaming();
streaming.write(ResponseHeaders.of(HttpStatus.OK, HttpHeaderNames.CONTENT_LENGTH, 7));
req.aggregate().handle((aggregatedHttpRequest, cause) -> {
if (cause != null) {
streaming.close(cause);
} else {
streaming.write(HttpData.ofUtf8("content"));
streaming.close();
}
return null;
});
return streaming;
});
}
};

@ParameterizedTest
@EnumSource(value = SessionProtocol.class, names = { "H1", "H1C" })
void closedSessionForHttp1_contentTooLargeAfterResponseHeadersSent(SessionProtocol sessionProtocol) {
final WebClient client = WebClient.builder(server.uri(sessionProtocol))
.factory(ClientFactory.insecure())
.build();
assertThatThrownBy(() -> client.post("/", "abcdefgh").aggregate().join()).hasCauseInstanceOf(
ClosedSessionException.class);
}

@ParameterizedTest
@EnumSource(value = SessionProtocol.class, names = { "H2C" })
void closedStreamForHttp2_contentTooLargeAfterResponseHeadersSent(SessionProtocol sessionProtocol) {
final WebClient client = WebClient.builder(server.uri(sessionProtocol))
.factory(ClientFactory.insecure())
.build();
final AggregatedHttpResponse res = client.post("/", "abcdefgh").aggregate().join();
assertThat(res.status().code()).isEqualTo(HttpStatus.OK.code());
assertThat(res.contentUtf8()).isEqualTo("custom response");
}
}
4 changes: 2 additions & 2 deletions testing-internal/src/main/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

<logger name="com.linecorp.armeria" level="DEBUG" />
<logger name="com.linecorp.armeria.logging.traffic.server" level="OFF" />
<logger name="com.linecorp.armeria.logging.traffic.server.http2" level="OFF" />
<logger name="com.linecorp.armeria.logging.traffic.server.http2" level="trace" />
<logger name="com.linecorp.armeria.logging.traffic.client" level="OFF" />
<logger name="com.linecorp.armeria.logging.traffic.client.http2" level="OFF" />
<logger name="com.linecorp.armeria.logging.traffic.client.http2" level="trace" />
<logger name="com.linecorp.armeria.internal.common.Http2GoAwayHandler" level="INFO" />
<logger name="io.netty.resolver.dns.TraceDnsQueryLifeCycleObserverFactory" level="DEBUG" />
<logger name="reactor" level="INFO" />
Expand Down

0 comments on commit 7d629bf

Please sign in to comment.