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 io.sockets io.streams.string io.files io.timeouts | ||||||
| io.pathnames io.encodings io.encodings.string io.encodings.ascii | io.pathnames io.encodings io.encodings.string io.encodings.ascii | ||||||
| io.encodings.utf8 io.encodings.8-bit io.encodings.binary io.crlf | 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 ; | http http.parsers http.client.post-data ; | ||||||
| IN: http.client | IN: http.client | ||||||
| 
 | 
 | ||||||
|  | @ -77,12 +77,13 @@ SYMBOL: redirects | ||||||
| : redirect? ( response -- ? ) | : redirect? ( response -- ? ) | ||||||
|     code>> 300 399 between? ; |     code>> 300 399 between? ; | ||||||
| 
 | 
 | ||||||
| : do-redirect ( quot: ( chunk -- ) response -- response ) | :: do-redirect ( quot: ( chunk -- ) response -- response ) | ||||||
|     redirects inc |     redirects inc | ||||||
|     redirects get max-redirects < [ |     redirects get max-redirects < [ | ||||||
|         request get clone |         request get clone | ||||||
|         swap "location" header redirect-url |         response "location" header redirect-url | ||||||
|         "GET" >>method swap (with-http-request) |         response code>> 307 = [ "GET" >>method ] unless | ||||||
|  |         quot (with-http-request) | ||||||
|     ] [ too-many-redirects ] if ; inline recursive |     ] [ too-many-redirects ] if ; inline recursive | ||||||
| 
 | 
 | ||||||
| : read-chunk-size ( -- n ) | : read-chunk-size ( -- n ) | ||||||
|  |  | ||||||
|  | @ -373,3 +373,23 @@ SYMBOL: a | ||||||
| ] unit-test | ] unit-test | ||||||
| 
 | 
 | ||||||
| [ ] [ "http://localhost/quit" add-port http-get 2drop ] 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