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
This commit is contained in:
Greg Wilkins 2010-03-23 20:24:11 +00:00
parent da9f167b31
commit f3e2b0248d
2 changed files with 25 additions and 1 deletions

View File

@ -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);

View File

@ -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