Skip to content

Commit

Permalink
Support basic-auth option (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe authored Nov 30, 2021
1 parent f20f56b commit 3e5aeee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Usage:
Flags:
-A, --agent string User-Agent name (default "rj/v0.0.1")
-u, --basic string Basic Auth username:password
-H, --header stringArray HTTP Request Header
-h, --help help for rj
--http1.1 Use HTTP/1.1
Expand All @@ -38,14 +39,12 @@ with `-b` Option:

support HTTP/3 with `--http3` option:

![Screenshot](
https://user-images.githubusercontent.com/10682/143975571-3925c02d-113d-414f-b2cc-a445c54bbd18.png)

![Screenshot](https://user-images.githubusercontent.com/10682/143975571-3925c02d-113d-414f-b2cc-a445c54bbd18.png)

## Author

Yusuke Wada <https://github.com/yusukebe>

## License

MIT
MIT
9 changes: 9 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type param struct {
includeBody bool
http1_1 bool
http3 bool
basicAuth string
}

var rootCmd = &cobra.Command{
Expand All @@ -47,6 +48,7 @@ var rootCmd = &cobra.Command{
includeBody, _ := cmd.Flags().GetBool("include-body")
http1_1, _ := cmd.Flags().GetBool("http1.1")
http3, _ := cmd.Flags().GetBool("http3")
basicAuth, _ := cmd.Flags().GetString("basic")

param := param{
method: method,
Expand All @@ -55,6 +57,7 @@ var rootCmd = &cobra.Command{
includeBody: includeBody,
http1_1: http1_1,
http3: http3,
basicAuth: basicAuth,
}
request(url, param)
},
Expand All @@ -67,6 +70,7 @@ func init() {
rootCmd.Flags().BoolP("include-body", "b", false, "Include Response body")
rootCmd.Flags().BoolP("http1.1", "", false, "Use HTTP/1.1")
rootCmd.Flags().BoolP("http3", "", false, "Use HTTP/3")
rootCmd.Flags().StringP("basic", "u", "", "Basic Auth username:password")
}

func Execute() {
Expand All @@ -90,6 +94,11 @@ func request(url string, param param) {
}
}

if param.basicAuth != "" {
kv := strings.Split(param.basicAuth, ":")
req.SetBasicAuth(kv[0], kv[1])
}

var start, connect, dns, tlsHandshake, wait time.Time
var dnsMs, sslMs, connectionMs, ttfbMs, totalMs float64

Expand Down

0 comments on commit 3e5aeee

Please sign in to comment.