Skip to content

Commit

Permalink
Merge branch 'hotfix/0.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
golflima committed Jun 25, 2020
2 parents 83ee8fa + 0d7cda5 commit 3b13ca8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
/gohrec
/index
/log
*.log
*.log
profile*
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
/gohrec
/index
/log
*.log
*.log
profile*
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* `--listen <interface:port>`: Interface and port to listen (default: `:8080`).
* `--max-body-size <bytes>`: Maximum size of body in bytes that will be recorded, `-1` to disallow limit (default: `-1`).
* `--only-path <regexp>`: If set, record only requests that match the specified URL path pattern.
* `--pprof`: Enable pprof endpoints `/debug/pprof/*`.
* `--proxy`: Enable proxy mode.
* `--redact-body <regexp>[/<replacement>]`: If set, matching parts of the specified pattern in request body will be redacted.
* `--redact-headers <regexp>>[/<replacement>]`: If set, matching parts of the specified pattern in request headers will be redacted.
Expand Down
3 changes: 3 additions & 0 deletions docs/examples/proxy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ services:
command:
- record
- --index
- --pprof
- --proxy
- --redact-body=(<secret>).*(<secret />)/$$1**REDACTED**$$2
- --redact-body=p@s$$w0rD
Expand All @@ -37,6 +38,8 @@ services:
- public
volumes:
- ./log:/gohrec/log:rw
#- /etc/timezone:/etc/timezone:ro
#- /etc/localtime:/etc/localtime:ro

traefik:
image: traefik:2.2
Expand Down
23 changes: 19 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"math/rand"
"net/http"
"net/http/httputil"
"net/http/pprof"
"net/url"
"os"
"regexp"
Expand Down Expand Up @@ -144,7 +145,7 @@ func dumpValues(in map[string][]string) []string {
out := []string{}
for name, values := range in {
for _, value := range values {
out = append(out, fmt.Sprintf("%v: %v", name, value))
out = append(out, fmt.Sprintf("%s: %s", name, value))
}
}
sort.Strings(out)
Expand Down Expand Up @@ -455,6 +456,7 @@ func record() {
echo := record.Bool("echo", false, "Echo logged request on calls.")
index := record.Bool("index", false, "Build an index of hashes and their clear text representation.")
proxy := record.Bool("proxy", false, "Enable proxy mode.")
enablePprof := record.Bool("pprof", false, "Enable pprof endpoints /debug/pprof/*.")
verbose := record.Bool("verbose", false, "Log processed request status.")

var redactBody arrayRedactFlag
Expand Down Expand Up @@ -517,19 +519,32 @@ func record() {
log.Printf(" echo: %t", gohrec.echo)
log.Printf(" index: %t", gohrec.index)
log.Printf(" proxy: %t", gohrec.proxy)
log.Printf(" pprof: %t", *enablePprof)
log.Printf(" verbose: %t", gohrec.verbose)

rand.Seed(time.Now().UnixNano())

gohrecMux := http.NewServeMux()

if gohrec.proxy {
if gohrec.targetURL == nil {
panic("--target-url is required when proxy mode is enabled!")
}
http.HandleFunc("/", gohrec.proxyHandler)
gohrecMux.HandleFunc("/", gohrec.proxyHandler)
} else {
http.HandleFunc("/", gohrec.handler)
gohrecMux.HandleFunc("/", gohrec.handler)
}

if *enablePprof {
// Register pprof handlers
gohrecMux.HandleFunc("/debug/pprof/", pprof.Index)
gohrecMux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
gohrecMux.HandleFunc("/debug/pprof/profile", pprof.Profile)
gohrecMux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
gohrecMux.HandleFunc("/debug/pprof/trace", pprof.Trace)
}
log.Fatal(http.ListenAndServe(gohrec.listen, nil))

log.Fatal(http.ListenAndServe(gohrec.listen, gohrecMux))
}

func redo() {
Expand Down

0 comments on commit 3b13ca8

Please sign in to comment.