! https tunneling setup for curl, wget, factor ! ! jon@zog:~/factor$ nc -l 3129 ! CONNECT www.google.fr:443 HTTP/1.1 ! Host: www.google.fr:443 ! User-Agent: curl/7.35.0 ! Proxy-Connection: Keep-Alive ! ! HTTP/1.1 200 Connection established ! ! "Cr�r��q�������G4ޓ�{��+ɹ�v�0�,�(�$� ! �kj98���2�.�*�&��=5�� ! www.google.fr ��g@32��ED�1�-�)�%��d����O�� ! ��]�^N%�a7 ��S��� T���o(d<7�^9 ! U ! [m6�D :ڲ��0�,�(�$� ! �kj98���2�.�*�&��=5�� ! �/�+�'�#�� ��g@32��ED�1�-�)�%��> write bl ] - [ url>> relative-url present write bl ] + ! present adds an extra "//" when the protocol is f, remove it + [ url>> clone f >>protocol present 2 tail write bl ] [ "HTTP/" write version>> write crlf ] tri ; @@ -112,14 +113,23 @@ SYMBOL: redirects [ read-chunked ] [ each-block ] if ; inline : ( -- stream ) - request get url>> url-addr ascii drop + request get [ proxy>> ] [ url>> ] bi [ url-addr ] bi@ +remote-address set ascii local-address set 1 minutes over set-timeout ; +: ?https-tunnel ( -- ) + request get clone "connect" >>method write-request + read-response drop send-secure-handshake ; + : (with-http-request) ( request quot: ( chunk -- ) -- response ) swap request [ [ [ + [ in>> ] [ out>> ] bi + [ ?https-tunnel ] with-streams* + ] + [ out>> [ request get write-request ] with-output-stream* @@ -133,7 +143,7 @@ SYMBOL: redirects 2tri f ] if ] with-input-stream* - ] bi + ] tri ] with-disposal [ do-redirect ] [ nip ] if ] with-variable ; inline recursive diff --git a/basis/http/http.factor b/basis/http/http.factor index 9e1f637..e053215 100644 --- a/basis/http/http.factor +++ b/basis/http/http.factor @@ -134,6 +134,7 @@ TUPLE: cookie name value version comment path domain expires max-age http-only s TUPLE: request method url +proxy version header post-data @@ -149,6 +150,7 @@ redirects ; : ( -- request ) request new "1.1" >>version + "http://localhost:3129" >url >>proxy H{ } clone >>query >>url