Skip to content

Commit

Permalink
http: keep F_LENIENT between messages
Browse files Browse the repository at this point in the history
`F_LENIENT` flag should not be reset along with the other flags when
starting parsing a new message. This setting should remain on for the
lifetime of the parser or until `llhttp_set_lenient(..., 0)`.

PR-URL: #34
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
  • Loading branch information
indutny committed Nov 21, 2019
1 parent cdcbd2c commit 5f29a33
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/native/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ int llhttp__after_message_complete(llhttp_t* parser, const char* p,
int should_keep_alive;

should_keep_alive = llhttp_should_keep_alive(parser);
parser->flags = 0;
parser->finish = HTTP_FINISH_SAFE;

/* Keep `F_LENIENT` flag between messages, but reset every other flag */
parser->flags &= F_LENIENT;

/* NOTE: this is ignored in loose parsing mode */
return should_keep_alive;
}
Expand Down
29 changes: 29 additions & 0 deletions test/request/lenient.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,35 @@ off=33 headers complete method=1 v=1/1 flags=100 content_length=0
off=33 message complete
```

## Second request header value with lenient

<!-- meta={"type": "request-lenient"} -->
```http
GET /url HTTP/1.1
Header1: Okay
GET /url HTTP/1.1
Header1: \f
```

```log
off=0 message begin
off=4 len=4 span[url]="/url"
off=19 len=7 span[header_field]="Header1"
off=28 len=4 span[header_value]="Okay"
off=36 headers complete method=1 v=1/1 flags=100 content_length=0
off=36 message complete
off=38 message begin
off=42 len=4 span[url]="/url"
off=57 len=7 span[header_field]="Header1"
off=66 len=1 span[header_value]="\f"
off=71 headers complete method=1 v=1/1 flags=100 content_length=0
off=71 message complete
```

## Header value without lenient

<!-- meta={"type": "request"} -->
Expand Down

0 comments on commit 5f29a33

Please sign in to comment.