Skip to content

Instantly share code, notes, and snippets.

@johnboxall
Created June 2, 2013 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnboxall/5695301 to your computer and use it in GitHub Desktop.
Save johnboxall/5695301 to your computer and use it in GitHub Desktop.
Go's default redirect behaviour seems to merge slashes in HTTP redirects. How can you override this behaviour?
package main
import (
"testing"
"net/http"
"net/http/httptest"
)
func TestMergeSlashes(t *testing.T) {
req, _ := http.NewRequest("GET", "http://foo.com/", nil)
resp := httptest.NewRecorder()
http.Redirect(resp, req, "/http://bar.com/", 302)
if g, e := resp.Header().Get("Location"), "/http://bar.com/"; g != e {
t.Errorf("Location header was %q; want %q", g, e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment