-
-
Save mstaack/3f9e5344398c6de249aa8bbec58ef554 to your computer and use it in GitHub Desktop.
A simple HTTP server in Golang which just prints all the headers
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/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) | |
} |
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/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