I'm trying to get the origin of a http request. I don't know exactly
how http communication works, but the address of the origin of the
request must be included in there somewhere, because otherwise you
wouldn't be able to respond. Is there any way to do this using the
http package?
What I was trying is below. However all the information that I get
from the request is &{GET / / HTTP/1.1 1 1 map[] 0x7f574c52a030 -1 []
false localhost:8085 Go http package map[] map[]}. This has the
destination "localhost:8085", but I can't figure out how to get the
origin. Are the destination and origin the same because I'm using
localhost to try this example? Is there another way of doing this?
// server.go ----------------------------------------------------
package main
import (
"fmt"
"http"
)
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8085", nil)
}
func handler(w http.ResponseWriter, r *http. Request) {
fmt.Printf("r: %v\n", r)
}
// client.go ------------------------------------------------------
package main
import (
"http"
)
func main() {
http.Get("
http://localhost:8085")
}