Skip to content

Commit

Permalink
Added user agent option
Browse files Browse the repository at this point in the history
  • Loading branch information
datadavev committed Mar 24, 2021
1 parent 4e42e90 commit d3e5642
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ Usage: htrace [OPTIONS] URL
Options:
-T, --timeout INTEGER Request timeout in seconds
-a, --accept TEXT Accept header value
-b, --body Show response body
-j, --json Report in JSON
-k, --insecure Don't verify certificates
-b, --body Show response body
-L, --link-type TEXT Follow link header with type
-R, --link-rel TEXT Follow link header with rel
-P, --link-profile TEXT Follow link header with profile
-R, --link-rel TEXT Follow link header with rel
-U, --user-agent TEXT User agent header value
--help Show this message and exit.
```

Expand Down
9 changes: 6 additions & 3 deletions htrace/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ def cbLinkFollow(response, *args, **kwargs):
@click.argument("url")
@click.option("-T", "--timeout", default=10, help="Request timeout in seconds")
@click.option("-a", "--accept", default="*/*", help="Accept header value")
@click.option("-b", "--body", is_flag=True, help="Show response body")
@click.option("-j", "--json", "json_report", is_flag=True, help="Report in JSON")
@click.option("-k", "--insecure", default=False, is_flag=True, help="Don't verify certificates")
@click.option("-b", "--body", is_flag=True, help="Show response body")
@click.option("-L", "--link-type", default=None, help="Follow link header with type")
@click.option("-R", "--link-rel", default='alternate', help="Follow link header with rel")
@click.option("-P", "--link-profile", default=None, help="Follow link header with profile")
def main(url, timeout, accept, json_report, insecure, body, link_type, link_rel, link_profile):
@click.option("-R", "--link-rel", default='alternate', help="Follow link header with rel")
@click.option("-U", "--user-agent", default=None, help="User agent header value")
def main(url, timeout, accept, body, json_report, insecure, link_type, link_profile, link_rel, user_agent):
if insecure:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

Expand All @@ -89,6 +90,8 @@ def main(url, timeout, accept, json_report, insecure, body, link_type, link_rel,
"Accept": accept,
"User-Agent": htrace.USER_AGENT,
}
if not user_agent is None:
headers["User-Agent"] = user_agent
hooks = {
'response': [cbUrl, cbLinkFollow]
}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "htrace"
version = "0.2.2"
version = "0.2.3"
description = "Tracing HTTP requests over redirects, link headers"
authors = ["datadavev <605409+datadavev@users.noreply.github.com>"]
license = "Apache 2.0"
Expand Down

0 comments on commit d3e5642

Please sign in to comment.