first commit
This commit is contained in:
commit
87a78e5cfd
63
main.go
Normal file
63
main.go
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func handler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
fmt.Println(strings.Repeat("~", 80))
|
||||||
|
|
||||||
|
if len(r.Header) > 0 {
|
||||||
|
fmt.Println("--- Headers ---")
|
||||||
|
for name, values := range r.Header {
|
||||||
|
for _, value := range values {
|
||||||
|
fmt.Printf("%s: %s\n", name, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(r.URL.Query()) > 0 {
|
||||||
|
fmt.Println("--- URL Parameters ---")
|
||||||
|
r.ParseForm()
|
||||||
|
for key, values := range r.URL.Query() {
|
||||||
|
for _, value := range values {
|
||||||
|
fmt.Printf("%s: %s\n", key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(r.Cookies()) > 0 {
|
||||||
|
fmt.Println("--- Cookies ---")
|
||||||
|
for _, cookie := range r.Cookies() {
|
||||||
|
fmt.Printf("%s: %s\n", cookie.Name, cookie.Value)
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
|
||||||
|
bodyBytes, err := io.ReadAll(r.Body)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error reading body:", err)
|
||||||
|
} else {
|
||||||
|
if bodyStr := string(bodyBytes); bodyStr != "" {
|
||||||
|
fmt.Println("--- Body ---")
|
||||||
|
fmt.Println(bodyStr)
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
defer r.Body.Close()
|
||||||
|
|
||||||
|
fmt.Println("--- Client IP ---")
|
||||||
|
fmt.Println(r.RemoteAddr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
http.HandleFunc("/", handler)
|
||||||
|
fmt.Println("Server started at http://localhost:8080")
|
||||||
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user