Parse HTTP responses more generously
This commit is contained in:
parent
19cf923305
commit
fbccbd8ad3
|
@ -78,6 +78,18 @@
|
|||
'(#"Content-Type: text/plain")
|
||||
#"This is the data in the first chunk and this is the second one"]
|
||||
|
||||
["HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 62\r\n\r\nThis is the data in the first chunk and this is the second one"
|
||||
#"GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"
|
||||
#"HTTP/1.0 200 OK"
|
||||
'(#"Content-Type: text/plain" #"Content-Length: 62")
|
||||
#"This is the data in the first chunk and this is the second one"]
|
||||
|
||||
["HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\ncontent-length: 62\r\n\r\nThis is the data in the first chunk and this is the second one"
|
||||
#"GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"
|
||||
#"HTTP/1.0 200 OK"
|
||||
'(#"Content-Type: text/plain" #"content-length: 62")
|
||||
#"This is the data in the first chunk and this is the second one"]
|
||||
|
||||
["HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n20\r\nThis is the data in the first ch\r\n21\r\nand this is the second oneXXXXXXX\r\n0\r\n"
|
||||
|
||||
#"GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
(error 'http-client "Connection ended early"))
|
||||
bs)
|
||||
|
||||
(define (regexp-member rx l)
|
||||
(ormap (λ (h) (regexp-match rx h)) l))
|
||||
|
||||
;; Core
|
||||
|
||||
(struct http-conn (host to from abandon-p) #:mutable)
|
||||
|
@ -160,13 +163,13 @@
|
|||
(define headers (http-conn-headers! hc))
|
||||
(define close?
|
||||
(or iclose?
|
||||
(member #"Connection: close" headers)))
|
||||
(regexp-member #rx#"^(?i:Connection: +close)$" headers)))
|
||||
(define response-port
|
||||
(cond
|
||||
[(member #"Transfer-Encoding: chunked" headers)
|
||||
[(regexp-member #rx#"^(?i:Transfer-Encoding: +chunked)$" headers)
|
||||
(http-conn-response-port/chunked! hc #:close? #t)]
|
||||
[(ormap (λ (h)
|
||||
(match (regexp-match #rx#"^Content-Length: (.+)$" h)
|
||||
(match (regexp-match #rx#"^(?i:Content-Length:) +(.+)$" h)
|
||||
[#f #f]
|
||||
[(list _ cl-bs)
|
||||
(string->number
|
||||
|
|
Loading…
Reference in New Issue
Block a user