improved error checking when the response is badly malformed

svn: r11925
This commit is contained in:
Robby Findler 2008-10-02 19:49:33 +00:00
parent e99645136b
commit a7217aed0e

View File

@ -628,7 +628,7 @@ subdirectory.
(min-hi . ,(get pkg-spec-minor-hi))
(path . ,(get pkg-spec-path)))))
;; get-http-response-code : header[from net/head] -> string
;; get-http-response-code : header[from net/head] -> string or #f
;; gets the HTTP response code in the given header
(define (get-http-response-code header)
(let ([parsed (regexp-match #rx"^HTTP/[^ ]* ([^ ]*)" header)])
@ -656,7 +656,8 @@ subdirectory.
[ip (get-impure-port target)]
[head (purify-port ip)]
[response-code/str (get-http-response-code head)]
[response-code (string->number response-code/str)])
[response-code (and response-code/str
(string->number response-code/str))])
(define (abort msg)
(close-input-port ip)