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 {
9595
9696 final shelf.Request _request;
9797
98+ /// Connection information for the associated HTTP request.
99+ HttpConnectionInfo get connectionInfo {
100+ return _request.context['shelf.io.connection_info' ]! as HttpConnectionInfo ;
101+ }
102+
98103 /// The requested url relative to the current handler path.
99104 Uri get url => _request.url;
100105
Original file line number Diff line number Diff line change @@ -25,5 +25,22 @@ void main() {
2525 expect (response.statusCode, equals (HttpStatus .notFound));
2626 await server.close ();
2727 });
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+ });
2845 });
2946}
You can’t perform that action at this time.
0 commit comments