Skip to content

Commit 34a0082

Browse files
committed
Fixed an issue with gocurl setting UA. Closes #34
1 parent 2b1c559 commit 34a0082

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ adheres to [Semantic Versioning][semver].
1111

1212
## [Unreleased]
1313

14+
### Fixed
15+
16+
* Cannot set User Agent via headers. ([#34][#34])
17+
18+
[#34]: https://github.com/ameshkov/gocurl/issues/34
19+
1420
[unreleased]: https://github.com/ameshkov/gocurl/compare/v1.4.5...HEAD
1521

1622
## [1.4.5] - 2025-03-17

README.md

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -264,47 +264,38 @@ Usage:
264264
Application Options:
265265
--url=<URL> URL the request will be made to. Can be specified without any flags.
266266
-X, --request=<method> HTTP method. GET by default.
267-
-d, --data=<data> Sends the specified data to the HTTP server using content type
268-
application/x-www-form-urlencoded.
267+
-d, --data=<data> Sends the specified data to the HTTP server using content type application/x-www-form-urlencoded.
269268
-H, --header= Extra header to include in the request. Can be specified multiple times.
270-
-x, --proxy=[protocol://username:password@]host[:port] Use the specified proxy. The proxy string can be specified with a
271-
protocol:// prefix.
272-
--connect-to=<HOST1:PORT1:HOST2:PORT2> For a request to the given HOST1:PORT1 pair, connect to HOST2:PORT2
273-
instead. Can be specified multiple times.
269+
-x, --proxy=[protocol://username:password@]host[:port] Use the specified proxy. The proxy string can be specified with a protocol:// prefix.
270+
--connect-to=<HOST1:PORT1:HOST2:PORT2> For a request to the given HOST1:PORT1 pair, connect to HOST2:PORT2 instead. Can be specified
271+
multiple times.
274272
-I, --head Fetch the headers only.
275273
-k, --insecure Disables TLS verification of the connection.
276274
--tlsv1.3 Forces gocurl to use TLS v1.3 or newer.
277275
--tlsv1.2 Forces gocurl to use TLS v1.2 or newer.
278-
--tls-max=<VERSION> (TLS) VERSION defines maximum supported TLS version. Can be 1.2 or 1.3.
279-
The minimum acceptable version is set by tlsv1.2 or tlsv1.3.
276+
--tls-max=<VERSION> (TLS) VERSION defines maximum supported TLS version. Can be 1.2 or 1.3. The minimum acceptable
277+
version is set by tlsv1.2 or tlsv1.3.
280278
--ciphers=<space-separated list of ciphers> Specifies which ciphers to use in the connection, see
281-
https://go.dev/src/crypto/tls/cipher_suites.go for the full list of
282-
available ciphers.
279+
https://go.dev/src/crypto/tls/cipher_suites.go for the full list of available ciphers.
283280
--tls-servername=<HOSTNAME> Specifies the server name that will be sent in TLS ClientHello
284281
--http1.1 Forces gocurl to use HTTP v1.1.
285282
--http2 Forces gocurl to use HTTP v2.
286283
--http3 Forces gocurl to use HTTP v3.
287284
--ech Enables ECH support for the request.
288-
--echconfig=<base64-encoded data> ECH configuration to use for this request. Implicitly enables --ech
289-
when specified.
290-
-4, --ipv4 This option tells gocurl to use IPv4 addresses only when resolving host
291-
names.
292-
-6, --ipv6 This option tells gocurl to use IPv6 addresses only when resolving host
293-
names.
294-
--dns-servers=<DNSADDR1,DNSADDR2> DNS servers to use when making the request. Supports encrypted DNS:
295-
tls://, https://, quic://, sdns://
296-
--resolve=<[+]host:port:addr[,addr]...> Provide a custom address for a specific host. port is ignored by
297-
gocurl. '*' can be used instead of the host name. Can be specified
298-
multiple times.
299-
--tls-split-hello=<CHUNKSIZE:DELAY> An option that allows splitting TLS ClientHello in two parts in order
300-
to avoid common DPI systems detecting TLS. CHUNKSIZE is the size of the
301-
first bytes before ClientHello is split, DELAY is delay in milliseconds
302-
before sending the second part.
285+
--echconfig=<base64-encoded data> ECH configuration to use for this request. Implicitly enables --ech when specified.
286+
-4, --ipv4 This option tells gocurl to use IPv4 addresses only when resolving host names.
287+
-6, --ipv6 This option tells gocurl to use IPv6 addresses only when resolving host names.
288+
--dns-servers=<DNSADDR1,DNSADDR2> DNS servers to use when making the request. Supports encrypted DNS: tls://, https://, quic://,
289+
sdns://
290+
--resolve=<[+]host:port:addr[,addr]...> Provide a custom address for a specific host. port is ignored by gocurl. '*' can be used instead of
291+
the host name. Can be specified multiple times.
292+
--tls-split-hello=<CHUNKSIZE:DELAY> An option that allows splitting TLS ClientHello in two parts in order to avoid common DPI systems
293+
detecting TLS. CHUNKSIZE is the size of the first bytes before ClientHello is split, DELAY is delay
294+
in milliseconds before sending the second part.
303295
--json-output Makes gocurl write machine-readable output in JSON format.
304-
-o, --output=<file> Defines where to write the received data. If not set, gocurl will write
305-
everything to stdout.
306-
--experiment=<name[:value]> Allows enabling experimental options. See the documentation for
307-
available options. Can be specified multiple times.
296+
-o, --output=<file> Defines where to write the received data. If not set, gocurl will write everything to stdout.
297+
--experiment=<name[:value]> Allows enabling experimental options. See the documentation for available options. Can be specified
298+
multiple times.
308299
-v, --verbose Verbose output (optional).
309300
310301
Help Options:

internal/client/request.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ func NewRequest(cfg *config.Config) (req *http.Request, err error) {
3131
return nil, err
3232
}
3333

34-
req.Header.Set("User-Agent", fmt.Sprintf("gocurl/%s", version.Version()))
3534
addBodyHeaders(req, cfg)
3635
addHeaders(req, cfg)
3736

37+
// Only set default User-Agent if it was not set by the user.
38+
if req.Header.Get("User-Agent") == "" {
39+
req.Header.Set("User-Agent", fmt.Sprintf("gocurl/%s", version.Version()))
40+
}
41+
3842
if ur := websocket.UpgradeWebSocket(req); ur != nil {
3943
req = ur
4044
}

0 commit comments

Comments
 (0)