[tor-commits] [meek/webextension] Read the requestSpec outside of roundTrip.
dcf at torproject.org
dcf at torproject.org
Sat Mar 30 19:36:57 UTC 2019
commit 25ecd3e29b6699dc43970d0f4e4813651c64cf15
Author: David Fifield <david at bamsoftware.com>
Date: Sat Mar 30 12:10:19 2019 -0600
Read the requestSpec outside of roundTrip.
The difference here is that we don't send a JSON error response as a
result of errors at this stage.
---
webextension/native/main.go | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/webextension/native/main.go b/webextension/native/main.go
index d889e9c..c2d9873 100644
--- a/webextension/native/main.go
+++ b/webextension/native/main.go
@@ -175,19 +175,10 @@ func sendWebExtensionMessage(w io.Writer, message []byte) error {
// browser. Wait for the browser to send back a webExtensionRoundTripResponse
// (which actually happens in inFromBrowserLoop--that function uses the ID to
// find this goroutine again). Return a responseSpec object or an error.
-func roundTrip(conn net.Conn, outToBrowserChan chan<- []byte) (responseSpec, error) {
- err := conn.SetReadDeadline(time.Now().Add(localReadTimeout))
- if err != nil {
- return nil, err
- }
- req, err := readRequestSpec(conn)
- if err != nil {
- return nil, err
- }
-
+func roundTrip(req requestSpec, outToBrowserChan chan<- []byte) (responseSpec, error) {
// Generate an ID that will allow us to match a response to this request.
idRaw := make([]byte, 8)
- _, err = rand.Read(idRaw)
+ _, err := rand.Read(idRaw)
if err != nil {
return nil, err
}
@@ -245,7 +236,16 @@ type errorResponseSpec struct {
func handleConn(conn net.Conn, outToBrowserChan chan<- []byte) error {
defer conn.Close()
- resp, err := roundTrip(conn, outToBrowserChan)
+ err := conn.SetReadDeadline(time.Now().Add(localReadTimeout))
+ if err != nil {
+ return err
+ }
+ req, err := readRequestSpec(conn)
+ if err != nil {
+ return err
+ }
+
+ resp, err := roundTrip(req, outToBrowserChan)
if err != nil {
resp = &errorResponseSpec{Error: err.Error()}
}
More information about the tor-commits
mailing list