moul / http2curl

:triangular_ruler: Convert Golang's http.Request to CURL command line

Home Page:https://manfred.life/http2curl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] GetCurlCommand() can't get the request host

linuxsong opened this issue ยท comments

Describe the bug

GetCurlCommand() can not get the request host.

To Reproduce

package main

import (
	"fmt"
	"net/http"

	"moul.io/http2curl"
)

func greet(w http.ResponseWriter, r *http.Request) {
	command, _ := http2curl.GetCurlCommand(r)
	fmt.Fprintf(w, command.String())
}

func main() {
	http.HandleFunc("/", greet)
	http.ListenAndServe(":8080", nil)
}

$ curl --location --request GET 'http://127.0.0.1:8080/'

Output: curl -X 'GET' -d '' -H 'Accept: */*' -H 'User-Agent: curl/7.77.0' '/'

Expect output: curl -X 'GET' -d '' -H 'Accept: */*' -H 'User-Agent: curl/7.77.0' 'http://127.0.0.1:8080/'

๐ŸŽ‰ This issue has been resolved in version 2.3.0 ๐ŸŽ‰

The release is available on GitHub release

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€