File tree 4 files changed +15
-11
lines changed
4 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -151,7 +151,7 @@ func TestDialWithRemoteAddr(t *testing.T) {
151
151
return
152
152
}
153
153
154
- _ , err = c .Write ([]byte ("Response" ))
154
+ _ , err = c .Write ([]byte (c . RemoteAddr (). String () ))
155
155
common .Must (err )
156
156
}(conn )
157
157
})
@@ -169,7 +169,7 @@ func TestDialWithRemoteAddr(t *testing.T) {
169
169
var b [1024 ]byte
170
170
n , err := conn .Read (b [:])
171
171
common .Must (err )
172
- if string (b [:n ]) != "Response " {
172
+ if string (b [:n ]) != "1.1.1.1:0 " {
173
173
t .Error ("response: " , string (b [:n ]))
174
174
}
175
175
Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ func TestDialWithRemoteAddr(t *testing.T) {
96
96
return
97
97
}
98
98
99
- _ , err = c .Write ([]byte ("Response" ))
99
+ _ , err = c .Write ([]byte (c . RemoteAddr (). String () ))
100
100
common .Must (err )
101
101
}(conn )
102
102
})
@@ -113,7 +113,7 @@ func TestDialWithRemoteAddr(t *testing.T) {
113
113
114
114
var b [1024 ]byte
115
115
n , _ := conn .Read (b [:])
116
- if string (b [:n ]) != "Response " {
116
+ if string (b [:n ]) != "1.1.1.1:0 " {
117
117
t .Error ("response: " , string (b [:n ]))
118
118
}
119
119
Original file line number Diff line number Diff line change @@ -14,15 +14,19 @@ import (
14
14
var _ buf.Writer = (* connection )(nil )
15
15
16
16
// connection is a wrapper for net.Conn over WebSocket connection.
17
+ // remoteAddr is used to pass "virtual" remote IP addresses in X-Forwarded-For.
18
+ // so we shouldn't directly read it form conn.
17
19
type connection struct {
18
- conn * websocket.Conn
19
- reader io.Reader
20
+ conn * websocket.Conn
21
+ reader io.Reader
22
+ remoteAddr net.Addr
20
23
}
21
24
22
25
func NewConnection (conn * websocket.Conn , remoteAddr net.Addr , extraReader io.Reader ) * connection {
23
26
return & connection {
24
- conn : conn ,
25
- reader : extraReader ,
27
+ conn : conn ,
28
+ remoteAddr : remoteAddr ,
29
+ reader : extraReader ,
26
30
}
27
31
}
28
32
@@ -90,7 +94,7 @@ func (c *connection) LocalAddr() net.Addr {
90
94
}
91
95
92
96
func (c * connection ) RemoteAddr () net.Addr {
93
- return c .conn . RemoteAddr ()
97
+ return c .remoteAddr
94
98
}
95
99
96
100
func (c * connection ) SetDeadline (t time.Time ) error {
Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ func TestDialWithRemoteAddr(t *testing.T) {
91
91
return
92
92
}
93
93
94
- _ , err = c .Write ([]byte ("Response" ))
94
+ _ , err = c .Write ([]byte (c . RemoteAddr (). String () ))
95
95
common .Must (err )
96
96
}(conn )
97
97
})
@@ -109,7 +109,7 @@ func TestDialWithRemoteAddr(t *testing.T) {
109
109
var b [1024 ]byte
110
110
n , err := conn .Read (b [:])
111
111
common .Must (err )
112
- if string (b [:n ]) != "Response " {
112
+ if string (b [:n ]) != "1.1.1.1:0 " {
113
113
t .Error ("response: " , string (b [:n ]))
114
114
}
115
115
You can’t perform that action at this time.
0 commit comments