Skip to content

Commit

Permalink
Issue #1503 Optionally strip IPv6. Default true
Browse files Browse the repository at this point in the history
  • Loading branch information
gregw authored and joakime committed Jun 26, 2017
1 parent ccf35e6 commit 17f6c28
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 9 deletions.
87 changes: 87 additions & 0 deletions jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
Expand Up @@ -60,6 +60,8 @@
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpUpgradeHandler;
import javax.servlet.http.Part;
import javax.servlet.http.PushBuilder;
import javax.servlet.http.HttpServletMapping;

import org.eclipse.jetty.http.BadMessageException;
import org.eclipse.jetty.http.HostPortHttpField;
Expand Down Expand Up @@ -2462,4 +2464,89 @@ public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IO
{
throw new ServletException("HttpServletRequest.upgrade() not supported in Jetty");
}


public void setPathSpec(PathSpec pathSpec)
{
_pathSpec = pathSpec;
}

public PathSpec getPathSpec()
{
return _pathSpec;
}


// TODO replace with overriden version from API
public HttpServletMapping getMapping()
{
final PathSpec pathSpec = _pathSpec;
final MappingMatch match;
final String mapping;
if (pathSpec instanceof ServletPathSpec)
{
switch(((ServletPathSpec)pathSpec).getGroup())
{
case ROOT:
match = MappingMatch.CONTEXT_ROOT;
mapping = "";
break;
case DEFAULT:
match = MappingMatch.DEFAULT;
mapping = "/";
break;
case EXACT:
match = MappingMatch.EXACT;
mapping = _servletPath;
break;
case SUFFIX_GLOB:
match = MappingMatch.EXTENSION;
int dot = _servletPath.lastIndexOf('.');
mapping = _servletPath.substring(0,dot);
break;
case PREFIX_GLOB:
match = MappingMatch.PATH;
mapping = _servletPath;
break;
default:
match = null;
mapping = _servletPath;
break;
}
}
else
{
match = null;
mapping = _servletPath;
}

return new HttpServletMapping()
{
@Override
public String getMatchValue()
{
return mapping;
}

@Override
public String getPattern()
{
if (pathSpec!=null)
pathSpec.toString();
return null;
}

@Override
public String getServletName()
{
return Request.this.getServletName();
}

@Override
public MappingMatch getMappingMatch()
{
return match;
}
};
}
}
50 changes: 47 additions & 3 deletions jetty-server/src/main/java/org/eclipse/jetty/server/Response.java
Expand Up @@ -108,7 +108,7 @@ public enum OutputType
private OutputType _outputType = OutputType.NONE;
private ResponseWriter _writer;
private long _contentLength = -1;
private Supplier<HttpFields> trailers;
private Supplier<HttpFields> _trailers;

private enum EncodingFrom { NOT_SET, INFERRED, SET_LOCALE, SET_CONTENT_TYPE, SET_CHARACTER_ENCODING }
private static final EnumSet<EncodingFrom> __localeOverride = EnumSet.of(EncodingFrom.NOT_SET,EncodingFrom.INFERRED);
Expand Down Expand Up @@ -1314,12 +1314,27 @@ public void resetBuffer()

public void setTrailers(Supplier<HttpFields> trailers)
{
this.trailers = trailers;
this._trailers = trailers;
}

@Override
public void setTrailerFields(Supplier<Map<String,String>> trailers)
{
// TODO new for 4.0 - avoid transient supplier?
this._trailers = new HttpFieldsSupplier(trailers);
}

public Supplier<HttpFields> getTrailers()
{
return trailers;
return _trailers;
}

@Override
public Supplier<Map<String,String>> getTrailerFields()
{
if (_trailers instanceof HttpFieldsSupplier)
((HttpFieldsSupplier)_trailers).getSupplier();
return null;
}

protected MetaData.Response newResponseMetaData()
Expand Down Expand Up @@ -1487,4 +1502,33 @@ public static void putHeaders(HttpServletResponse response, HttpContent content,
response.setHeader(HttpHeader.ETAG.asString(),et);
}
}

private static class HttpFieldsSupplier implements Supplier<HttpFields>
{
private final Supplier<Map<String, String>> _supplier;

public HttpFieldsSupplier(Supplier<Map<String, String>> trailers)
{
_supplier = trailers;
}

@Override
public HttpFields get()
{
Map<String,String> t = _supplier.get();
if (t==null)
return null;
HttpFields fields = new HttpFields();
for (Map.Entry<String,String> e : t.entrySet())
{
fields.add(e.getKey(),e.getValue());
}
return fields;
}

public Supplier<Map<String, String>> getSupplier()
{
return _supplier;
}
}
}
4 changes: 2 additions & 2 deletions jetty-util/src/main/java/org/eclipse/jetty/util/HostPort.java
Expand Up @@ -23,11 +23,11 @@
* <p>Parse a string in the form "host:port", handling IPv4 an IPv6 hosts</p>
*
* <p>The System property "org.eclipse.jetty.util.HostPort.STRIP_IPV6" can be set to a boolean
* value to control of the square brackets are stripped off IPv6 addresses (default false).</p>
* value to control of the square brackets are stripped off IPv6 addresses (default true).</p>
*/
public class HostPort
{
private final static boolean STRIP_IPV6 = Boolean.parseBoolean(System.getProperty("org.eclipse.jetty.util.HostPort.STRIP_IPV6","false"));
private final static boolean STRIP_IPV6 = Boolean.parseBoolean(System.getProperty("org.eclipse.jetty.util.HostPort.STRIP_IPV6","true"));

private final String _host;
private final int _port;
Expand Down
Expand Up @@ -131,7 +131,7 @@ public void assertExpected(BlockingQueue<WebSocketFrame> framesQueue, List<WebSo
prefix = "Frame[" + i + "]";

WebSocketFrame expected = expect.get(i);
WebSocketFrame actual = framesQueue.poll(3, TimeUnit.SECONDS);
WebSocketFrame actual = framesQueue.poll(10, TimeUnit.SECONDS);
assertThat(prefix + ".poll", actual, notNullValue());

if (LOG.isDebugEnabled())
Expand Down Expand Up @@ -365,4 +365,4 @@ public interface Provider

LocalConnector.LocalEndPoint newLocalConnection();
}
}
}
Expand Up @@ -272,7 +272,19 @@ public void dropServerConnection() throws Exception
assertThat("No frames as output", framesQueue.size(), Matchers.is(0));
}
}


/**
*
* @throws Exception on test failure
*/
@Test
public void testFastFailFastClose() throws Exception
{
fastFail();
fastClose();
}


/**
* Test session open session cleanup (bug #474936)
*
Expand Down
Expand Up @@ -26,7 +26,7 @@ org.eclipse.jetty.LEVEL=WARN
# org.eclipse.jetty.io.WriteFlusher.LEVEL=DEBUG
# org.eclipse.jetty.io.FillInterest.LEVEL=DEBUG
# org.eclipse.jetty.client.LEVEL=DEBUG
# org.eclipse.jetty.websocket.LEVEL=DEBUG
org.eclipse.jetty.websocket.LEVEL=DEBUG
# org.eclipse.jetty.websocket.LEVEL=INFO
# org.eclipse.jetty.websocket.jsr356.messages.LEVEL=DEBUG
# org.eclipse.jetty.websocket.tests.LEVEL=DEBUG
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -21,6 +21,7 @@
<jetty-test-policy-version>1.2</jetty-test-policy-version>
<alpn.api.version>1.1.3.v20160715</alpn.api.version>
<jsp.version>8.5.9.1</jsp.version>
<servlet.api.version>4.0.0-b07</servlet.api.version>
<!-- default values are unsupported, but required to be defined for reactor sanity reasons -->
<alpn.version>undefined</alpn.version>
</properties>
Expand Down

0 comments on commit 17f6c28

Please sign in to comment.