Skip to content

Instantly share code, notes, and snippets.

@andrewhampton
Created November 9, 2015 19:05

Revisions

  1. andrewhampton created this gist Nov 9, 2015.
    14 changes: 14 additions & 0 deletions anonymous-gist.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    // 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("")))
    }