diff --git a/collects/net/scribblings/url.scrbl b/collects/net/scribblings/url.scrbl index 4c7297efbf..26c9322858 100644 --- a/collects/net/scribblings/url.scrbl +++ b/collects/net/scribblings/url.scrbl @@ -316,14 +316,17 @@ empty string, or it will be a string matching the following regexp: @defproc[(get-pure-port/headers [url url?] [headers (listof string?) '()] - [#:redirections redirections exact-nonnegative-integer? 0]) + [#:redirections redirections exact-nonnegative-integer? 0] + [#:status? status? boolean? #f]) (values input-port? string?)]{ This function is an alternative to calling @racket[get-impure-port] and @racket[purify-port] when needing to follow redirections. That is, it does a GET request on @racket[url], follows up to @racket[redirections] redirections and returns a port containing - the data as well as the headers for the final connection. + the data as well as the headers for the final connection. If + @racket[status?] is true, then the status line is included in the + result string. } @defproc*[([(call/input-url [URL url?] diff --git a/collects/net/url.rkt b/collects/net/url.rkt index 333784185a..aa30803bad 100644 --- a/collects/net/url.rkt +++ b/collects/net/url.rkt @@ -216,7 +216,9 @@ (file://get-pure-port url)] [else (url-error "Scheme ~a unsupported" scheme)]))) -(define (get-pure-port/headers url [strings '()] #:redirections [redirections 0]) +(define (get-pure-port/headers url [strings '()] + #:redirections [redirections 0] + #:status? [status? #f]) (let redirection-loop ([redirections redirections] [url url]) (define ip (http://getpost-impure-port #t url #f strings)) @@ -261,7 +263,9 @@ (close-input-port ip))) (values in-pipe (apply string-append (map (λ (x) (string-append x "\r\n")) - (cons status (reverse headers)))))]))) + (if status? + (cons status (reverse headers)) + (reverse headers)))))]))) ;; get-pure-port : url [x list (str)] -> in-port (define (get-pure-port url [strings '()] #:redirections [redirections 0]) @@ -700,7 +704,7 @@ (put-impure-port (->* (url? bytes?) ((listof string?)) input-port?)) (display-pure-port (input-port? . -> . void?)) (purify-port (input-port? . -> . string?)) - (get-pure-port/headers (->* (url?) ((listof string?) #:redirections exact-nonnegative-integer?) + (get-pure-port/headers (->* (url?) ((listof string?) #:redirections exact-nonnegative-integer? #:status? boolean?) (values input-port? string?))) (netscape/string->url (string? . -> . url?)) (call/input-url (case-> (-> url?