Compare commits

...

2 commits

Author SHA1 Message Date
Delyan Angelov
21c46f4ae5
time: move the nanosecond comparison before the rest in the Time == Time implementation
Some checks are pending
Tools CI / tools-linux (clang) (push) Waiting to run
Graphics CI / gg-regressions (push) Waiting to run
vlib modules CI / build-module-docs (push) Waiting to run
Shy and PV CI / v-compiles-puzzle-vibes (push) Waiting to run
sdl CI / v-compiles-sdl-examples (push) Waiting to run
Time CI / time-linux (push) Waiting to run
Time CI / time-macos (push) Waiting to run
Time CI / time-windows (push) Waiting to run
toml CI / toml-module-pass-external-test-suites (push) Waiting to run
Tools CI / tools-linux (gcc) (push) Waiting to run
Tools CI / tools-linux (tcc) (push) Waiting to run
Tools CI / tools-macos (clang) (push) Waiting to run
Tools CI / tools-windows (gcc) (push) Waiting to run
Tools CI / tools-windows (msvc) (push) Waiting to run
Tools CI / tools-windows (tcc) (push) Waiting to run
Tools CI / tools-docker-ubuntu-musl (push) Waiting to run
vab CI / vab-compiles-v-examples (push) Waiting to run
vab CI / v-compiles-os-android (push) Waiting to run
2025-09-05 19:28:29 +03:00
kfont
083d3dba38
net.http: Use a full url when using a proxy, instead of only the path (#25228) 2025-09-05 19:24:59 +03:00
3 changed files with 33 additions and 3 deletions

View file

@ -87,7 +87,9 @@ fn (pr &HttpProxy) build_proxy_headers(host string) string {
fn (pr &HttpProxy) http_do(host urllib.URL, method Method, path string, req &Request) !Response {
host_name, port := net.split_address(host.hostname())!
s := req.build_request_headers(req.method, host_name, port, path)
port_part := if port == 80 || port == 0 { '' } else { ':${port}' }
s := req.build_request_headers(req.method, host_name, port, '${host.scheme}://${host_name}${port_part}${path}')
if host.scheme == 'https' {
mut client := pr.ssl_dial('${host.host}:443')!

View file

@ -1,6 +1,8 @@
module http
import encoding.base64
import net.urllib
import os
const sample_proxy_url = 'https://localhost'
const sample_auth_proxy_url = 'http://user:pass@localhost:8888'
@ -46,3 +48,29 @@ fn test_proxy_headers_authenticated() ? {
assert headers == 'CONNECT 127.0.0.1:1337 HTTP/1.1\r\n' + 'Host: 127.0.0.1\r\n' +
'Proxy-Connection: Keep-Alive\r\nProxy-Authorization: Basic ${auth_token}\r\n\r\n'
}
fn test_http_proxy_do() {
env := os.environ()
mut env_proxy := ''
for envvar in ['http_proxy', 'HTTP_PROXY', 'https_proxy', 'HTTPS_PROXY'] {
prox_val := env[envvar] or { continue }
if prox_val != '' {
env_proxy = env[envvar]
}
}
if env_proxy != '' {
println('Has usable proxy env vars')
proxy := new_http_proxy(env_proxy)!
mut header := new_header(key: .user_agent, value: 'vlib')
header.add_custom('X-Vlang-Test', 'proxied')!
res := proxy.http_do(urllib.parse('http://httpbin.org/headers')!, Method.get,
'/headers', &Request{ proxy: proxy, header: header })!
println(res.status_code)
println('he4aders ${res.header}')
assert res.status_code == 200
// assert res.header.data['X-Vlang-Test'] == 'proxied'
} else {
println('Proxy env vars (HTTP_PROXY or HTTPS_PROXY) not set. Skipping test.')
}
}

View file

@ -3,8 +3,8 @@ module time
// operator `==` returns true if provided time is equal to time
@[inline]
pub fn (t1 Time) == (t2 Time) bool {
return t1.is_local == t2.is_local && t1.local_unix() == t2.local_unix()
&& t1.nanosecond == t2.nanosecond
return t1.nanosecond == t2.nanosecond && t1.is_local == t2.is_local
&& t1.local_unix() == t2.local_unix()
}
// operator `<` returns true if provided time is less than time