Skip to content

Commit

Permalink
Merge pull request #35 from SimonBaeumer/add-redirect-route
Browse files Browse the repository at this point in the history
Add redirect route to http_test_server
  • Loading branch information
SimonBaeumer authored Feb 22, 2019
2 parents 61c5e4b + 617d4b6 commit c11597b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions development/http/http_test_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,37 @@ import (
"net/http"
)

const RedirectStatusCode = 302

func httpHandler(w http.ResponseWriter, r *http.Request) {
log.Println("/")

printHeader(r)

w.Header().Add("key", "value")
}

func printHeader(r *http.Request) {
for k, values := range r.Header {
for _, value := range values {
fmt.Println("key:", k, "val:", value)
}
}

w.Header().Add("key", "value")
}

func main() {
fmt.Println("Running on localhost:9090")
http.HandleFunc("/", httpHandler)
http.HandleFunc("/redirect", redirectHandler)
err := http.ListenAndServe(":9090", nil)

if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}

func redirectHandler(w http.ResponseWriter, r *http.Request) {
log.Println("/redirect")
printHeader(r)
http.Redirect(w, r, "/", RedirectStatusCode)
}

0 comments on commit c11597b

Please sign in to comment.