Skip to content

Commit

Permalink
make printing response optional
Browse files Browse the repository at this point in the history
  • Loading branch information
jssblck committed Feb 16, 2024
1 parent a262a94 commit f77df84
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import (

var proxyTarget string
var listen string
var printResponse bool

func main() {
log.SetFlags(0)

flag.StringVar(&proxyTarget, "proxy", "https://app.fossa.com", "The host to which all requests should be proxied.")
flag.StringVar(&listen, "listen", ":3000", "The local address on which to listen.")
flag.BoolVar(&printResponse, "response", false, "Prints the response from the remote endpoint if enabled and if the response is text.")
flag.Parse()

proxyUrl, err := url.Parse(proxyTarget)
Expand Down Expand Up @@ -69,8 +71,12 @@ func main() {
// that was previously buffered at the start of this function, and perform the reverse proxy.
r.Body = ioutil.NopCloser(bytes.NewBuffer(body))

rr := responseRecorder{w}
proxy.ServeHTTP(rr, r)
if printResponse {
rr := responseRecorder{w}
proxy.ServeHTTP(rr, r)
} else {
proxy.ServeHTTP(w, r)
}
})

http.ListenAndServe(listen, nil)
Expand Down

0 comments on commit f77df84

Please sign in to comment.