Skip to content

Instantly share code, notes, and snippets.

@lotusirous
Created July 4, 2020 09:34
Show Gist options
  • Select an option

  • Save lotusirous/43d2948f0b3310db0d2d6d9ecb2f4ee5 to your computer and use it in GitHub Desktop.

Select an option

Save lotusirous/43d2948f0b3310db0d2d6d9ecb2f4ee5 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"net/http"
"net/http/httputil"
)
// HandleDump returns an http.HandlerFunc that processes an http.Request
// to return a raw content from request.
func HandleDump() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
b, err := httputil.DumpRequest(r, true)
if err != nil {
fmt.Fprintf(w, "internal error: %v\n", err)
return
}
w.Write(b)
}
}
func main() {
addr := ":1234"
r := http.NewServeMux()
r.Handle("/", HandleDump())
svr := &http.Server{
Addr: addr,
Handler: r,
}
log.Println("server started", addr)
log.Fatal(svr.ListenAndServe())
}
@lotusirous
Copy link
Copy Markdown
Author

The following is a raw request of multipart/mixed performed by curl

$ curl -X POST -F "asdf=asdf" -F "data=@data.xml"  http://localhost:1234
POST / HTTP/1.1
Host: localhost:1234
Accept: */*
Content-Length: 421
Content-Type: multipart/form-data; boundary=------------------------326bcde20f093527
User-Agent: curl/7.64.1

--------------------------326bcde20f093527
Content-Disposition: form-data; name="asdf"

asdf
--------------------------326bcde20f093527
Content-Disposition: form-data; name="data"; filename="data.xml"
Content-Type: application/xml

<note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
</note>
--------------------------326bcde20f093527--

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment