Skip to content

Commit

Permalink
Merge pull request #11 from google/consistency
Browse files Browse the repository at this point in the history
Consistency
  • Loading branch information
bramhaghosh committed Jul 9, 2015
2 parents 1626c34 + 2c9e40c commit 8f48754
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 16 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion header/header_modifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion martianurl/url_modifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion martianurl/url_modifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion martianurl/url_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
)

func init() {
parse.Register("martianurl.Verifier", verifierFromJSON)
parse.Register("url.Verifier", verifierFromJSON)
}

// Verifier verifies the structure of URLs.
Expand Down
2 changes: 1 addition & 1 deletion martianurl/url_verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
37 changes: 26 additions & 11 deletions proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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}
}
Expand Down

0 comments on commit 8f48754

Please sign in to comment.