Skip to content

added resp/req parsing for handleForward, minor changes to CLI #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ You can download the binary for your platform from [Releases](https://github.com
Example:

```shell
HPTS_RELEASE=v1.7.1; wget -v https://github.com/shadowy-pycoder/go-http-proxy-to-socks/releases/download/$HPTS_RELEASE/gohpts-$HPTS_RELEASE-linux-amd64.tar.gz -O gohpts && tar xvzf gohpts && mv -f gohpts-$HPTS_RELEASE-linux-amd64 gohpts && ./gohpts -h
HPTS_RELEASE=v1.7.2; wget -v https://github.com/shadowy-pycoder/go-http-proxy-to-socks/releases/download/$HPTS_RELEASE/gohpts-$HPTS_RELEASE-linux-amd64.tar.gz -O gohpts && tar xvzf gohpts && mv -f gohpts-$HPTS_RELEASE-linux-amd64 gohpts && ./gohpts -h
```

Alternatively, you can install it using `go install` command (requires Go [1.24](https://go.dev/doc/install) or later):
Expand Down
2 changes: 1 addition & 1 deletion cmd/gohpts/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func root(args []string) error {
flags.StringVar(&conf.SniffLogFile, "snifflog", "", "Sniffed traffic log file path (Default: the same as -logfile)")
flags.BoolVar(&conf.Color, "color", false, "Enable colored output for logs in stdout (no effect if log file provided or -j flag specified)")
flags.BoolFunc("v", "print version", func(flagValue string) error {
fmt.Println(gohpts.Version)
fmt.Printf("%s (built for %s %s with %s)\n", gohpts.Version, runtime.GOOS, runtime.GOARCH, runtime.Version())
os.Exit(0)
return nil
})
Expand Down
16 changes: 14 additions & 2 deletions gohpts.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ func (p *proxyapp) handleForward(w http.ResponseWriter, r *http.Request) {
return
}
req.RequestURI = ""
delConnectionHeaders(r.Header)
delHopHeaders(r.Header)
copyHeader(req.Header, r.Header)
delConnectionHeaders(req.Header)
delHopHeaders(req.Header)
if clientIP, _, err := net.SplitHostPort(req.RemoteAddr); err == nil {
appendHostToXForwardHeader(req.Header, clientIP)
}
Expand Down Expand Up @@ -392,6 +392,18 @@ func (p *proxyapp) handleForward(w http.ResponseWriter, r *http.Request) {
}
}
defer resp.Body.Close()
if p.sniff {
sniffheader := make([]string, 0, 2)
j, err := json.Marshal(&layers.HTTPMessage{Request: r})
if err == nil {
sniffheader = append(sniffheader, string(j))
}
j, err = json.Marshal(&layers.HTTPMessage{Response: resp})
if err == nil {
sniffheader = append(sniffheader, string(j))
}
p.snifflogger.Debug().Msg(fmt.Sprintf("[%s]", strings.Join(sniffheader, ",")))
}
done := make(chan bool)
if chunked {
rc := http.NewResponseController(w)
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package gohpts

const Version string = "gohpts v1.7.1"
const Version string = "gohpts v1.7.2"