From 985fd319035c6f1ba76c6a5f0f5276bfb436eea4 Mon Sep 17 00:00:00 2001 From: Adam Tanner Date: Wed, 8 Jul 2015 11:01:07 -0700 Subject: [PATCH 1/4] header_modifier_test: "type" to "scope" in FromJSON test. --- header/header_modifier_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/header/header_modifier_test.go b/header/header_modifier_test.go index a802d40d0..8398ad0ec 100644 --- a/header/header_modifier_test.go +++ b/header/header_modifier_test.go @@ -66,7 +66,7 @@ func TestModifyRequestWithHostHeader(t *testing.T) { func TestModifierFromJSON(t *testing.T) { msg := []byte(`{ "header.Modifier": { - "type": ["request", "response"], + "scope": ["request", "response"], "name": "X-Martian", "value": "true" } From bc74dcf668640eea50f97eec64b4fdbd9c31139f Mon Sep 17 00:00:00 2001 From: Adam Tanner Date: Wed, 8 Jul 2015 11:10:04 -0700 Subject: [PATCH 2/4] auth: Move auth{,_test}.go to auth_filter{,_test}.go. --- auth/{auth.go => auth_filter.go} | 0 auth/{auth_test.go => auth_filter_test.go} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename auth/{auth.go => auth_filter.go} (100%) rename auth/{auth_test.go => auth_filter_test.go} (100%) diff --git a/auth/auth.go b/auth/auth_filter.go similarity index 100% rename from auth/auth.go rename to auth/auth_filter.go diff --git a/auth/auth_test.go b/auth/auth_filter_test.go similarity index 100% rename from auth/auth_test.go rename to auth/auth_filter_test.go From b7b16413bd87e24c0c26f00c5977f9ddc8d92e13 Mon Sep 17 00:00:00 2001 From: Adam Tanner Date: Wed, 8 Jul 2015 11:13:24 -0700 Subject: [PATCH 3/4] [BREAKING] Unify on "url" over "martianurl" for JSON. --- martianurl/url_modifier.go | 2 +- martianurl/url_modifier_test.go | 2 +- martianurl/url_verifier.go | 2 +- martianurl/url_verifier_test.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/martianurl/url_modifier.go b/martianurl/url_modifier.go index 4befdcb65..87d3dbd35 100644 --- a/martianurl/url_modifier.go +++ b/martianurl/url_modifier.go @@ -40,7 +40,7 @@ type modifierJSON struct { } func init() { - parse.Register("martianurl.Modifier", modifierFromJSON) + parse.Register("url.Modifier", modifierFromJSON) } // ModifyRequest sets the fields of req.URL to m.Url if they are not the zero value. diff --git a/martianurl/url_modifier_test.go b/martianurl/url_modifier_test.go index 2e572b8f0..2e8f3c224 100644 --- a/martianurl/url_modifier_test.go +++ b/martianurl/url_modifier_test.go @@ -116,7 +116,7 @@ func TestIntegration(t *testing.T) { func TestModifierFromJSON(t *testing.T) { msg := []byte(`{ - "martianurl.Modifier": { + "url.Modifier": { "scope": ["request"], "scheme": "https", "host": "www.martian.proxy", diff --git a/martianurl/url_verifier.go b/martianurl/url_verifier.go index 2abf3b516..8ddcbdd73 100644 --- a/martianurl/url_verifier.go +++ b/martianurl/url_verifier.go @@ -32,7 +32,7 @@ const ( ) func init() { - parse.Register("martianurl.Verifier", verifierFromJSON) + parse.Register("url.Verifier", verifierFromJSON) } // Verifier verifies the structure of URLs. diff --git a/martianurl/url_verifier_test.go b/martianurl/url_verifier_test.go index a87ba47c7..42cd00d43 100644 --- a/martianurl/url_verifier_test.go +++ b/martianurl/url_verifier_test.go @@ -118,7 +118,7 @@ func TestVerifyRequests(t *testing.T) { func TestVerifierFromJSON(t *testing.T) { msg := []byte(`{ - "martianurl.Verifier": { + "url.Verifier": { "scope": ["request"], "scheme": "https", "host": "www.martian.proxy", From 2c9e40c893dec9e5304381fac5592f222f43dd17 Mon Sep 17 00:00:00 2001 From: Adam Tanner Date: Wed, 8 Jul 2015 11:27:01 -0700 Subject: [PATCH 4/4] proxy_test: fix -race condition with timeout pipe. --- proxy_test.go | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/proxy_test.go b/proxy_test.go index 6627d9007..277ac87a2 100644 --- a/proxy_test.go +++ b/proxy_test.go @@ -159,12 +159,20 @@ func (p *timeoutPipe) SetWriteDeadline(t time.Time) error { return nil } -func (p *timeoutPipe) Read(b []byte) (n int, err error) { - rc := make(chan bool, 1) +func (p *timeoutPipe) Read(b []byte) (int, error) { + type connRead struct { + n int + err error + } + + rc := make(chan connRead, 1) go func() { - n, err = p.Conn.Read(b) - rc <- true + n, err := p.Conn.Read(b) + rc <- connRead{ + n: n, + err: err, + } }() d := p.readTimeout.Sub(time.Now()) @@ -173,19 +181,26 @@ func (p *timeoutPipe) Read(b []byte) (n int, err error) { } select { - case <-rc: - return n, err + case cr := <-rc: + return cr.n, cr.err case <-time.After(d): return 0, &pipeNetError{true, false} } } func (p *timeoutPipe) Write(b []byte) (n int, err error) { - wc := make(chan bool, 1) + type connWrite struct { + n int + err error + } + wc := make(chan connWrite, 1) go func() { - n, err = p.Conn.Write(b) - wc <- true + n, err := p.Conn.Write(b) + wc <- connWrite{ + n: n, + err: err, + } }() d := p.writeTimeout.Sub(time.Now()) @@ -194,8 +209,8 @@ func (p *timeoutPipe) Write(b []byte) (n int, err error) { } select { - case <-wc: - return n, err + case cw := <-wc: + return cw.n, cw.err case <-time.After(d): return 0, &pipeNetError{true, false} }