Skip to content

Commit c67a99d

Browse files
committed
porting changes in http_message_needs_eof logic, applying changes in tests.dumped
1 parent 6a428af commit c67a99d

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/impl/http_parser/lolevel/HTTPParser.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ public int execute(ParserSettings settings, ByteBuffer data) {
273273
// else there is no way of knowing the message is complete.
274274
int len = (data.limit() - data.position());
275275
if (0 == len) {
276-
// if (State.body_identity_eof == state) {
277-
// settings.call_on_message_complete(this);
278-
// }
276+
// if (State.body_identity_eof == state) {
277+
// settings.call_on_message_complete(this);
278+
// }
279279
switch (state) {
280280
case body_identity_eof:
281281
settings.call_on_message_complete(this);
@@ -1268,30 +1268,30 @@ public int execute(ParserSettings settings, ByteBuffer data) {
12681268

12691269
// Exit, the rest of the connect is in a different protocol.
12701270
if (upgrade) {
1271-
settings.call_on_message_complete(this);
12721271
state = new_message();
1272+
settings.call_on_message_complete(this);
12731273
return data.position()-this.p_start;
12741274
}
12751275

12761276
if (0 != (flags & F_SKIPBODY)) {
1277-
settings.call_on_message_complete(this);
12781277
state = new_message();
1278+
settings.call_on_message_complete(this);
12791279
} else if (0 != (flags & F_CHUNKED)) {
12801280
/* chunked encoding - ignore Content-Length header */
12811281
state = State.chunk_size_start;
12821282
} else {
12831283
if (content_length == 0) {
12841284
/* Content-Length header given but zero: Content-Length: 0\r\n */
1285-
settings.call_on_message_complete(this);
12861285
state = new_message();
1287-
} else if (content_length > 0) {
1286+
settings.call_on_message_complete(this);
1287+
} else if (content_length != -1) {
12881288
/* Content-Length header given and non-zero */
12891289
state = State.body_identity;
12901290
} else {
1291-
if (type == ParserType.HTTP_REQUEST || http_message_needs_eof()) {
1291+
if (type == ParserType.HTTP_REQUEST || !http_message_needs_eof()) {
12921292
/* Assume content-length 0 - read the next */
1293-
settings.call_on_message_complete(this);
12941293
state = new_message();
1294+
settings.call_on_message_complete(this);
12951295
} else {
12961296
/* Read body until EOF */
12971297
state = State.body_identity_eof;
@@ -1327,7 +1327,7 @@ public int execute(ParserSettings settings, ByteBuffer data) {
13271327
case body_identity_eof:
13281328
to_read = pe - p; // TODO change to use buffer ?
13291329
if (to_read > 0) {
1330-
settings.call_on_body(this, data, p, to_read);
1330+
settings.call_on_body(this, data, p, to_read);
13311331
data.position(p+to_read);
13321332
}
13331333
break;
@@ -1506,10 +1506,10 @@ public boolean http_message_needs_eof() {
15061506
if ((status_code / 100 == 1) || /* 1xx e.g. Continue */
15071507
(status_code == 204) || /* No Content */
15081508
(status_code == 304) || /* Not Modified */
1509-
(flags & F_SKIPBODY) == 0) { /* response to a HEAD request */
1509+
(flags & F_SKIPBODY) != 0) { /* response to a HEAD request */
15101510
return false;
15111511
}
1512-
if ((flags & F_CHUNKED) == 0 || content_length != 0) {
1512+
if ((flags & F_CHUNKED) != 0 || content_length != -1) {
15131513
return false;
15141514
}
15151515

@@ -1537,6 +1537,7 @@ public boolean http_should_keep_alive() {
15371537
return !http_message_needs_eof();
15381538
}
15391539

1540+
15401541
//TODO Skip http_parser_parse_url & http_parser_pause for now
15411542

15421543
boolean isDigit(byte b) {

tests.dumped

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ fragment :
493493
query_string:
494494
body :""
495495
body_size :0
496-
should_keep_alive :1
496+
should_keep_alive :0
497497
upgrade :0
498498
http_major :1
499499
http_minor :1
@@ -509,7 +509,7 @@ fragment :
509509
query_string:
510510
body :""
511511
body_size :0
512-
should_keep_alive :1
512+
should_keep_alive :0
513513
upgrade :0
514514
http_major :1
515515
http_minor :1

0 commit comments

Comments
 (0)