426739 - Response with Connection: keep-alive truncated.
Fixed copy/paste error. Also removed unnecessary constant.
This commit is contained in:
parent
2db90757ed
commit
7ce6aee304
|
@ -825,7 +825,7 @@ public class HttpGenerator
|
|||
header.put(CONNECTION_KEEP_ALIVE);
|
||||
else
|
||||
{
|
||||
header.put(CONNECTION_KEEP_ALIVE,0,CONNECTION_CLOSE.length-2);
|
||||
header.put(CONNECTION_KEEP_ALIVE,0,CONNECTION_KEEP_ALIVE.length-2);
|
||||
header.put((byte)',');
|
||||
header.put(StringUtil.getBytes(connection.toString()));
|
||||
header.put(CRLF);
|
||||
|
@ -833,7 +833,7 @@ public class HttpGenerator
|
|||
}
|
||||
else if (connection!=null)
|
||||
{
|
||||
header.put(CONNECTION_);
|
||||
header.put(HttpHeader.CONNECTION.getBytesColonSpace());
|
||||
header.put(StringUtil.getBytes(connection.toString()));
|
||||
header.put(CRLF);
|
||||
}
|
||||
|
@ -872,7 +872,6 @@ public class HttpGenerator
|
|||
private static final byte[] CONTENT_LENGTH_0 = StringUtil.getBytes("Content-Length: 0\015\012");
|
||||
private static final byte[] CONNECTION_KEEP_ALIVE = StringUtil.getBytes("Connection: keep-alive\015\012");
|
||||
private static final byte[] CONNECTION_CLOSE = StringUtil.getBytes("Connection: close\015\012");
|
||||
private static final byte[] CONNECTION_ = StringUtil.getBytes("Connection: ");
|
||||
private static final byte[] HTTP_1_1_SPACE = StringUtil.getBytes(HttpVersion.HTTP_1_1+" ");
|
||||
private static final byte[] CRLF = StringUtil.getBytes("\015\012");
|
||||
private static final byte[] TRANSFER_ENCODING_CHUNKED = StringUtil.getBytes("Transfer-Encoding: chunked\015\012");
|
||||
|
|
|
@ -18,6 +18,15 @@
|
|||
|
||||
package org.eclipse.jetty.http;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.http.HttpGenerator.ResponseInfo;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.either;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
@ -28,14 +37,6 @@ import static org.junit.Assert.assertFalse;
|
|||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.http.HttpGenerator.ResponseInfo;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HttpGeneratorServerTest
|
||||
{
|
||||
private class Handler implements HttpParser.ResponseHandler<ByteBuffer>
|
||||
|
@ -365,8 +366,7 @@ public class HttpGeneratorServerTest
|
|||
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
|
||||
HttpGenerator.Result
|
||||
result = gen.generateResponse(null, null, null, null, true);
|
||||
HttpGenerator.Result result = gen.generateResponse(null, null, null, null, true);
|
||||
assertEquals(HttpGenerator.Result.NEED_INFO, result);
|
||||
assertEquals(HttpGenerator.State.START, gen.getState());
|
||||
|
||||
|
@ -399,8 +399,7 @@ public class HttpGeneratorServerTest
|
|||
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
|
||||
HttpGenerator.Result
|
||||
result = gen.generateResponse(null, null, null, null, true);
|
||||
HttpGenerator.Result result = gen.generateResponse(null, null, null, null, true);
|
||||
assertEquals(HttpGenerator.Result.NEED_INFO, result);
|
||||
assertEquals(HttpGenerator.State.START, gen.getState());
|
||||
|
||||
|
@ -495,9 +494,7 @@ public class HttpGeneratorServerTest
|
|||
ByteBuffer content1 = BufferUtil.toBuffer("The quick brown fox jumped over the lazy dog. ");
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
|
||||
HttpGenerator.Result
|
||||
|
||||
result = gen.generateResponse(null, null, null, content0, false);
|
||||
HttpGenerator.Result result = gen.generateResponse(null, null, null, content0, false);
|
||||
assertEquals(HttpGenerator.Result.NEED_INFO, result);
|
||||
assertEquals(HttpGenerator.State.START, gen.getState());
|
||||
|
||||
|
@ -540,15 +537,12 @@ public class HttpGeneratorServerTest
|
|||
@Test
|
||||
public void test100ThenResponseWithContent() throws Exception
|
||||
{
|
||||
|
||||
ByteBuffer header = BufferUtil.allocate(4096);
|
||||
ByteBuffer content0 = BufferUtil.toBuffer("Hello World! ");
|
||||
ByteBuffer content1 = BufferUtil.toBuffer("The quick brown fox jumped over the lazy dog. ");
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
|
||||
HttpGenerator.Result
|
||||
|
||||
result = gen.generateResponse(HttpGenerator.CONTINUE_100_INFO, null, null, null, false);
|
||||
HttpGenerator.Result result = gen.generateResponse(HttpGenerator.CONTINUE_100_INFO, null, null, null, false);
|
||||
assertEquals(HttpGenerator.Result.NEED_HEADER, result);
|
||||
assertEquals(HttpGenerator.State.START, gen.getState());
|
||||
|
||||
|
@ -563,7 +557,6 @@ public class HttpGeneratorServerTest
|
|||
|
||||
assertThat(out, containsString("HTTP/1.1 100 Continue"));
|
||||
|
||||
|
||||
result = gen.generateResponse(null, null, null, content0, false);
|
||||
assertEquals(HttpGenerator.Result.NEED_INFO, result);
|
||||
assertEquals(HttpGenerator.State.START, gen.getState());
|
||||
|
@ -603,4 +596,22 @@ public class HttpGeneratorServerTest
|
|||
assertThat(out, containsString("Content-Length: 59"));
|
||||
assertThat(out, containsString("\r\n\r\nHello World! The quick brown fox jumped over the lazy dog. "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectionKeepAliveWithAdditionalCustomValue() throws Exception
|
||||
{
|
||||
HttpGenerator generator = new HttpGenerator();
|
||||
|
||||
HttpFields fields = new HttpFields();
|
||||
fields.put(HttpHeader.CONNECTION, HttpHeaderValue.KEEP_ALIVE);
|
||||
String customValue = "test";
|
||||
fields.add(HttpHeader.CONNECTION, customValue);
|
||||
ResponseInfo info = new ResponseInfo(HttpVersion.HTTP_1_0, fields, -1, 200, "OK", false);
|
||||
ByteBuffer header = BufferUtil.allocate(4096);
|
||||
HttpGenerator.Result result = generator.generateResponse(info, header, null, null, true);
|
||||
Assert.assertSame(HttpGenerator.Result.FLUSH, result);
|
||||
String headers = BufferUtil.toString(header);
|
||||
Assert.assertTrue(headers.contains(HttpHeaderValue.KEEP_ALIVE.asString()));
|
||||
Assert.assertTrue(headers.contains(customValue));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue