Skip to content

Commit

Permalink
Merge pull request #73 from bugfan/master
Browse files Browse the repository at this point in the history
  • Loading branch information
moul authored Jun 19, 2022
2 parents 24a8cfa + 0dbc0fc commit bdc7f97
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
3 changes: 2 additions & 1 deletion http2curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func GetCurlCommand(req *http.Request) (*CurlCommand, error) {

command.append(bashEscape(requestURL))

command.append("--compressed")

return &command, nil
}

21 changes: 11 additions & 10 deletions http2curl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func ExampleGetCurlCommand() {
fmt.Println(command)

// Output:
// curl -X 'POST' -d 'age=10&name=Hudson' -H 'Api_key: 123' 'http://foo.com/cats'
// curl -X 'POST' -d 'age=10&name=Hudson' -H 'Api_key: 123' 'http://foo.com/cats' --compressed
}

func ExampleGetCurlCommand_json() {
Expand All @@ -36,7 +36,7 @@ func ExampleGetCurlCommand_json() {
fmt.Println(command)

// Output:
// curl -X 'PUT' -d '{"hello":"world","answer":42}' -H 'Content-Type: application/json' 'http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu'
// curl -X 'PUT' -d '{"hello":"world","answer":42}' -H 'Content-Type: application/json' 'http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu' --compressed
}

func ExampleGetCurlCommand_slice() {
Expand All @@ -55,7 +55,8 @@ func ExampleGetCurlCommand_slice() {
// '{"hello":"world","answer":42}' \
// -H \
// 'Content-Type: application/json' \
// 'http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu'
// 'http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu' \
// --compressed
}

func ExampleGetCurlCommand_noBody() {
Expand All @@ -66,7 +67,7 @@ func ExampleGetCurlCommand_noBody() {
fmt.Println(command)

// Output:
// curl -X 'PUT' -H 'Content-Type: application/json' 'http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu'
// curl -X 'PUT' -H 'Content-Type: application/json' 'http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu' --compressed
}

func ExampleGetCurlCommand_emptyStringBody() {
Expand All @@ -77,7 +78,7 @@ func ExampleGetCurlCommand_emptyStringBody() {
fmt.Println(command)

// Output:
// curl -X 'PUT' -H 'Content-Type: application/json' 'http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu'
// curl -X 'PUT' -H 'Content-Type: application/json' 'http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu' --compressed
}

func ExampleGetCurlCommand_newlineInBody() {
Expand All @@ -89,7 +90,7 @@ func ExampleGetCurlCommand_newlineInBody() {

// Output:
// curl -X 'POST' -d 'hello
// world' -H 'Content-Type: application/json' 'http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu'
// world' -H 'Content-Type: application/json' 'http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu' --compressed
}

func ExampleGetCurlCommand_specialCharsInBody() {
Expand All @@ -100,7 +101,7 @@ func ExampleGetCurlCommand_specialCharsInBody() {
fmt.Println(command)

// Output:
// curl -X 'POST' -d 'Hello $123 o'\''neill -"-' -H 'Content-Type: application/json' 'http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu'
// curl -X 'POST' -d 'Hello $123 o'\''neill -"-' -H 'Content-Type: application/json' 'http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu' --compressed
}

func ExampleGetCurlCommand_other() {
Expand All @@ -119,7 +120,7 @@ func ExampleGetCurlCommand_other() {
panic(err)
}
fmt.Println(command)
// Output: curl -X 'PUT' -d '{"hello":"world","answer":42}' -H 'Content-Type: application/json' -H 'X-Auth-Token: private-token' 'http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu'
// Output: curl -X 'PUT' -d '{"hello":"world","answer":42}' -H 'Content-Type: application/json' -H 'X-Auth-Token: private-token' 'http://www.example.com/abc/def.ghi?jlk=mno&pqr=stu' --compressed
}

func ExampleGetCurlCommand_https() {
Expand All @@ -138,7 +139,7 @@ func ExampleGetCurlCommand_https() {
panic(err)
}
fmt.Println(command)
// Output: curl -k -X 'PUT' -d '{"hello":"world","answer":42}' -H 'Content-Type: application/json' -H 'X-Auth-Token: private-token' 'https://www.example.com/abc/def.ghi?jlk=mno&pqr=stu'
// Output: curl -k -X 'PUT' -d '{"hello":"world","answer":42}' -H 'Content-Type: application/json' -H 'X-Auth-Token: private-token' 'https://www.example.com/abc/def.ghi?jlk=mno&pqr=stu' --compressed
}

// Benchmark test for GetCurlCommand
Expand Down Expand Up @@ -176,7 +177,7 @@ func TestGetCurlCommand_serverSide(t *testing.T) {
t.Error(err)
}

exp := fmt.Sprintf("curl -X 'GET' -H 'Accept-Encoding: gzip' -H 'User-Agent: Go-http-client/1.1' '%s/'", svr.URL)
exp := fmt.Sprintf("curl -X 'GET' -H 'Accept-Encoding: gzip' -H 'User-Agent: Go-http-client/1.1' '%s/' --compressed", svr.URL)
if out := string(data); out != exp {
t.Errorf("act: %s, exp: %s", out, exp)
}
Expand Down

0 comments on commit bdc7f97

Please sign in to comment.