Skip to content

Commit

Permalink
add removal of proxy header
Browse files Browse the repository at this point in the history
  • Loading branch information
xvzc committed Jan 14, 2022
1 parent 9d5cd8f commit cb6a593
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
22 changes: 22 additions & 0 deletions packet/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,28 @@ func (p *HttpPacket) IsConnectMethod() bool {
return p.Method() == "CONNECT"
}

func (p *HttpPacket) RemoveProxyHeader() {
s := string(p.raw)

lines := strings.Split(s, "\n")
for i := 0; i < len(lines); i++ {
if strings.HasPrefix(lines[i], "Proxy-Connection") {
lines[i] = ""
}
}

result := ""
for i := 0; i < len(lines); i++ {
if lines[i] == "" {
continue
}

result += lines[i] + "\n"
}

p.raw = []byte(result)
}

func parse(raw []byte) (string, string, string) {
var firstLine string
for i := 0; i < len(raw); i++ {
Expand Down
5 changes: 4 additions & 1 deletion proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ func (p *Proxy) Start() {
log.Debug("Client sent data: ", len(b))

pkt := packet.NewHttpPacket(b)
log.Debug("New request: \n\n" + string(pkt.Raw()))

if !pkt.IsValidMethod() {
log.Println("Unsupported method: ", pkt.Method())
return
}

pkt.RemoveProxyHeader()

log.Debug("New request: \n\n" + string(pkt.Raw()))

if pkt.IsConnectMethod() {
log.Debug("[HTTPS] Start")
go conn.HandleHttps(pkt)
Expand Down

0 comments on commit cb6a593

Please sign in to comment.