Created
November 9, 2015 19:05
-
-
Save andrewhampton/d6d4fe19a92d65c6324f to your computer and use it in GitHub Desktop.
build a 302 redirect reponse in golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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