Skip to content

Commit c174c9a

Browse files
committed
[UNDERTOW-2654] preserve status line in proxy scenarios
1 parent 6d05233 commit c174c9a

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* JBoss, Home of Professional Open Source.
3+
* Copyright 2025 Red Hat, Inc., and individual contributors
4+
* as indicated by the @author tags.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package io.undertow.server.handlers;
19+
20+
import java.io.IOException;
21+
import java.util.concurrent.ExecutionException;
22+
23+
import org.apache.http.HttpResponse;
24+
import org.apache.http.client.methods.HttpGet;
25+
import org.junit.Assert;
26+
import org.junit.Before;
27+
import org.junit.Test;
28+
import org.junit.runner.RunWith;
29+
30+
import io.undertow.server.HttpHandler;
31+
import io.undertow.server.HttpServerExchange;
32+
import io.undertow.testutils.DefaultServer;
33+
import io.undertow.testutils.HttpOneOnly;
34+
import io.undertow.testutils.TestHttpClient;
35+
import io.undertow.util.StatusCodes;
36+
37+
@RunWith(DefaultServer.class)
38+
@HttpOneOnly // Http2 does NOT have way to transfer status: https://httpwg.org/specs/rfc7540.html#rfc.section.8.1.2.4
39+
// https://www.rfc-editor.org/rfc/rfc9113.html#name-response-pseudo-header-fiel
40+
public class PreseverStatusTestCase {
41+
private static final String CUSTOM_REASON = "Its just a flesh wound";
42+
43+
@Before
44+
public void setup() {
45+
46+
DefaultServer.setRootHandler(new BlockingHandler(new HttpHandler() {
47+
48+
@Override
49+
public void handleRequest(HttpServerExchange exchange) throws Exception {
50+
exchange.setStatusCode(StatusCodes.TOO_MANY_REQUESTS);
51+
exchange.setReasonPhrase(CUSTOM_REASON);
52+
}}));
53+
}
54+
55+
@Test
56+
public void testWindowSliding() throws ExecutionException, InterruptedException {
57+
TestHttpClient client = new TestHttpClient();
58+
try {
59+
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL());
60+
HttpResponse result = client.execute(get);
61+
Assert.assertEquals(StatusCodes.TOO_MANY_REQUESTS, result.getStatusLine().getStatusCode());
62+
Assert.assertEquals(CUSTOM_REASON, result.getStatusLine().getReasonPhrase());
63+
} catch (IOException e) {
64+
throw new RuntimeException(e);
65+
} finally {
66+
client.getConnectionManager().shutdown();
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)