From f36d47523b4e90495b5538cfce7f14c6ae5067bd Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+tobealive@users.noreply.github.com> Date: Thu, 20 Jul 2023 15:57:14 +0200 Subject: [PATCH] feat: allow to add proxy settings in `vibe.Request`s --- src/_instructions_common.v | 18 ++++++++++++++++++ src/_state_common.v | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/src/_instructions_common.v b/src/_instructions_common.v index 76fea42..577ddae 100644 --- a/src/_instructions_common.v +++ b/src/_instructions_common.v @@ -29,6 +29,24 @@ fn (req Request) set_common_opts(h &C.CURL, url string, resp &Response) { curl.easy_setopt(h, .url, url) curl.easy_setopt(h, .headerdata, resp) curl.easy_setopt(h, .headerfunction, write_resp_header) + req.set_proxy(h) +} + +fn (req Request) set_proxy(h &C.CURL) { + if req.proxy.address == '' { + return + } + curl.easy_setopt(h, .proxy, req.proxy.address.str) + if req.proxy.port != 0 { + curl.easy_setopt(h, .proxyport, req.proxy.port) + } + if req.proxy.user != '' { + mut userpwd := req.proxy.user + if req.proxy.password != '' { + userpwd += ':' + req.proxy.password.trim_space() + } + curl.easy_setopt(h, .proxyuserpwd, userpwd.str) + } } fn send_request(handle &C.CURL) ! { diff --git a/src/_state_common.v b/src/_state_common.v index 249bf37..30ae0b5 100644 --- a/src/_state_common.v +++ b/src/_state_common.v @@ -9,10 +9,18 @@ pub mut: custom_headers map[string]string cookie_jar string cookie_file string + proxy ProxySettings timeout time.Duration max_redirects u16 = 10 } +pub struct ProxySettings { + address string + port u16 + user string + password string +} + // TODO: pub enum SSLLevel { @none