Fixing missing '\r\n' on Connection: Upgrade
This commit is contained in:
parent
29249d5fab
commit
d0daf16d17
|
@ -634,6 +634,7 @@ public class HttpGenerator
|
||||||
{
|
{
|
||||||
// special case for websocket connection ordering
|
// special case for websocket connection ordering
|
||||||
header.put(HttpHeader.CONNECTION.getBytesColonSpace()).put(HttpHeader.UPGRADE.getBytes());
|
header.put(HttpHeader.CONNECTION.getBytesColonSpace()).put(HttpHeader.UPGRADE.getBytes());
|
||||||
|
header.put(CRLF);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.http;
|
package org.eclipse.jetty.http;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.either;
|
import static org.hamcrest.Matchers.either;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
@ -30,6 +31,7 @@ import org.eclipse.jetty.http.HttpGenerator.Action;
|
||||||
import org.eclipse.jetty.http.HttpGenerator.ResponseInfo;
|
import org.eclipse.jetty.http.HttpGenerator.ResponseInfo;
|
||||||
import org.eclipse.jetty.util.BufferUtil;
|
import org.eclipse.jetty.util.BufferUtil;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -392,6 +394,40 @@ public class HttpGeneratorServerTest
|
||||||
assertThat(head,containsString("Content-Length: 0"));
|
assertThat(head,containsString("Content-Length: 0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResponseUpgrade() throws Exception
|
||||||
|
{
|
||||||
|
ByteBuffer header=BufferUtil.allocate(8096);
|
||||||
|
|
||||||
|
HttpGenerator gen = new HttpGenerator();
|
||||||
|
|
||||||
|
HttpGenerator.Result
|
||||||
|
result=gen.generate(null,null,null,null,null,Action.COMPLETE);
|
||||||
|
assertEquals(HttpGenerator.State.COMMITTING_COMPLETING,gen.getState());
|
||||||
|
assertEquals(HttpGenerator.Result.NEED_INFO,result);
|
||||||
|
|
||||||
|
ResponseInfo info = new ResponseInfo(HttpVersion.HTTP_1_1,new HttpFields(),-1,101,null,false);
|
||||||
|
info.getHttpFields().add("Upgrade","WebSocket");
|
||||||
|
info.getHttpFields().add("Connection","Upgrade");
|
||||||
|
info.getHttpFields().add("Sec-WebSocket-Accept","123456789==");
|
||||||
|
|
||||||
|
result=gen.generate(info,header,null,null,null,null);
|
||||||
|
assertEquals(HttpGenerator.Result.FLUSH,result);
|
||||||
|
String head = BufferUtil.toString(header);
|
||||||
|
System.out.println(head);
|
||||||
|
BufferUtil.clear(header);
|
||||||
|
|
||||||
|
result=gen.generate(info,null,null,null,null,null);
|
||||||
|
assertEquals(HttpGenerator.Result.OK,result);
|
||||||
|
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||||
|
|
||||||
|
assertEquals(0,gen.getContentPrepared());
|
||||||
|
|
||||||
|
assertThat(head,startsWith("HTTP/1.1 101 Switching Protocols"));
|
||||||
|
assertThat(head,containsString("Upgrade: WebSocket\r\n"));
|
||||||
|
assertThat(head,containsString("Connection: Upgrade\r\n"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponseWithChunkedContent() throws Exception
|
public void testResponseWithChunkedContent() throws Exception
|
||||||
{
|
{
|
||||||
|
@ -497,6 +533,7 @@ public class HttpGeneratorServerTest
|
||||||
assertThat(head,containsString("Transfer-Encoding: chunked"));
|
assertThat(head,containsString("Transfer-Encoding: chunked"));
|
||||||
assertTrue(head.endsWith("\r\n\r\n10\r\n"));
|
assertTrue(head.endsWith("\r\n\r\n10\r\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponseWithKnownContent() throws Exception
|
public void testResponseWithKnownContent() throws Exception
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue