Skip to content

Commit

Permalink
Respond OK to application ASAP when using CONNECT
Browse files Browse the repository at this point in the history
  • Loading branch information
uaalto committed Aug 17, 2015
1 parent d939f87 commit 5d6e2fb
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/github.com/getlantern/flashlight/client/handler.go
Expand Up @@ -73,6 +73,19 @@ func (client *Client) intercept(resp http.ResponseWriter, req *http.Request) {
return
}

// Respond OK as soon as possible, even if we don't have the outbound connection
// established yet, to avoid timeouts on the client application
success := make(chan bool, 1)
go func() {
err = respondOK(clientConn, req)
if err != nil {
log.Errorf("Unable to respond OK: %s", err)
success <- false
return
}
success <- true
}()

// Establish outbound connection.
addr := hostIncludingPort(req, 443)
d := func(network, addr string) (net.Conn, error) {
Expand All @@ -89,15 +102,10 @@ func (client *Client) intercept(resp http.ResponseWriter, req *http.Request) {
return
}

// Respond OK
err = respondOK(clientConn, req)
if err != nil {
log.Errorf("Unable to respond OK: %s", err)
return
if <-success {
// Pipe data between the client and the proxy.
pipeData(clientConn, connOut, func() { closeOnce.Do(closeConns) })
}

// Pipe data between the client and the proxy.
pipeData(clientConn, connOut, func() { closeOnce.Do(closeConns) })
}

// targetQOS determines the target quality of service given the X-Flashlight-QOS
Expand Down

0 comments on commit 5d6e2fb

Please sign in to comment.