diff options
author | Ben Morrison <ben@gbmor.dev> | 2019-05-20 22:52:50 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2019-05-21 03:42:17 -0400 |
commit | df1d1efa19aed5bc6553c7c0a0b4b7dfe20e3bd0 (patch) | |
tree | 2a60f30829b8d1fca943aa3ca4a077cb4cb3517d /http.go | |
parent | a3c67f1ff9ed2cff44930f6bfd17a3ec272fe2f5 (diff) | |
download | getwtxt-df1d1efa19aed5bc6553c7c0a0b4b7dfe20e3bd0.tar.gz |
fleshed out POST handler, added remote registry list
Diffstat (limited to 'http.go')
-rw-r--r-- | http.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/http.go b/http.go index 4b6d460..1f6126c 100644 --- a/http.go +++ b/http.go @@ -3,6 +3,7 @@ package main import ( "context" "log" + "net" "net/http" "strings" ) @@ -17,14 +18,14 @@ func newCtxUserIP(ctx context.Context, r *http.Request) context.Context { } // Retrieves a request's IP address from the request's context -func getIPFromCtx(ctx context.Context) string { +func getIPFromCtx(ctx context.Context) net.IP { uip, ok := ctx.Value(ctxKey).(string) if !ok { log.Printf("Couldn't retrieve IP from request\n") } - return uip + return net.ParseIP(uip) } // Shim function to modify/pass context value to a handler @@ -47,6 +48,7 @@ func log200(r *http.Request) { func log400(w http.ResponseWriter, r *http.Request, err error) { uip := getIPFromCtx(r.Context()) log.Printf("*** %v :: 400 :: %v %v :: %v\n", uip, r.Method, r.URL, err) + http.Error(w, err.Error(), http.StatusBadRequest) } // log output for 404s |