Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
Snawoot committed Apr 13, 2020
1 parent c626c7c commit 73cdcfb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func (s *ProxyHandler) ServeHTTP(wr http.ResponseWriter, req *http.Request) {
}
proxyReq.Header.Set("Proxy-Authorization", s.auth())
rawreq, _ := httputil.DumpRequest(proxyReq, false)
s.logger.Debug("Rewritten request: %s", string(rawreq))

// Prepare upstream TLS conn
conn, err := tls.Dial("tcp", s.upstream, nil)
Expand All @@ -172,6 +171,11 @@ func (s *ProxyHandler) ServeHTTP(wr http.ResponseWriter, req *http.Request) {

// Send proxy request
_, err = conn.Write(rawreq)
if err != nil {
s.logger.Error("Can't write tls upstream: %v", err)
http.Error(wr, "Can't write tls upstream", http.StatusBadGateway)
return
}

// Read proxy response
bufrd := bufio.NewReader(conn)
Expand All @@ -191,8 +195,12 @@ func (s *ProxyHandler) ServeHTTP(wr http.ResponseWriter, req *http.Request) {
orig_req.RequestURI = ""
orig_req.Header.Set("Connection", "close")
rawreq, _ = httputil.DumpRequest(orig_req, false)
s.logger.Debug("Tunneled request: %s", string(rawreq))
_, err = conn.Write(rawreq)
if err != nil {
s.logger.Error("Can't write tls upstream: %v", err)
http.Error(wr, "Can't write tls upstream", http.StatusBadGateway)
return
}

// Read tunneled response
resp, err = http.ReadResponse(bufrd, orig_req)
Expand Down

0 comments on commit 73cdcfb

Please sign in to comment.