about summary refs log tree commit diff stats
path: root/adapter
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-12-13 14:02:02 +0100
committerbptato <nincsnevem662@gmail.com>2023-12-13 14:02:02 +0100
commit4818cb28debf4601213707f6c1b9b22348b51fbc (patch)
tree6120f6728417532c3309ee711f7645e81caa9687 /adapter
parentdf40fcdde896f636a05d1e3fe598feb2a816f2b9 (diff)
downloadchawan-4818cb28debf4601213707f6c1b9b22348b51fbc.tar.gz
http: use CURLU for URLs
Diffstat (limited to 'adapter')
-rw-r--r--adapter/protocol/curlwrap.nim3
-rw-r--r--adapter/protocol/http.nim22
2 files changed, 23 insertions, 2 deletions
diff --git a/adapter/protocol/curlwrap.nim b/adapter/protocol/curlwrap.nim
index 7aef4182..d5014b26 100644
--- a/adapter/protocol/curlwrap.nim
+++ b/adapter/protocol/curlwrap.nim
@@ -8,3 +8,6 @@ template setopt*(curl: CURL, opt: CURLoption, arg: string) =
 
 template getinfo*(curl: CURL, info: CURLINFO, arg: typed) =
   discard curl_easy_getinfo(curl, info, arg)
+
+template set*(url: CURLU, part: CURLUPart, content: string, flags: cuint) =
+  discard curl_url_set(url, part, cstring(content), flags)
diff --git a/adapter/protocol/http.nim b/adapter/protocol/http.nim
index 10b0c060..e59cac0a 100644
--- a/adapter/protocol/http.nim
+++ b/adapter/protocol/http.nim
@@ -77,8 +77,26 @@ proc curlPreRequest(clientp: pointer, conn_primary_ip, conn_local_ip: cstring,
 proc main() =
   let curl = curl_easy_init()
   doAssert curl != nil
-  let surl = getEnv("QUERY_STRING")
-  curl.setopt(CURLOPT_URL, surl)
+  let url = curl_url()
+  const flags = cuint(CURLU_PATH_AS_IS)
+  url.set(CURLUPART_SCHEME, getEnv("MAPPED_URI_SCHEME"), flags)
+  let username = getEnv("MAPPED_URI_USERNAME")
+  if username != "":
+    url.set(CURLUPART_USER, username, flags)
+  let password = getEnv("MAPPED_URI_PASSWORD")
+  if password != "":
+    url.set(CURLUPART_PASSWORD, password, flags)
+  url.set(CURLUPART_HOST, getEnv("MAPPED_URI_HOST"), flags)
+  let port = getEnv("MAPPED_URI_PORT")
+  if port != "":
+    url.set(CURLUPART_PORT, port, flags)
+  let path = getEnv("MAPPED_URI_PATH")
+  if path != "":
+    url.set(CURLUPART_PATH, path, flags)
+  let query = getEnv("MAPPED_URI_QUERY")
+  if query != "":
+    url.set(CURLUPART_QUERY, query, flags)
+  curl.setopt(CURLOPT_CURLU, url)
   let op = HttpHandle(curl: curl)
   curl.setopt(CURLOPT_WRITEFUNCTION, curlWriteBody)
   curl.setopt(CURLOPT_HEADERDATA, op)