Skip to content

Commit

Permalink
Merge branch 'hotfix/0.3.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
golflima committed Jun 29, 2020
2 parents c43e4a1 + 4906aa2 commit f3903da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/examples/proxy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ services:
image: frxyt/gohrec:latest
command:
- record
- --freemem
- --index
- --pprof
- --proxy
Expand Down
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/url"
"os"
"regexp"
"runtime/debug"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -450,6 +451,12 @@ func (ghr goHRec) proxyHandler(w http.ResponseWriter, r *http.Request) {
defer ghr.saveRequest(req, record, rt, bodyReader)
}

func freeMemHandler(w http.ResponseWriter, r *http.Request) {
debug.FreeOSMemory()
w.WriteHeader(http.StatusAccepted)
fmt.Fprintln(w, "Requested free os memory.")
}

func record() {
record := flag.NewFlagSet("record", flag.PanicOnError)
listen := record.String("listen", ":8080", "Interface and port to listen.")
Expand All @@ -461,6 +468,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.")
enableFreeMem := record.Bool("freemem", false, "Enable free memory endpoint /debug/freemem.")
enablePprof := record.Bool("pprof", false, "Enable pprof endpoints /debug/pprof/*.")
verbose := record.Bool("verbose", false, "Log processed request status.")

Expand Down Expand Up @@ -540,6 +548,9 @@ func record() {
gohrecMux.HandleFunc("/", gohrec.handler)
}

if *enableFreeMem {
gohrecMux.HandleFunc("/debug/freemem", freeMemHandler)
}
if *enablePprof {
// Register pprof handlers
gohrecMux.HandleFunc("/debug/pprof/", pprof.Index)
Expand Down

0 comments on commit f3903da

Please sign in to comment.