Skip to content

Commit

Permalink
yegor256#306: Reviewer feedback fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
lautarobock committed Jun 12, 2015
1 parent 5abbe05 commit 8c98c86
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/takes/http/BkBasic.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ public void accept(final Socket socket) throws IOException {
final RqLive req = new RqLive(input);
boolean keep = false;
final Iterator<String> values = new RqHeaders.Base(req)
.header(CONNECTION).iterator();
.header(BkBasic.CONNECTION).iterator();
if (values.hasNext()) {
do {
keep = KEEP_ALIVE.equals(values.next());
keep = values.next().contains(BkBasic.KEEP_ALIVE);
} while (!keep && values.hasNext());
}
try {
Expand Down Expand Up @@ -127,7 +127,7 @@ private void print(
final Response res;
if (keep) {
res = new RsWithHeader(
this.take.act(req), CONNECTION, KEEP_ALIVE
this.take.act(req), BkBasic.CONNECTION, BkBasic.KEEP_ALIVE
);
} else {
res = this.take.act(req);
Expand Down
33 changes: 14 additions & 19 deletions src/test/java/org/takes/http/BkBasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
*/
public final class BkBasicTest {

/**
* New line.
*/
private static final String CRLF = "\r\n";
/**
* Keep alive header value.
*/
Expand All @@ -66,7 +70,7 @@ public void handlesSocket() throws IOException {
final Socket socket = Mockito.mock(Socket.class);
Mockito.when(socket.getInputStream()).thenReturn(
new ByteArrayInputStream(
this.joiner().join(
Joiner.on(BkBasicTest.CRLF).join(
"GET / HTTP/1.1",
"Host:localhost",
"Content-Length: 2",
Expand All @@ -93,19 +97,19 @@ public void handlesSocket() throws IOException {
}

/**
* BkBasic supports HTTP persistent connections.
* BkBasic can handle HTTP persistent connections.
* @throws IOException If some problem inside
*/
@Test
public void persistentConnection() throws IOException {
public void handlesPersistentConnection() throws IOException {
final Socket socket = Mockito.mock(Socket.class);
final ByteArrayInputStream input = Mockito.spy(
new ByteArrayInputStream(
this.joiner().join(
Joiner.on(BkBasicTest.CRLF).join(
"GET /keep HTTP/1.1",
"Host:localhost2",
"Content-Length: 5",
KEEP_ALIVE,
"Connection: Keep-Alive2,Keep-Alive",
"",
"hello"
).getBytes()
Expand All @@ -118,20 +122,20 @@ public void persistentConnection() throws IOException {
Mockito.verify(input, Mockito.never()).close();
MatcherAssert.assertThat(
baos.toString(),
Matchers.containsString(KEEP_ALIVE)
Matchers.containsString(BkBasicTest.KEEP_ALIVE)
);
}

/**
* BkBasic not supports HTTP persistent connections.
* BkBasic can handle ephemeral (non-persistent) HTTP connections.
* @throws IOException If some problem inside
*/
@Test
public void notPersistentConnection() throws IOException {
public void handlesEphemeralConnection() throws IOException {
final Socket socket = Mockito.mock(Socket.class);
final ByteArrayInputStream input = Mockito.spy(
new ByteArrayInputStream(
this.joiner().join(
Joiner.on(BkBasicTest.CRLF).join(
"GET /close HTTP/1.1",
"Host:localhost3",
"Content-Length: 6",
Expand All @@ -147,7 +151,7 @@ public void notPersistentConnection() throws IOException {
Mockito.verify(input, Mockito.times(1)).close();
MatcherAssert.assertThat(
baos.toString(),
Matchers.not(Matchers.containsString(KEEP_ALIVE))
Matchers.not(Matchers.containsString(BkBasicTest.KEEP_ALIVE))
);
}
/**
Expand All @@ -173,13 +177,4 @@ public void exec(final URI home) throws IOException {
}
);
}

/**
* Create a joiner for a header.
* @return Joiner
*/
private Joiner joiner() {
return Joiner.on("\r\n");
}

}

0 comments on commit 8c98c86

Please sign in to comment.