Skip to content

Commit

Permalink
Fix #6860 IPv6 Format (#6861)
Browse files Browse the repository at this point in the history
Fix #6860 IPv6 format by adding an extensible HttpChannel method

Signed-off-by: Greg Wilkins <gregw@webtide.com>
Co-authored-by: Lachlan Roberts <lachlan@webtide.com>
Signed-off-by: Greg Wilkins <gregw@webtide.com>
# Conflicts:
#	jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java
#	jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
#	jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java
#	jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java
  • Loading branch information
gregw committed Sep 23, 2021
1 parent 72f3479 commit 6646405
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
Expand Up @@ -74,6 +74,7 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jetty.http.tools.matchers.HttpFieldsMatchers.containsHeader;
import static org.eclipse.jetty.http.tools.matchers.HttpFieldsMatchers.containsHeaderValue;
import static org.eclipse.jetty.http.tools.matchers.HttpFieldsMatchers.headerValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsString;
Expand Down Expand Up @@ -881,25 +882,25 @@ public void testWelcomeRedirect() throws Exception
rawResponse = connector.getResponse("GET /context/dir/ HTTP/1.0\r\n\r\n");
response = HttpTester.parseResponse(rawResponse);
assertThat(response.toString(), response.getStatus(), is(HttpStatus.MOVED_TEMPORARILY_302));
assertThat(response, containsHeaderValue("Location", "http://0.0.0.0/context/dir/index.html"));
assertThat(response, headerValue("Location", "http://0.0.0.0/context/dir/index.html"));

createFile(inde, "<h1>Hello Inde</h1>");
rawResponse = connector.getResponse("GET /context/dir HTTP/1.0\r\n\r\n");
response = HttpTester.parseResponse(rawResponse);
assertThat(response.toString(), response.getStatus(), is(HttpStatus.MOVED_TEMPORARILY_302));
assertThat(response, containsHeaderValue("Location", "http://0.0.0.0/context/dir/"));
assertThat(response, headerValue("Location", "http://0.0.0.0/context/dir/"));

rawResponse = connector.getResponse("GET /context/dir/ HTTP/1.0\r\n\r\n");
response = HttpTester.parseResponse(rawResponse);
assertThat(response.toString(), response.getStatus(), is(HttpStatus.MOVED_TEMPORARILY_302));
assertThat(response, containsHeaderValue("Location", "http://0.0.0.0/context/dir/index.html"));
assertThat(response, headerValue("Location", "http://0.0.0.0/context/dir/index.html"));

if (deleteFile(index))
{
rawResponse = connector.getResponse("GET /context/dir/ HTTP/1.0\r\n\r\n");
response = HttpTester.parseResponse(rawResponse);
assertThat(response.toString(), response.getStatus(), is(HttpStatus.MOVED_TEMPORARILY_302));
assertThat(response, containsHeaderValue("Location", "http://0.0.0.0/context/dir/index.htm"));
assertThat(response, headerValue("Location", "http://0.0.0.0/context/dir/index.htm"));

if (deleteFile(inde))
{
Expand Down Expand Up @@ -937,20 +938,17 @@ public void testRelativeRedirect() throws Exception
rawResponse = connector.getResponse("GET /context/dir HTTP/1.0\r\n\r\n");
response = HttpTester.parseResponse(rawResponse);
assertThat(response.toString(), response.getStatus(), is(HttpStatus.MOVED_TEMPORARILY_302));
assertThat(response, containsHeaderValue("Location", "/context/dir/"));
assertThat(response, not(containsHeaderValue("Location", "http://")));
assertThat(response, headerValue("Location", "/context/dir/"));

rawResponse = connector.getResponse("GET /context/dir/ HTTP/1.0\r\n\r\n");
response = HttpTester.parseResponse(rawResponse);
assertThat(response.toString(), response.getStatus(), is(HttpStatus.MOVED_TEMPORARILY_302));
assertThat(response, containsHeaderValue("Location", "/context/dir/index.html"));
assertThat(response, not(containsHeaderValue("Location", "http://")));
assertThat(response, headerValue("Location", "/context/dir/index.html"));

rawResponse = connector.getResponse("GET /context/dir/index.html/ HTTP/1.0\r\n\r\n");
response = HttpTester.parseResponse(rawResponse);
assertThat(response.toString(), response.getStatus(), is(HttpStatus.MOVED_TEMPORARILY_302));
assertThat(response, containsHeaderValue("Location", "/context/dir/index.html"));
assertThat(response, not(containsHeaderValue("Location", "http://")));
assertThat(response, headerValue("Location", "/context/dir/index.html"));
}

/**
Expand Down
@@ -1,22 +1,17 @@
//
// ========================================================================
// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// ========================================================================
// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//

package org.eclipse.jetty.http.matchers;
package org.eclipse.jetty.http.tools.matchers;

import java.util.Objects;

Expand Down
Expand Up @@ -29,6 +29,11 @@ public static Matcher<HttpFields> containsHeader(HttpHeader header)
return new HttpFieldsContainsHeaderKey(header);
}

public static Matcher<HttpFields> headerValue(String keyName, String value)
{
return new HttpFieldsHeaderValue(keyName, value);
}

public static Matcher<HttpFields> containsHeaderValue(String keyName, String value)
{
return new HttpFieldsContainsHeaderValue(keyName, value);
Expand Down

0 comments on commit 6646405

Please sign in to comment.