Skip to content

Add User-Agent to all requests by default; add arg to drop it#647

Open
craigreyenga wants to merge 1 commit intoraviqqe:mainfrom
craigreyenga:useragent
Open

Add User-Agent to all requests by default; add arg to drop it#647
craigreyenga wants to merge 1 commit intoraviqqe:mainfrom
craigreyenga:useragent

Conversation

@craigreyenga
Copy link

Closes #378

A User-Agent header is now added to all requests:

craig@Mac> ./muffet http://localhost:6890/
GET / HTTP/1.1
User-Agent: muffet/2.11.0 (macOS; arm64)         <<----------- !
Host: localhost:6890
Accept: */*
Connection: close

Customize by using the header argument:

craig@Mac> ./muffet --header="User-Agent: Chrome" http://localhost:6890/
GET / HTTP/1.1
User-Agent: Chrome
Host: localhost:6890
Accept: */*
Connection: close

Legacy behavior (no UA):

craig@Mac> ./muffet --drop-user-agent http://localhost:6890/
GET / HTTP/1.1
Host: localhost:6890
Accept: */*
Connection: close

uaHeaderName := "User-Agent"

// Add a default User-Agent
h.Add(uaHeaderName, fmt.Sprintf("%s/%s (%s; %s)", agentName, version, getOSName(), runtime.GOARCH))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is about as fancy as the user-agent can get without importing more libraries or executing external commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Send a default user agent

1 participant