Skip to content

Instantly share code, notes, and snippets.

@GauthamBanasandra
Last active May 13, 2024 07:47
Show Gist options
  • Save GauthamBanasandra/8d6f27e25a4bb1a805e11716aa4bb66c to your computer and use it in GitHub Desktop.
Save GauthamBanasandra/8d6f27e25a4bb1a805e11716aa4bb66c to your computer and use it in GitHub Desktop.
A simple HTTP server in Golang which just prints all the headers
package main
import (
"net/http"
"fmt"
"time"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Request at %v\n", time.Now())
for k, v := range r.Header {
fmt.Printf("%v: %v\n", k, v)
}
if r.Header.Get("Authorization") == "" {
w.WriteHeader(http.StatusUnauthorized)
w.Header().Set("WWW-Authenticate", `Digest realm="testrealm@host.com", qop="auth,auth-int", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41"`)
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":9090", nil)
}
package main
import (
"net/http"
"fmt"
"time"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Request at %v\n", time.Now())
for k, v := range r.Header {
fmt.Printf("%v: %v\n", k, v)
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":9090", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment