Skip to content

net/http: ServeMux redirect loses query info #17841

Closed
@sdwarwick

Description

@sdwarwick

Please answer these questions before submitting your issue. Thanks!

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

go version go1.7.1 windows/amd64

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

go version go1.7.1 windows/amd64

What did you do?

this error cannot be seen on play as it requires http.

package main

import (
	"fmt"
	"net/http"
)

func main() {

	http.HandleFunc("/testOne", testOneHandler)  // no slash at end or you lose the query string
	http.HandleFunc("/testTwo/", testTwoHandler) // no slash at end or you lose the query string

	http.ListenAndServe(":8008", nil)

}

func testOneHandler(w http.ResponseWriter, r *http.Request) {

	textOut := r.URL.Query()
	fmt.Fprintln(w, textOut)

	return
}

func testTwoHandler(w http.ResponseWriter, r *http.Request) {

	textOut := r.URL.Query()
	fmt.Fprintln(w, textOut)
	return
}

What did you expect to see?

This version works:
input URL: http://localhost:8008/testOne?this=that
result: URL stays the same, and the output is: map[this:[that]]

This doesn't:

input URL: http://localhost:8008/testTwo?this=that

result: URL is redirected to http://localhost:8008/testTwo/
there is no output.

conclusion:
query strings are lost when the input URL and the http router have a "/" at the end of the selector.

this error was initially reported in #5382,

I hope that this is sufficient information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions