about summary refs log tree commit diff stats
path: root/src/io
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-04-30 17:13:29 +0200
committerbptato <nincsnevem662@gmail.com>2023-04-30 17:13:29 +0200
commitc235e638788b43ca752179341e429f4d7e090870 (patch)
treef1928dfc396edf9eb30dda80de1c873716c955d0 /src/io
parent2a4aeb3acb7c4877ee0d4b972bb204453eee67d5 (diff)
downloadchawan-c235e638788b43ca752179341e429f4d7e090870.tar.gz
Add initial proxy support
For now, API-only.
Diffstat (limited to 'src/io')
-rw-r--r--src/io/http.nim3
-rw-r--r--src/io/request.nim10
2 files changed, 10 insertions, 3 deletions
diff --git a/src/io/http.nim b/src/io/http.nim
index a6a1781d..bd880445 100644
--- a/src/io/http.nim
+++ b/src/io/http.nim
@@ -120,6 +120,9 @@ proc loadHttp*(curlm: CURLM, request: Request, ostream: Stream): HandleData =
   curl.setopt(CURLOPT_WRITEFUNCTION, curlWriteBody)
   curl.setopt(CURLOPT_HEADERDATA, handleData)
   curl.setopt(CURLOPT_HEADERFUNCTION, curlWriteHeader)
+  if request.proxy != nil:
+    let purl = request.proxy.serialize()
+    curl.setopt(CURLOPT_PROXY, purl)
   case request.httpmethod
   of HTTP_GET:
     curl.setopt(CURLOPT_HTTPGET, 1)
diff --git a/src/io/request.nim b/src/io/request.nim
index 8837a1f9..7c764449 100644
--- a/src/io/request.nim
+++ b/src/io/request.nim
@@ -44,6 +44,7 @@ type
     mode*: RequestMode
     destination*: RequestDestination
     credentialsMode*: CredentialsMode
+    proxy*: URL #TODO: this should definitely be a different API.
 
   Response* = ref object
     body*: Stream
@@ -151,7 +152,8 @@ func newRequest*(url: URL, httpmethod = HTTP_GET, headers = newHeaderList(),
                  body = none(string), multipart = none(MimeData),
                  mode = RequestMode.NO_CORS,
                  credentialsMode = CredentialsMode.SAME_ORIGIN,
-                 destination = RequestDestination.NO_DESTINATION): Request =
+                 destination = RequestDestination.NO_DESTINATION,
+                 proxy: URL = nil): Request =
   return Request(
     url: url,
     httpmethod: httpmethod,
@@ -160,11 +162,13 @@ func newRequest*(url: URL, httpmethod = HTTP_GET, headers = newHeaderList(),
     multipart: multipart,
     mode: mode,
     credentialsMode: credentialsMode,
-    destination: destination
+    destination: destination,
+    proxy: proxy
   )
 
 func newRequest*(url: URL, httpmethod = HTTP_GET, headers: seq[(string, string)] = @[],
-                 body = none(string), multipart = none(MimeData), mode = RequestMode.NO_CORS): Request {.jsctor.} =
+                 body = none(string), multipart = none(MimeData),
+                 mode = RequestMode.NO_CORS, proxy: URL = nil): Request {.jsctor.} =
   let hl = newHeaderList()
   for pair in headers:
     let (k, v) = pair