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

Comments

Projects
None yet
5 participants
@terinjokes
Copy link
Contributor

commented Dec 19, 2017

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

This comment has been minimized.

Copy link

commented Dec 19, 2017

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

@bradfitz

This comment has been minimized.

Copy link
Member

commented Dec 19, 2017

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

@bradfitz

This comment has been minimized.

Copy link
Member

commented Dec 19, 2017

@namusyaka

This comment has been minimized.

Copy link
Member

commented Dec 20, 2017

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

@odeke-em

This comment has been minimized.

Copy link
Member

commented Dec 21, 2017

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

@gopherbot gopherbot closed this in 936b6bf Jan 11, 2018

@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.
You can’t perform that action at this time.