Created
May 10, 2021 12:49
-
-
Save LautaroJayat/c6bffed5975ab81e8e10e0c92fa1a1fb to your computer and use it in GitHub Desktop.
target server go
This file contains hidden or 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 ( | |
"fmt" | |
"io" | |
"net/http" | |
"os" | |
) | |
func welcome(w http.ResponseWriter, r *http.Request) { | |
if r.Host != "localhost:8081" { | |
w.WriteHeader(http.StatusForbidden) | |
return | |
} | |
if os.Getenv("SECRET") != "" && r.Header.Get("SECRET") != os.Getenv("SECRET") { | |
w.WriteHeader(http.StatusForbidden) | |
return | |
} | |
w.Header().Add("x-method", r.Method) | |
w.Header().Add("x-url", r.RequestURI) | |
w.Header().Add("x-host", r.Host) | |
io.WriteString(w, "hi from target server!\n") | |
} | |
func main(){ | |
fmt.Println("Starting target server") | |
mux := http.NewServeMux() | |
mux.HandleFunc("/", welcome) | |
srv := http.Server{ | |
Handler: mux, | |
Addr: "localhost:8080", | |
} | |
srv.ListenAndServe() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment