added logging
This commit is contained in:
parent
ae18c0ea3b
commit
a5e74338d4
5
Dockerfile
Normal file
5
Dockerfile
Normal file
@ -0,0 +1,5 @@
|
||||
FROM scratch
|
||||
|
||||
COPY proxy /proxy
|
||||
|
||||
ENTRYPOINT ["/proxy"]
|
6
proxy.go
6
proxy.go
@ -2,6 +2,7 @@ package simpleproxy
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
@ -41,6 +42,9 @@ func (p *Proxy) ListenAndServe() error {
|
||||
// ServeHTTP is the main handler for the proxy server.
|
||||
// all requests here should be proxied to the server.
|
||||
func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
logger := slog.Default().With("method", r.Method, "url", r.URL.String())
|
||||
|
||||
logger.Info("proxying request")
|
||||
// all requests should be proxied to the server.
|
||||
req, err := http.NewRequest(r.Method, p.ServerAddr+r.URL.String(), r.Body)
|
||||
if err != nil {
|
||||
@ -61,6 +65,8 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
logger = slog.Default().With("status", resp.StatusCode)
|
||||
|
||||
mirrorResponse(w, resp)
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user