File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,11 @@ class Request {
95
95
96
96
final shelf.Request _request;
97
97
98
+ /// Connection information for the associated HTTP request.
99
+ HttpConnectionInfo get connectionInfo {
100
+ return _request.context['shelf.io.connection_info' ]! as HttpConnectionInfo ;
101
+ }
102
+
98
103
/// The requested url relative to the current handler path.
99
104
Uri get url => _request.url;
100
105
Original file line number Diff line number Diff line change @@ -25,5 +25,22 @@ void main() {
25
25
expect (response.statusCode, equals (HttpStatus .notFound));
26
26
await server.close ();
27
27
});
28
+
29
+ test ('exposes connectionInfo on the incoming request' , () async {
30
+ late HttpConnectionInfo connectionInfo;
31
+ final server = await serve (
32
+ (context) {
33
+ connectionInfo = context.request.connectionInfo;
34
+ return Response ();
35
+ },
36
+ 'localhost' ,
37
+ 3000 ,
38
+ );
39
+ final client = HttpClient ();
40
+ final request = await client.getUrl (Uri .parse ('http://localhost:3000' ));
41
+ await request.close ();
42
+ expect (connectionInfo.remoteAddress.address, equals ('::1' ));
43
+ await server.close ();
44
+ });
28
45
});
29
46
}
You can’t perform that action at this time.
0 commit comments