Skip to content

Instantly share code, notes, and snippets.

@andrewhampton
Created November 9, 2015 19:05
Show Gist options
  • Save andrewhampton/d6d4fe19a92d65c6324f to your computer and use it in GitHub Desktop.
Save andrewhampton/d6d4fe19a92d65c6324f to your computer and use it in GitHub Desktop.
build a 302 redirect reponse in golang
// buildRedirect creates a 302 redirect for the request
func buildRedirect(request *http.Request) *http.Response {
log.Printf("transport: building redirect for: %s", request.URL.String())
response := &http.Response{
StatusCode: http.StatusFound,
Header: make(map[string][]string),
Body: buildEmptyBody()}
response.Header.Add("Location", request.URL.String())
return response
}
func buildEmptyBody() io.ReadCloser {
return ioutil.NopCloser(bytes.NewReader([]byte("")))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment