Skip to content

Instantly share code, notes, and snippets.

@LautaroJayat
Created May 10, 2021 12:49
Show Gist options
  • Save LautaroJayat/c6bffed5975ab81e8e10e0c92fa1a1fb to your computer and use it in GitHub Desktop.
Save LautaroJayat/c6bffed5975ab81e8e10e0c92fa1a1fb to your computer and use it in GitHub Desktop.
target server go
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