Repository: VeryGoodOpenSource/dart_frog (dart)

Issue:
feat: expose HttpConnectionInfo
**Description**

As a developer, I want to have easy access to the [`HttpConnectionInfo`](https://api.dart.dev/stable/2.17.6/dart-io/HttpConnectionInfo-class.html) so that I can access the remote address and/or port.

This can be surfaced via the `RequestContext`:

```dart
Response onRequest(RequestContext context) {
  final connectionInfo = context.connectionInfo;
}
```

Pull request description:
<!--
  Thanks for contributing!

  Provide a description of your changes below and a general summary in the title

  Please look at the following checklist to ensure that your PR can be accepted quickly:
-->

## Status

**READY**

## Description

<!--- Describe your changes in detail -->
- feat(dart_frog): expose HttpConnectionInfo on Request (closes #203)

## Type of Change

<!--- Put an `x` in all the boxes that apply: -->

- [X] ✨ New feature (non-breaking change which adds functionality)
- [ ] 🛠️ Bug fix (non-breaking change which fixes an issue)
- [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change)
- [ ] 🧹 Code refactor
- [ ] ✅ Build configuration change
- [ ] 📝 Documentation
- [ ] 🗑️ Chore

Patch:
diff --git a/packages/dart_frog/lib/src/request.dart b/packages/dart_frog/lib/src/request.dart
index 7ab7bc27e..1eba046d0 100644
--- a/packages/dart_frog/lib/src/request.dart
+++ b/packages/dart_frog/lib/src/request.dart
@@ -95,6 +95,11 @@ class Request {
 
   final shelf.Request _request;
 
+  /// Connection information for the associated HTTP request.
+  HttpConnectionInfo get connectionInfo {
+    return _request.context['shelf.io.connection_info']! as HttpConnectionInfo;
+  }
+
   /// The requested url relative to the current handler path.
   Uri get url => _request.url;
 


Test patch:
diff --git a/packages/dart_frog/test/src/serve_test.dart b/packages/dart_frog/test/src/serve_test.dart
index dd80691ac..85ee6a6fe 100644
--- a/packages/dart_frog/test/src/serve_test.dart
+++ b/packages/dart_frog/test/src/serve_test.dart
@@ -25,5 +25,22 @@ void main() {
       expect(response.statusCode, equals(HttpStatus.notFound));
       await server.close();
     });
+
+    test('exposes connectionInfo on the incoming request', () async {
+      late HttpConnectionInfo connectionInfo;
+      final server = await serve(
+        (context) {
+          connectionInfo = context.request.connectionInfo;
+          return Response();
+        },
+        'localhost',
+        3000,
+      );
+      final client = HttpClient();
+      final request = await client.getUrl(Uri.parse('http://localhost:3000'));
+      await request.close();
+      expect(connectionInfo.remoteAddress.address, equals('::1'));
+      await server.close();
+    });
   });
 }