httputil.DumpRequestOut - unsupported protocol scheme ""

691 views
Skip to first unread message

bsr

unread,
Jul 3, 2014, 9:37:58 AM7/3/14
to golan...@googlegroups.com
I have a problem with multipart file upload when used with a specific client library. To debug it, I am trying to dump the request. But fails.

so, I have a file a.json with content as shown, and a simple http server which try to dump the request. but, I get error

http: panic serving [::1]:63164: unsupported protocol scheme ""

goroutine 9 [running]:

net/http.func·009()

/Users/../go/src/pkg/net/http/server.go:1093 +0xae

what is wrong. Curl uses http as default protocol, but specified it explicitly too.

curl:
----

curl -v -include --form key1=value1 --form file=@a.json http://localhost:8080

a.json
--------
{"Name":"hello"}

 main.go
------
package main

import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httputil"
)

func check(err error) {
if err != nil {
panic(err)
}
}

type Test struct {
Name string
}

func handler(w http.ResponseWriter, r *http.Request) {
dmp, err := httputil.DumpRequestOut(r, true)
check(err)
fmt.Printf("Dump: %s\n", dmp)

f, _, err := r.FormFile("file")
check(err)
defer f.Close()

var buf bytes.Buffer
io.Copy(&buf, f)
b := buf.Bytes()
fmt.Printf("File: %s\n", b)

var t Test
err = json.Unmarshal(b, &t)
check(err)
fmt.Printf("Success: %s", t.Name)
}

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

Craig Wickesser

unread,
Nov 5, 2015, 11:51:43 AM11/5/15
to golang-nuts
 I have the same problem, did you resolve this?

Jud White

unread,
Nov 5, 2015, 12:04:30 PM11/5/15
to golang-nuts
Use httputil.DumpRequest for incoming requests.
Reply all
Reply to author
Forward
0 new messages