/*
* Equivalent to Http10.test_synchronous in sockjs-protocol-0.3.3.py.
*/
@Test
public void http10TestSynchronous() throws Exception {
final SockJsServiceFactory echoFactory = echoService();
final EmbeddedChannel ch = channelForService(echoFactory);
final FullHttpRequest request = httpGetRequest(echoFactory.config().prefix(), HTTP_1_0);
request.headers().set(CONNECTION, KEEP_ALIVE);
ch.writeInbound(request);
final FullHttpResponse response = ch.readOutbound();
assertThat(response.getStatus(), is(HttpResponseStatus.OK));
assertThat(response.getProtocolVersion(), is(HTTP_1_0));
assertThat(response.headers().get(TRANSFER_ENCODING), is(nullValue()));
if (response.headers().get(CONTENT_LENGTH) == null) {
assertThat(response.headers().get(CONNECTION), equalTo("close"));
assertThat(response.content().toString(UTF_8), equalTo("Welcome to SockJS!\n"));
assertThat(ch.isActive(), is(false));
} else {
assertThat(response.headers().get(CONTENT_LENGTH), is("19"));
assertThat(response.content().toString(UTF_8), equalTo("Welcome to SockJS!\n"));
final String connectionHeader = response.headers().get(CONNECTION);
if (connectionHeader.contains("close") || connectionHeader.isEmpty()) {
assertThat(ch.isActive(), is(false));
} else {
assertThat(connectionHeader, equalTo("keep-alive"));
ch.writeInbound(httpGetRequest(echoFactory.config().prefix(), HTTP_1_0));
final HttpResponse newResponse = ch.readOutbound();
assertThat(newResponse.getStatus(), is(HttpResponseStatus.OK));
}
}
}