Paste: http proxy
Author: | Jon |
Mode: | factor |
Date: | Thu, 4 Feb 2016 16:43:03 |
Plain Text |
diff --git a/basis/http/client/client.factor b/basis/http/client/client.factor
index b1a9dae..7282295 100644
--- a/basis/http/client/client.factor
+++ b/basis/http/client/client.factor
@@ -16,7 +16,7 @@ ERROR: too-many-redirects ;
: write-request-line ( request -- request )
dup
[ method>> write bl ]
- [ url>> relative-url present write bl ]
+ [ [ url>> ] [ proxy>> ] bi [ relative-url ] unless present write bl ]
[ "HTTP/" write version>> write crlf ]
tri ;
@@ -112,7 +112,7 @@ SYMBOL: redirects
[ read-chunked ] [ each-block ] if ; inline
: <request-socket> ( -- stream )
- request get url>> url-addr ascii <client> drop
+ request get [ proxy>> ] [ url>> ] bi or url-addr ascii <client> drop
1 minutes over set-timeout ;
: (with-http-request) ( request quot: ( chunk -- ) -- response )
Author: | jon |
Mode: | factor |
Date: | Fri, 5 Feb 2016 15:28:31 |
Plain Text |
Cr�r��q�������G4ޓ�{��+ɹ�v�0�,�(�$�
^C
^C
���o(d<7�^9
ڲ��0�,�(�$�
d���2�:Gw�Ş
^C �كAU�sټ&�J]�5L x���
ERROR: too-many-redirects ;
@@ -16,7 +16,8 @@ ERROR: too-many-redirects ;
: write-request-line ( request -- request )
dup
[ method>> write bl ]
- [ url>> relative-url present write bl ]
+
+ [ 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
: <request-socket> ( -- stream )
- request get url>> url-addr ascii <client> drop
+ request get [ proxy>> ] [ url>> ] bi [ url-addr ] bi@
+remote-address set ascii <client> 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 [
<request-socket> [
[
+ [ 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 )
request new
"1.1" >>version
+ "http://localhost:3129" >url >>proxy
<url>
H{ } clone >>query
>>url
New Annotation