Documentation
¶
Overview ¶
Package http provides a http client that outputs raw http to stdout.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewClient ¶
NewClient returns a http.Client that will output all http data to stderr. The client has various default timeouts, call with nil values to use them, otherwise pass arguments to customise.
Example ¶
package main
import (
"io/ioutil"
"github.com/petems/client-inspect/http"
)
func main() {
client := http.NewClient(nil, nil)
resp, _ := client.Get("http://example.com/")
// ensure all of the body is read
ioutil.ReadAll(resp.Body)
resp.Body.Close()
resp, _ = client.Get("https://example.com/")
ioutil.ReadAll(resp.Body)
resp.Body.Close()
}
Output:
func NewClientWriter ¶
NewClientWriter returns a http.Client that will output all http data to a given io.Writer The client has various default timeouts, call with nil values to use them, otherwise pass arguments to customise.
Example (ToCustomBuffer) ¶
package main
import (
"bytes"
"fmt"
"io/ioutil"
"strings"
"github.com/petems/client-inspect/http"
)
func main() {
buf := new(bytes.Buffer)
client := http.NewClientWriter(nil, nil, buf)
resp, _ := client.Get("http://example.com/")
// ensure all of the body is read
ioutil.ReadAll(resp.Body)
resp.Body.Close()
resp, _ = client.Get("https://example.com/")
ioutil.ReadAll(resp.Body)
resp.Body.Close()
httpLog := buf.String()
s := strings.Split(httpLog, "\n")
fmt.Println(s[4])
}
Output: Host: example.com
Example (ToCustomBufferWithRedaction) ¶
package main
import (
"bytes"
"fmt"
"io/ioutil"
"regexp"
"strings"
"github.com/petems/client-inspect/http"
)
func main() {
buf := new(bytes.Buffer)
client := http.NewClientWriter(nil, nil, buf)
resp, _ := client.Get("http://example.com/")
// ensure all of the body is read
ioutil.ReadAll(resp.Body)
resp.Body.Close()
resp, _ = client.Get("https://example.com/")
ioutil.ReadAll(resp.Body)
resp.Body.Close()
httpLog := buf.String()
s := strings.Split(httpLog, "\n")
for count, line := range s {
rgx := regexp.MustCompile(`^(Host: )(.+)$`)
line = rgx.ReplaceAllString(line, `$1[REDACTED]`)
s[count] = line
}
fmt.Println(s[4])
}
Output: Host: [REDACTED]
Example (ToStderr) ¶
package main
import (
"io/ioutil"
"os"
"github.com/petems/client-inspect/http"
)
func main() {
client := http.NewClientWriter(nil, nil, os.Stderr)
resp, _ := client.Get("http://example.com/")
// ensure all of the body is read
ioutil.ReadAll(resp.Body)
resp.Body.Close()
resp, _ = client.Get("https://example.com/")
ioutil.ReadAll(resp.Body)
resp.Body.Close()
}
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.