Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mstaack/3f9e5344398c6de249aa8bbec58ef554 to your computer and use it in GitHub Desktop.
Save mstaack/3f9e5344398c6de249aa8bbec58ef554 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="[email protected]", 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