|
59 | 59 | import org.eclipse.jetty.io.ClientConnector;
|
60 | 60 | import org.eclipse.jetty.io.Content;
|
61 | 61 | import org.eclipse.jetty.io.EndPoint;
|
| 62 | +import org.eclipse.jetty.io.RetainableByteBuffer; |
62 | 63 | import org.eclipse.jetty.logging.StacklessLogging;
|
63 | 64 | import org.eclipse.jetty.server.Handler;
|
| 65 | +import org.eclipse.jetty.server.HttpConfiguration; |
| 66 | +import org.eclipse.jetty.server.HttpConnectionFactory; |
64 | 67 | import org.eclipse.jetty.server.internal.HttpChannelState;
|
65 | 68 | import org.eclipse.jetty.toolchain.test.Net;
|
66 | 69 | import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
@@ -1936,6 +1939,108 @@ protected void service(org.eclipse.jetty.server.Request request, org.eclipse.jet
|
1936 | 1939 | assertEquals(HttpStatus.OK_200, response.getStatus());
|
1937 | 1940 | }
|
1938 | 1941 |
|
| 1942 | + @ParameterizedTest |
| 1943 | + @ArgumentsSource(ScenarioProvider.class) |
| 1944 | + public void testRequestHeadersSizeOverflow(Scenario scenario) throws Exception |
| 1945 | + { |
| 1946 | + start(scenario, new EmptyServerHandler()); |
| 1947 | + |
| 1948 | + RetainableByteBuffer buffer = client.getByteBufferPool().acquire(client.getRequestBufferSize(), false); |
| 1949 | + int capacity = buffer.capacity(); |
| 1950 | + buffer.release(); |
| 1951 | + client.setMaxRequestHeadersSize(3 * capacity); |
| 1952 | + connector.getBean(HttpConnectionFactory.class).getHttpConfiguration().setRequestHeaderSize(3 * capacity); |
| 1953 | + |
| 1954 | + ContentResponse response = client.newRequest("localhost", connector.getLocalPort()) |
| 1955 | + .scheme(scenario.getScheme()) |
| 1956 | + // Overflow the default request headers size, but don't exceed the max. |
| 1957 | + .agent("A".repeat(2 * capacity)) |
| 1958 | + .timeout(5, TimeUnit.SECONDS) |
| 1959 | + .send(); |
| 1960 | + |
| 1961 | + assertEquals(HttpStatus.OK_200, response.getStatus()); |
| 1962 | + } |
| 1963 | + |
| 1964 | + @ParameterizedTest |
| 1965 | + @ArgumentsSource(ScenarioProvider.class) |
| 1966 | + public void testResponseHeadersSizeOverflow(Scenario scenario) throws Exception |
| 1967 | + { |
| 1968 | + start(scenario, new EmptyServerHandler() |
| 1969 | + { |
| 1970 | + @Override |
| 1971 | + protected void service(org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response) |
| 1972 | + { |
| 1973 | + int capacity = (int)request.getHeaders().getLongField("X-Capacity"); |
| 1974 | + // Overflow the default response headers size, but don't exceed the max. |
| 1975 | + response.getHeaders().put("X-Large", "A".repeat(2 * capacity)); |
| 1976 | + } |
| 1977 | + }); |
| 1978 | + |
| 1979 | + HttpConfiguration httpConfig = connector.getBean(HttpConnectionFactory.class).getHttpConfiguration(); |
| 1980 | + RetainableByteBuffer buffer = server.getByteBufferPool().acquire(httpConfig.getResponseHeaderSize(), false); |
| 1981 | + int capacity = buffer.capacity(); |
| 1982 | + buffer.release(); |
| 1983 | + httpConfig.setMaxResponseHeaderSize(3 * capacity); |
| 1984 | + client.setMaxResponseHeadersSize(3 * capacity); |
| 1985 | + |
| 1986 | + ContentResponse response = client.newRequest("localhost", connector.getLocalPort()) |
| 1987 | + .scheme(scenario.getScheme()) |
| 1988 | + .headers(h -> h.put("X-Capacity", capacity)) |
| 1989 | + .timeout(5, TimeUnit.SECONDS) |
| 1990 | + .send(); |
| 1991 | + |
| 1992 | + assertEquals(HttpStatus.OK_200, response.getStatus()); |
| 1993 | + } |
| 1994 | + |
| 1995 | + @ParameterizedTest |
| 1996 | + @ArgumentsSource(ScenarioProvider.class) |
| 1997 | + public void testMaxRequestHeadersSize(Scenario scenario) throws Exception |
| 1998 | + { |
| 1999 | + start(scenario, new EmptyServerHandler()); |
| 2000 | + |
| 2001 | + RetainableByteBuffer buffer = client.getByteBufferPool().acquire(client.getRequestBufferSize(), false); |
| 2002 | + int capacity = buffer.capacity(); |
| 2003 | + buffer.release(); |
| 2004 | + client.setMaxRequestHeadersSize(2 * capacity); |
| 2005 | + connector.getBean(HttpConnectionFactory.class).getHttpConfiguration().setRequestHeaderSize(4 * capacity); |
| 2006 | + |
| 2007 | + assertThrows(ExecutionException.class, () -> client.newRequest("localhost", connector.getLocalPort()) |
| 2008 | + .scheme(scenario.getScheme()) |
| 2009 | + // Overflow the max request headers size. |
| 2010 | + .agent("A".repeat(3 * capacity)) |
| 2011 | + .timeout(5, TimeUnit.SECONDS) |
| 2012 | + .send()); |
| 2013 | + } |
| 2014 | + |
| 2015 | + @ParameterizedTest |
| 2016 | + @ArgumentsSource(ScenarioProvider.class) |
| 2017 | + public void testMaxResponseHeadersSize(Scenario scenario) throws Exception |
| 2018 | + { |
| 2019 | + start(scenario, new EmptyServerHandler() |
| 2020 | + { |
| 2021 | + @Override |
| 2022 | + protected void service(org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response) throws Throwable |
| 2023 | + { |
| 2024 | + int capacity = (int)request.getHeaders().getLongField("X-Capacity"); |
| 2025 | + // Overflow the max request headers size, should generate a 500. |
| 2026 | + response.getHeaders().put("X-Large", "A".repeat(3 * capacity)); |
| 2027 | + } |
| 2028 | + }); |
| 2029 | + |
| 2030 | + HttpConfiguration httpConfig = connector.getBean(HttpConnectionFactory.class).getHttpConfiguration(); |
| 2031 | + RetainableByteBuffer buffer = server.getByteBufferPool().acquire(httpConfig.getResponseHeaderSize(), false); |
| 2032 | + int capacity = buffer.capacity(); |
| 2033 | + buffer.release(); |
| 2034 | + httpConfig.setMaxResponseHeaderSize(2 * capacity); |
| 2035 | + client.setMaxResponseHeadersSize(4 * capacity); |
| 2036 | + |
| 2037 | + assertThrows(ExecutionException.class, () -> client.newRequest("localhost", connector.getLocalPort()) |
| 2038 | + .scheme(scenario.getScheme()) |
| 2039 | + .headers(h -> h.put("X-Capacity", capacity)) |
| 2040 | + .timeout(5, TimeUnit.SECONDS) |
| 2041 | + .send()); |
| 2042 | + } |
| 2043 | + |
1939 | 2044 | private void assertCopyRequest(Request original)
|
1940 | 2045 | {
|
1941 | 2046 | Request copy = client.copyRequest(original, original.getURI());
|
|
0 commit comments