Fix bugs in cookiejar and transfer-encoding

This commit is contained in:
xenia 2020-04-11 01:46:30 -04:00
parent e3fefc7af4
commit 66ca83ded6
2 changed files with 11 additions and 4 deletions

View File

@ -3,8 +3,8 @@
(require xml) (require xml)
(provide debug-mode? printf-debug print-progress print-complete (provide debug-mode? printf-debug print-progress print-complete
current-cookie-jar update-cookie-jar! cookie-jar->header current-cookie-jar update-cookie-jar! cookie-jar->header cookie-jar-ref
find-flags find-hrefs) string->xexpr find-flags find-hrefs)
;; scheme is bad and it should feel bad ;; scheme is bad and it should feel bad
(define member? member) (define member? member)
@ -45,6 +45,13 @@
;; Parameter for current cookie jar ;; Parameter for current cookie jar
(define current-cookie-jar (make-parameter (make-cookie-jar))) (define current-cookie-jar (make-parameter (make-cookie-jar)))
;; CookieJar -> String
;; Gets a value from a cookie jar
(define (cookie-jar-ref jar key)
(call-with-semaphore
(cj-sema jar)
(lambda () (hash-ref (cj-jar jar) key))))
;; CookieJar [List-of (cons Symbol String)] -> ;; CookieJar [List-of (cons Symbol String)] ->
;; For a response with the given headers, finds any set-cookie headers and updates the jar ;; For a response with the given headers, finds any set-cookie headers and updates the jar
(define (update-cookie-jar! jar hdrs) (define (update-cookie-jar! jar hdrs)
@ -66,7 +73,7 @@
;; CookieJar -> (cons Symbol String) ;; CookieJar -> (cons Symbol String)
;; Converts this cookie jar into a cookie header for requests ;; Converts this cookie jar into a cookie header for requests
(define (cookie-jar->header jar) (define (cookie-jar->header jar)
(call-with-semaphore (cj-sema jar) (curry unbox (cj-cache jar)))) (call-with-semaphore (cj-sema jar) (lambda () (unbox (cj-cache jar)))))
;; HTML (XML) handling ;; HTML (XML) handling
;; String -> xexpr ;; String -> xexpr

View File

@ -236,7 +236,7 @@
;; input-port? -> [streamof bytes?] ;; input-port? -> [streamof bytes?]
(define (read-chunked-stream port) (define (read-chunked-stream port)
(define len (string->number (read-crlf-line port))) (define len (string->number (read-crlf-line port) 16))
(unless (integer? len) (unless (integer? len)
(raise-read-http-error "read-chunked-stream: invalid chunked encoding detected")) (raise-read-http-error "read-chunked-stream: invalid chunked encoding detected"))
(define data (read-bytes len port)) (define data (read-bytes len port))