From a9f23a219895d4452894894f35481709b9e20d01 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 23 Apr 2026 21:50:46 +0300 Subject: [PATCH] net.http: fix `net.http.Request.proxy` is public but cannot be interpolated because `HttpProxy` is private and has no explicit `str()` (fixes #26938) --- .gitignore | 1 + vlib/net/http/http_proxy.v | 8 ++++++++ .../net_http_request_proxy_interpolation_test.v | 14 ++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 vlib/v/tests/net_http_request_proxy_interpolation_test.v diff --git a/.gitignore b/.gitignore index 7a7b4addb..ca0156cfa 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ !vlib/v/gen/c/testdata/nested_unary_minus_regression.vv !vlib/v/gen/c/testdata/nested_unary_minus_regression.out !vlib/v/tests/interfaces/interface_pointer_method_value_issue_22237_test.v +!vlib/v/tests/net_http_request_proxy_interpolation_test.v !vlib/v/checker/tests/modules/c_type_cast_imported_from_module/** !vlib/v/checker/tests/modules/c_type_cast_imported_from_module.out diff --git a/vlib/net/http/http_proxy.v b/vlib/net/http/http_proxy.v index 8a6733555..a92cd8593 100644 --- a/vlib/net/http/http_proxy.v +++ b/vlib/net/http/http_proxy.v @@ -75,6 +75,14 @@ pub fn new_http_proxy(raw_url string) !&HttpProxy { } } +// str returns the configured proxy URL for logging and debugging. +pub fn (pr &HttpProxy) str() string { + if isnil(pr) { + return 'nil' + } + return pr.url +} + // host format - ip:port fn (pr &HttpProxy) build_proxy_headers(host string) string { mut uheaders := []string{} diff --git a/vlib/v/tests/net_http_request_proxy_interpolation_test.v b/vlib/v/tests/net_http_request_proxy_interpolation_test.v new file mode 100644 index 000000000..38eeafeb7 --- /dev/null +++ b/vlib/v/tests/net_http_request_proxy_interpolation_test.v @@ -0,0 +1,14 @@ +import net.http + +fn test_request_proxy_can_be_interpolated_outside_net_http() { + req := http.Request{} + assert '${req.proxy}' == '&nil' +} + +fn test_http_proxy_can_be_interpolated_outside_net_http() ! { + proxy := http.new_http_proxy('http://user:pass@localhost:8888')! + req := http.Request{ + proxy: proxy + } + assert '${req.proxy}' == '&http://user:pass@localhost:8888' +} -- 2.39.5