Skip to content

Instantly share code, notes, and snippets.

@jesugmz
Last active April 21, 2022 13:21
Show Gist options
  • Save jesugmz/5bc3785163fc1e44e86c7b3dc5146398 to your computer and use it in GitHub Desktop.
Save jesugmz/5bc3785163fc1e44e86c7b3dc5146398 to your computer and use it in GitHub Desktop.
Debug Golang HTTP response

Debug HTTP response with Golang's httputil package https://golang.org/pkg/net/http/httputil/#DumpResponse.

import (
  "fmt"
  "net/http"
  "net/http/httputil"
)

resp, _ := http.Get("https://kctbh9vrtdwd.statuspage.io/api/v2/status.json")
dump, _ := httputil.DumpResponse(resp, true)
fmt.Printf("%s", dump)

will produce:

HTTP/2.0 200 OK
Content-Length: 215
Access-Control-Allow-Origin: *
Age: 371
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json; charset=utf-8
Date: Sat, 06 Mar 2021 12:39:15 GMT
Etag: W/"a29739d78e953d3e25f3a53891269d4e"
Referrer-Policy: strict-origin-when-cross-origin
Strict-Transport-Security: max-age=259200
Vary: Accept,Accept-Encoding,Fastly-SSL
X-Cache: HIT
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
X-Request-Id: df55ea4c-a05e-4674-b06c-c2d46c44a489
X-Runtime: 0.045800
X-Statuspage-Skip-Logging: true
X-Statuspage-Version: 5d61194286ceb9374633214f8becf79e1e15578b
X-Xss-Protection: 1; mode=block

{"page":{"id":"kctbh9vrtdwd","name":"GitHub","url":"https://www.githubstatus.com","time_zone":"Etc/UTC","updated_at":"2021-03-01T11:41:09.858Z"},"status":{"indicator":"none","description":"All Systems Operational"}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment