From f3e2b0248d0f7c57e188754103b84463b2c4333c Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Tue, 23 Mar 2010 20:24:11 +0000 Subject: [PATCH] 306840 suppress content-length in requests without content git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1404 7e9141cc-0065-0410-87d8-b60c137991c4 --- .../org/eclipse/jetty/http/HttpGenerator.java | 4 +++- .../eclipse/jetty/http/HttpGeneratorTest.java | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java index d21fdd4071b..d70e6896879 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java @@ -488,6 +488,7 @@ public class HttpGenerator extends AbstractGenerator HttpFields.Field transfer_encoding = null; boolean keep_alive = false; boolean close=false; + boolean content_type=false; StringBuilder connection = null; if (fields != null) @@ -516,6 +517,7 @@ public class HttpGenerator extends AbstractGenerator if (BufferUtil.isPrefix(MimeTypes.MULTIPART_BYTERANGES_BUFFER, field.getValueBuffer())) _contentLength = HttpTokens.SELF_DEFINING_CONTENT; // write the field to the header buffer + content_type=true; field.put(_header); break; @@ -659,7 +661,7 @@ public class HttpGenerator extends AbstractGenerator { // we have seen all the _content there is _contentLength = _contentWritten; - if (content_length == null) + if (content_length == null && (_method==null || _contentLength>0 || content_type )) { // known length but not actually set. _header.put(HttpHeaders.CONTENT_LENGTH_BUFFER); diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorTest.java index 17e13f7f024..fcf5195acd8 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorTest.java @@ -39,6 +39,28 @@ public class HttpGeneratorTest extends TestCase { super(arg0); } + + public void testRequest() + throws Exception + { + Buffer bb=new ByteArrayBuffer(8096); + Buffer sb=new ByteArrayBuffer(1500); + HttpFields fields = new HttpFields(); + ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096); + HttpGenerator hg = new HttpGenerator(new SimpleBuffers(sb,bb),endp); + + fields.add("Host","something"); + fields.add("User-Agent","test"); + + hg.setRequest("GET","/index.html"); + hg.setVersion(11); + hg.completeHeader(fields,true); + hg.complete(); + + assertTrue(endp.getOut().toString().indexOf("GET /index.html HTTP/1.1")==0); + assertTrue(endp.getOut().toString().indexOf("Content-Length")==-1); + + } public void testHTTP() throws Exception