Skip to content

net/http: receiving binary post-data in handler (server) #5560

Closed
@gopherbot

Description

@gopherbot

by cgmurray:

What steps will reproduce the problem?

Run the following server app with "go run":
package main

import (
    "fmt"
    "io"
    "net/http"
)

type handler struct{}

func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    r.Header.Set("Content-Type", "application/octet-stream")
    io.Copy(w, r.Body)
}

func main() {
    port := 9090
    http.ListenAndServe(fmt.Sprintf(":%d", port), new(handler))
}

create a text-file, "two_lines", with the following content:
one
two

post the text-file using curl:
curl -X POST -d@two_lines  --header "Content-Type: application/octet-stream"
http://localhost:9090

What is the expected output?
one
two

What do you see instead?
onetwo

Which operating system are you using?
OS X 10.8.3

Which version are you using?  (run 'go version')
go version go1.1 darwin/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