backport of fixes for #592 (#1208)

Signed-off-by: olivier lamy <olamy@webtide.com>
This commit is contained in:
Olivier Lamy 2017-01-01 10:33:51 +01:00 committed by Greg Wilkins
parent 6b3b59df43
commit 9bc4cd32fc
6 changed files with 47 additions and 26 deletions

2
Jenkinsfile vendored
View File

@ -1,6 +1,6 @@
#!groovy #!groovy
node('linux') { node {
// System Dependent Locations // System Dependent Locations
def mvntool = tool name: 'maven3', type: 'hudson.tasks.Maven$MavenInstallation' def mvntool = tool name: 'maven3', type: 'hudson.tasks.Maven$MavenInstallation'
def jdktool = tool name: 'jdk7', type: 'hudson.model.JDK' def jdktool = tool name: 'jdk7', type: 'hudson.model.JDK'

View File

@ -832,9 +832,10 @@ public class HttpParser
case HOST: case HOST:
add_to_connection_trie=_connectionFields!=null && _field==null; add_to_connection_trie=_connectionFields!=null && _field==null;
_host=true; _host=true;
if (_valueString==null || _valueString.length()==0) if (_valueString==null || _valueString.length()==0)
{ {
throw new BadMessageException(HttpStatus.BAD_REQUEST_400,"Bad Host header"); break;
} }
try try

View File

@ -114,7 +114,8 @@ public class DumpHandler extends AbstractHandler
String name=headers.nextElement(); String name=headers.nextElement();
writer.write(name); writer.write(name);
writer.write(": "); writer.write(": ");
writer.write(request.getHeader(name)); String value = request.getHeader(name);
writer.write(value == null?"":value);
writer.write("\n"); writer.write("\n");
} }
writer.write("</pre>\n<h3>Parameters:</h3>\n<pre>"); writer.write("</pre>\n<h3>Parameters:</h3>\n<pre>");

View File

@ -24,26 +24,6 @@
*/ */
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpParser; import org.eclipse.jetty.http.HttpParser;
import org.eclipse.jetty.http.MimeTypes; import org.eclipse.jetty.http.MimeTypes;
@ -56,9 +36,25 @@ import org.hamcrest.Matchers;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* *
*/ */
@ -335,6 +331,29 @@ public class HttpConnectionTest
checkContains(response,0,"HTTP/1.1 400"); checkContains(response,0,"HTTP/1.1 400");
} }
@Test
public void testNoHost()
throws Exception
{
String response;
response = connector.getResponses( "GET / HTTP/1.1\r\n"
+ "\r\n" );
checkContains( response, 0, "HTTP/1.1 400" );
}
@Test
public void testEmptyHost()
throws Exception
{
String response;
response = connector.getResponses( "GET / HTTP/1.1\r\n"
+ "Host:\r\n"
+ "\r\n" );
checkContains( response, 0, "HTTP/1.1 200" );
}
@Test @Test
public void testBadURIencoding() throws Exception public void testBadURIencoding() throws Exception
{ {

View File

@ -546,7 +546,7 @@ public class PartialRFC2616Test
offset=0; offset=0;
response=connector.getResponses("GET /R1 HTTP/1.1\n"+"Host:\n"+"Connection: close\n"+"\n"); response=connector.getResponses("GET /R1 HTTP/1.1\n"+"Host:\n"+"Connection: close\n"+"\n");
offset=checkContains(response,offset,"HTTP/1.1 400","400")+1; offset=checkContains(response,offset,"HTTP/1.1 200","200")+1;
} }
@Test @Test

View File

@ -1454,7 +1454,7 @@ public abstract class RFC2616BaseTest
req4.append("\n"); req4.append("\n");
HttpTester.Response response = http.request(req4); HttpTester.Response response = http.request(req4);
assertEquals("14.23 HTTP/1.1 - Empty Host", HttpStatus.BAD_REQUEST_400, response.getStatus()); assertEquals("14.23 HTTP/1.1 - Empty Host", HttpStatus.OK_200, response.getStatus());
} }
/** /**