From de8226d3d2a6485a46b68dfa4d835403052b13c4 Mon Sep 17 00:00:00 2001 From: Laurent Cheylus Date: Tue, 3 Feb 2026 20:58:01 +0100 Subject: [PATCH] net.http: add tests to check default/custom User-Agent header (#26514) --- vlib/net/http/http_test.v | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/vlib/net/http/http_test.v b/vlib/net/http/http_test.v index c7478d843..6f451745d 100644 --- a/vlib/net/http/http_test.v +++ b/vlib/net/http/http_test.v @@ -77,3 +77,26 @@ fn test_relative_redirects() { assert res.body != '' assert res.body.contains('"abc": "xyz"') } + +fn test_default_user_agent() { + $if !network ? { + return + } + res := http.get('https://httpbin.org/user-agent') or { panic(err) } + assert res.status() == .ok + assert res.body != '' + assert res.body.contains('"user-agent": "v.http"') +} + +fn test_custom_user_agent() { + $if !network ? { + return + } + ua := 'V http test for UA' + mut req := http.new_request(.get, 'https://httpbin.org/user-agent', '') + req.user_agent = ua + res := req.do() or { panic(err) } + assert res.status() == .ok + assert res.body != '' + assert res.body.contains('"user-agent": "${ua}"') +} -- 2.39.5