http.client: fix 307 redirect behavior (reported by Chris Double)
parent
e12f0f2280
commit
63cf5b04e1
|
@ -6,7 +6,7 @@ math.order hashtables byte-arrays destructors
|
|||
io io.sockets io.streams.string io.files io.timeouts
|
||||
io.pathnames io.encodings io.encodings.string io.encodings.ascii
|
||||
io.encodings.utf8 io.encodings.8-bit io.encodings.binary io.crlf
|
||||
io.streams.duplex fry ascii urls urls.encoding present
|
||||
io.streams.duplex fry ascii urls urls.encoding present locals
|
||||
http http.parsers http.client.post-data ;
|
||||
IN: http.client
|
||||
|
||||
|
@ -77,12 +77,13 @@ SYMBOL: redirects
|
|||
: redirect? ( response -- ? )
|
||||
code>> 300 399 between? ;
|
||||
|
||||
: do-redirect ( quot: ( chunk -- ) response -- response )
|
||||
:: do-redirect ( quot: ( chunk -- ) response -- response )
|
||||
redirects inc
|
||||
redirects get max-redirects < [
|
||||
request get clone
|
||||
swap "location" header redirect-url
|
||||
"GET" >>method swap (with-http-request)
|
||||
response "location" header redirect-url
|
||||
response code>> 307 = [ "GET" >>method ] unless
|
||||
quot (with-http-request)
|
||||
] [ too-many-redirects ] if ; inline recursive
|
||||
|
||||
: read-chunk-size ( -- n )
|
||||
|
|
|
@ -372,4 +372,24 @@ SYMBOL: a
|
|||
"vocab:http/test/foo.html" ascii file-contents =
|
||||
] unit-test
|
||||
|
||||
[ ] [ "http://localhost/quit" add-port http-get 2drop ] unit-test
|
||||
|
||||
! Check behavior of 307 redirect (reported by Chris Double)
|
||||
[ ] [
|
||||
<dispatcher>
|
||||
add-quit-action
|
||||
<action>
|
||||
[ "b" <temporary-redirect> ] >>submit
|
||||
"a" add-responder
|
||||
<action>
|
||||
[
|
||||
request get post-data>> data>> "data" =
|
||||
[ "OK" "text/plain" <content> ] [ "OOPS" throw ] if
|
||||
] >>submit
|
||||
"b" add-responder
|
||||
test-httpd
|
||||
] unit-test
|
||||
|
||||
[ "OK" ] [ "data" "http://localhost/a" add-port http-post nip ] unit-test
|
||||
|
||||
[ ] [ "http://localhost/quit" add-port http-get 2drop ] unit-test
|
Loading…
Reference in New Issue