Skip to content

Commit

Permalink
Fixed the detection of keep-alive connection, using close mode as def…
Browse files Browse the repository at this point in the history
…ault.
  • Loading branch information
nmihajlovski committed Feb 28, 2016
1 parent ab021d7 commit 70f04f0
Show file tree
Hide file tree
Showing 135 changed files with 145 additions and 140 deletions.
17 changes: 11 additions & 6 deletions rapidoid-http-fast/src/main/java/org/rapidoid/http/HttpParser.java
Expand Up @@ -97,10 +97,10 @@ public void parse(Buf buf, BoolWrap isGet, BoolWrap isKeepAlive, Range body, Ran
buf.scanLn(protocol);

IntWrap result = helper.integers[0];
buf.scanLnLn(headers.reset(), result, (byte) 's', (byte) 'e');
buf.scanLnLn(headers.reset(), result, (byte) 'v', (byte) 'e');

int possibleClosePos = result.value;
isKeepAlive.value = possibleClosePos < 0 ? false : isKeepAlive(bytes, headers, helper);
int possibleKeepAliveHeaderPos = result.value;
isKeepAlive.value = possibleKeepAliveHeaderPos >= 0 && isKeepAlive(bytes, headers, helper, possibleKeepAliveHeaderPos);

BytesUtil.split(bytes, uri, ASTERISK, path, query, false);

Expand All @@ -110,13 +110,18 @@ public void parse(Buf buf, BoolWrap isGet, BoolWrap isKeepAlive, Range body, Ran
}
}

private boolean isKeepAlive(Bytes bytes, Ranges headers, RapidoidHelper helper) {
private boolean isKeepAlive(Bytes bytes, Ranges headers, RapidoidHelper helper, int possibleKeepAliveHeaderPos) {
Range maybeConnHdr = headers.get(possibleKeepAliveHeaderPos);

if (BytesUtil.startsWith(bytes, maybeConnHdr, CONNECTION, true)) {
return true;
}

Range connHdr = headers.getByPrefix(bytes, CONNECTION, false);
return connHdr != null ? getKeepAliveValue(bytes, connHdr, helper) : true;
return connHdr == null || getKeepAliveValue(bytes, connHdr, helper);
}

private boolean getKeepAliveValue(Bytes bytes, Range connHdr, RapidoidHelper helper) {

assert bytes != null;
assert connHdr != null;

Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 500 Internal Server Error
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 500 Internal Server Error
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 500 Internal Server Error
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/plain; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/octet-stream
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/x-font
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 500 Internal Server Error
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 500 Internal Server Error
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 500 Internal Server Error
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 500 Internal Server Error
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 301 Moved Permanently
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 404 Not Found
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 500 Internal Server Error
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/octet-stream
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/msword
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 303 See Other
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 302 Found
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: text/html; charset=utf-8
Expand Down
@@ -1,5 +1,5 @@
HTTP/1.1 200 OK
Connection: close
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Expand Down

0 comments on commit 70f04f0

Please sign in to comment.