Created
September 28, 2017 13:14
-
-
Save nwjlyons/121063467e11d0c30e7561357b6ea24f to your computer and use it in GitHub Desktop.
Print HTTP request to stdout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net" | |
"os" | |
"log" | |
"fmt" | |
"io" | |
) | |
func main() { | |
port := 8080 | |
ln, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) | |
if err != nil { | |
log.Fatalf("could not listen to tcp connections on port %d: %v", port, err) | |
} | |
for { | |
conn, err := ln.Accept() | |
if err != nil { | |
log.Printf("could not accept connection: %v", err) | |
} | |
go func(){ | |
io.Copy(os.Stdout, conn) | |
}() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For debugging purposes it is useful to see the request that gets sent.
eg. I was trying to send this request and it was failing because
#
isn't allowed in JSON in PyCharm. When I fired the request to the echo.go server above I could see why.This is what was sent