Documentation
¶
Overview ¶
package uncurl is Go library to consume a Chrome/Chromium browser "Copy as cURL" string and generate one or more Go *http.Request objects from it
In the Chrome or Chromium browser, if you open "Developer tools" and go to the Network tab and navigate somewhere with the browser, you will see a list of requests. Right-clicking one these requests yields a menu with a Copy submenu. One of those options is "Copy as cURL". It allows you to paste a `curl` command to your terminal or editor, one that reproduces the request if run.
This library accepts that text input and turns it into a Go request. Further Go requests can be generated with different target URLs while maintaining the same header values.
Index ¶
- type Uncurl
- func (un *Uncurl) Body() []byte
- func (un *Uncurl) Header() http.Header
- func (un *Uncurl) Method() string
- func (un *Uncurl) NewRequest(method, url string, body io.Reader) (*http.Request, error)
- func (un *Uncurl) NewRequestWithContext(ctx context.Context, method, url string, body io.Reader) (*http.Request, error)
- func (un *Uncurl) Request() *http.Request
- func (un *Uncurl) String() string
- func (un *Uncurl) Target() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Uncurl ¶
type Uncurl struct {
// AcceptEncoding is the original `accept-encoding` header value. Including this header on our Go
// request would signal to the `net/http` package that we do not wish to use DefaultTransport for
// our request, disabling automatic gzip handling. As that's not usually desired, the value is
// instead copied here for the user to employ as desired.
AcceptEncoding string
// contains filtered or unexported fields
}
Uncurl is the object from which requests are generated. Create one with New
func New ¶
New generates a new Uncurl object from a Chrome/Chromium "Copy as cURL" input as bytes. This is useful when you're loading from a file or concerned about efficiency. If you prefer to pass string input instead, use NewString.
func NewString ¶
NewString generates a new Uncurl object from a Chrome/Chromium "Copy as cURL" string
func (*Uncurl) Body ¶
Body returns a copy of the --data argument from the original curl string. The slice will be empty if --data was not present.
func (*Uncurl) Header ¶
Header creates a new http.Header map and copies all headers from the original curl, with the exception of Accept-Encoding, to it
func (*Uncurl) NewRequest ¶
NewRequest is like Request(), but allows the caller to set the method, url, and body; matching the function signature of http.NewRequest
func (*Uncurl) NewRequestWithContext ¶
func (un *Uncurl) NewRequestWithContext(ctx context.Context, method, url string, body io.Reader) (*http.Request, error)
NewRequestWithContext is like NewRequest but allows setting of context as well, matching the signature of http.NewRequestWithContext