Skip to content

Commit

Permalink
feat: allow to add proxy settings in vibe.Requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Jul 20, 2023
1 parent 9a49785 commit f36d475
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/_instructions_common.v
Original file line number Diff line number Diff line change
Expand Up @@ -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) ! {
Expand Down
8 changes: 8 additions & 0 deletions src/_state_common.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f36d475

Please sign in to comment.