diff --git a/pkgs/net-pkgs/net-test/tests/net/http-client.rkt b/pkgs/net-pkgs/net-test/tests/net/http-client.rkt index 3c5b07bb8e..6bada90654 100644 --- a/pkgs/net-pkgs/net-test/tests/net/http-client.rkt +++ b/pkgs/net-pkgs/net-test/tests/net/http-client.rkt @@ -155,4 +155,13 @@ #"GET / HTTP/1.1\r\nHost: localhost:REDACTED\r\nAccept-Encoding: gzip\r\n\r\n" #"HTTP/1.1 200 OK" '(#"Content-Type: text/plain" #"Transfer-Encoding: chunked" #"Another-Header: ta-daa") - #"This is the data in the first chand this is the second oneXXXXXXX"])) + #"This is the data in the first chand this is the second oneXXXXXXX"] + + ["HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\nAnother-Header: ta-daa\r\n\r\nbb \r\n\n\t\t\t\t\t \n\t\t\t\t\t ABCNANOTECH Co., LTD.\n\t\t\t\t\t \n\t\t\t\t\t \n\t\t\t\t\t \n\t\t\t\t\t \r\n0\r\n\r\n" + #"GET / HTTP/1.1\r\nHost: localhost:REDACTED\r\nAccept-Encoding: gzip\r\n\r\n" + #"HTTP/1.1 200 OK" + '(#"Content-Type: text/plain" #"Transfer-Encoding: chunked" #"Another-Header: ta-daa") + #"\n\t\t\t\t\t \n\t\t\t\t\t ABCNANOTECH Co., LTD.\n\t\t\t\t\t \n\t\t\t\t\t \n\t\t\t\t\t \n\t\t\t\t\t "])) + + + diff --git a/racket/collects/net/http-client.rkt b/racket/collects/net/http-client.rkt index 94dfb15031..2b3b247366 100644 --- a/racket/collects/net/http-client.rkt +++ b/racket/collects/net/http-client.rkt @@ -2,6 +2,7 @@ (require racket/contract/base racket/match racket/list + racket/string racket/port (rename-in racket/tcp [tcp-connect plain-tcp-connect] @@ -147,10 +148,12 @@ (define (http-pipe-chunk ip op) (define crlf-bytes (make-bytes 2)) (let loop ([last-bytes #f]) - (define size-str (read-line ip 'return-linefeed)) + (define size-str (string-trim (read-line ip 'return-linefeed))) (define chunk-size (string->number size-str 16)) (unless chunk-size - (error 'http-conn-response/chunked "Could not parse ~S as hexadecimal number" size-str)) + (error 'http-conn-response/chunked + "Could not parse ~S as hexadecimal number" + size-str)) (define use-last-bytes? (and last-bytes (<= chunk-size (bytes-length last-bytes)))) (if (zero? chunk-size)