Skip to content

net/http: 301 redirect loses POST data #12456

Closed
@johndaniels

Description

@johndaniels
What I did:

Because of a coding error, I was trying to make a POST request to a go webserver with the path "//create", instead of "/create"

Expected Behavior:

The server should give me a 404 or 400 error, or pass the request along normally. I'm not convinced that "//foo" is a valid path, but if it isn't the server should return an error rather then mangling the request passed to the handler.

Actual Behavior:

The Go server decided to claim that the request was a GET request with no content. Attached is a go server that exhibits this bug along with python code to make the strange request.

Python request script
import requests
data = {'a': 1}
requests.post("http://localhost:8081//foo", data=data)
Go Server
package main

import (
    "log"
    "net/http/httputil"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    data, _ := httputil.DumpRequest(r, true)
    log.Println(string(data))
}

func main() {
    http.HandleFunc("/foo", handler)
    http.ListenAndServe("127.0.0.1:8081", nil)
}

The output I get from the go script is the following

2015/09/02 13:32:45 GET /foo HTTP/1.1
Host: localhost:8081
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
User-Agent: python-requests/2.7.0 CPython/2.7.6 Windows/8

I'm using go 1.4.2 windows/amd64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions