Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: muxer no longer redirects host patterns in go1.10 #23183

Closed
terinjokes opened this issue Dec 19, 2017 · 5 comments
Closed

net/http: muxer no longer redirects host patterns in go1.10 #23183

terinjokes opened this issue Dec 19, 2017 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@terinjokes
Copy link
Contributor

What version of Go are you using (go version)?

go version go1.10beta1 linux/amd64

Does this issue reproduce with the latest release?

Not reproducible with go version go1.9.2 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/terin/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/terin/go"
GORACE=""
GOROOT="/home/terin/sdk/go1.10beta1"
GOTMPDIR=""
GOTOOLDIR="/home/terin/sdk/go1.10beta1/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build956333713=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
	"net/http"
	"net/http/httptest"
	"testing"
)

type stringHandler string

func (s stringHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Result", string(s))
}

func TestMuxer(t *testing.T) {
	mux := http.NewServeMux()
	mux.Handle("example.org/pkg/foo/", stringHandler("example.org/pkg/foo/"))

	tests := []struct {
		url      string
		code     int
		response string
	}{
		{"http://example.org/pkg/foo", 301, ""},
		{"http://example.org/pkg/foo/", 200, "example.org/pkg/foo/"},
	}

	for i, tt := range tests {
		r, _ := http.NewRequest("GET", tt.url, nil)
		w := httptest.NewRecorder()

		mux.ServeHTTP(w, r)

		if got, want := w.Code, tt.code; got != want {
			t.Errorf("#%d Status = %d; want = %d", i, got, want)
		}

		if w.Code == 200 {
			if got, want := w.HeaderMap.Get("Result"), tt.response; got != want {
				t.Errorf("$%d Result = %q; want = %q", i, got, want)
			}
		}
	}
}

What did you expect to see?

Output from go1.9.2:

=== RUN   TestMuxer
--- PASS: TestMuxer (0.00s)
PASS
ok      _/home/terin  0.002s

What did you see instead?

Output from go1.10beta1:

=== RUN   TestMuxer
--- FAIL: TestMuxer (0.00s)
        muxer_test.go:35: #0 Status = 404; want = 301
FAIL
FAIL    _/home/terin    0.002s
@gopherbot
Copy link

Change https://golang.org/cl/84695 mentions this issue: net/http: redirect host-based patterns to trailing slash

@bradfitz bradfitz added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels Dec 19, 2017
@bradfitz bradfitz added this to the Go1.10 milestone Dec 19, 2017
@bradfitz
Copy link
Contributor

Looks like this change in behavior was due to ab40107 from @namusyaka for #17841.

@bradfitz
Copy link
Contributor

Also /cc @tombergan @odeke-em who reviewed https://go-review.googlesource.com/61210

@namusyaka
Copy link
Member

namusyaka commented Dec 20, 2017

I'm going to take a look at the CL in a few days, thanks @terinjokes

@odeke-em
Copy link
Member

Thank you for the report @terinjokes and for the tag @bradfitz, I'll take a look perhaps over the weekend or earlier.

@golang golang locked and limited conversation to collaborators Jan 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Projects
None yet
Development

No branches or pull requests

5 participants