Skip to content

Commit d5dfae4

Browse files
authored
Merge #27
Add ability to change user agent.
2 parents ba72f4c + 1a5df7e commit d5dfae4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

cmd/got/main.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,14 @@ func main() {
7272
},
7373
&cli.StringSliceFlag{
7474
Name: "header",
75-
Usage: "Set these HTTP-Headers on the requests. The format has to be Key: Value",
75+
Usage: `Set these HTTP-Headers on the requests. The format has to be: -H "Key: Value"`,
7676
Aliases: []string{"H"},
7777
},
78+
&cli.StringFlag{
79+
Name: "agent",
80+
Usage: `Set user agent for got HTTP requests.`,
81+
Aliases: []string{"u"},
82+
},
7883
},
7984
Version: version,
8085
Authors: []*cli.Author{
@@ -147,6 +152,11 @@ func run(ctx context.Context, c *cli.Context) error {
147152
}
148153
}
149154

155+
// Set default user agent.
156+
if c.String("agent") != "" {
157+
got.UserAgent = c.String("agent")
158+
}
159+
150160
// Piped stdin
151161
if info.Mode()&os.ModeNamedPipe > 0 || info.Size() > 0 {
152162

got.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ type Got struct {
1616
ctx context.Context
1717
}
1818

19-
// DefaulUserAgent is the default Got user agent to send http requests.
20-
const DefaulUserAgent = "Got/1.0"
19+
// UserAgent is the default Got user agent to send http requests.
20+
var UserAgent = "Got/1.0"
2121

2222
// ErrDownloadAborted - When download is aborted by the OS before it is completed, ErrDownloadAborted will be triggered
2323
var ErrDownloadAborted = errors.New("Operation aborted")
@@ -82,7 +82,7 @@ func NewRequest(ctx context.Context, method, URL string, header []GotHeader) (re
8282
return
8383
}
8484

85-
req.Header.Set("User-Agent", DefaulUserAgent)
85+
req.Header.Set("User-Agent", UserAgent)
8686

8787
for _, h := range header {
8888
req.Header.Set(h.Key, h.Value)

0 commit comments

Comments
 (0)