Skip to content

Commit

Permalink
get-twice should handle 301 or 302 redirects.
Browse files Browse the repository at this point in the history
Specifically this fixes the issue uncovered when Yahoo started
redirecting from http://www.yahoo.com to https://www.yahoo.com.
  • Loading branch information
Greg Hendershott committed Nov 30, 2014
1 parent 4ed40ee commit d439870
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions http/request.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
file/gunzip
racket/date
"head.rkt"
"util.rkt"
)
"util.rkt")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Expand Down Expand Up @@ -990,26 +989,27 @@
(define-values (in out) (connect-uri uri))
(define-values (path rh) (uri&headers->path&header uri heads))
(define/contract (get)
(-> (or/c #f 'ok/open 'ok/close))
(-> (or/c #f 'ok/open 'ok/close 'ok/redirect))
(start-request in out "1.1" "get" path rh)
(define h (purify-port/log-debug in))
(define code (extract-http-code h))
(cond [(= code 999) #f]
[else (define e (read-entity/bytes in h))
(log-http-debug
(format "<- ~a bytes entity transfer and content decoded"
(bytes-length e)))
(cond [(close-connection? h)
(unpool in out)
'ok/close]
[else 'ok/open])]))
(begin0 (match (get)
['ok/open
(not (not (get)))] ;try again on same connection
['ok/close
(log-http-debug "can't try again, due to Connection: close")
#t]
[_ #f])
(case code
[(999) #f]
[(301 302) 'ok/redirect]
[else (define e (read-entity/bytes in h))
(log-http-debug
(format "<- ~a bytes entity transfer and content decoded"
(bytes-length e)))
(cond [(close-connection? h)
(unpool in out)
'ok/close]
[else 'ok/open])]))
(begin0
(match (get)
['ok/open (not (not (get)))] ;try again on same connection
['ok/close (log-http-debug "can't try again, due to 'Connection: close'") #t]
['ok/redirect (log-http-debug "can't try again, due to redirect") #t]
[_ #f])
(disconnect in out)))

(define xs-uri-to-test
Expand Down

0 comments on commit d439870

Please sign in to comment.