Add proxy support
This commit is contained in:
parent
b0f30db094
commit
0bd0f90d4a
@ -3,10 +3,24 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var PROXY_HEADER string = os.Getenv("PROXY_HEADER")
|
||||||
|
|
||||||
func respondWithIp(writer http.ResponseWriter, request *http.Request) {
|
func respondWithIp(writer http.ResponseWriter, request *http.Request) {
|
||||||
fmt.Fprintf(writer, "%s\n", request.RemoteAddr)
|
remote := request.RemoteAddr
|
||||||
|
if PROXY_HEADER != "" {
|
||||||
|
ipHeader := request.Header[PROXY_HEADER]
|
||||||
|
if len(ipHeader) != 1 {
|
||||||
|
fmt.Println("Error: Reading proxy header", PROXY_HEADER, "in request from", request.RemoteAddr, "got", ipHeader)
|
||||||
|
writer.WriteHeader(http.StatusInternalServerError)
|
||||||
|
fmt.Fprintf(writer, "Internal Server Error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
remote = ipHeader[0]
|
||||||
|
}
|
||||||
|
fmt.Fprintf(writer, "%s\n", remote)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user