From 697a1a788f15d5130902e542f12342f98cc1f9d6 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sun, 19 Aug 2018 23:31:59 -0400 Subject: [PATCH] Completely remove RequestContext.io --- CHANGELOG.md | 4 ++- lib/src/http/http_request_context.dart | 39 +++++++++++++++----------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ce3e9fa..12c111de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,4 +17,6 @@ single type argument to determine how to parse a value. * In addition, this method was also made `static`. * `RequestContext` and `ResponseContext` are now generic, and take a single type argument pointing to the underlying request/response type, -respectively. \ No newline at end of file +respectively. +* `RequestContext.io` and `ResponseContext.io` are now permanently +gone. \ No newline at end of file diff --git a/lib/src/http/http_request_context.dart b/lib/src/http/http_request_context.dart index 5de674e2..aad06e20 100644 --- a/lib/src/http/http_request_context.dart +++ b/lib/src/http/http_request_context.dart @@ -1,37 +1,39 @@ import 'dart:async'; import 'dart:io'; + import 'package:body_parser/body_parser.dart'; import 'package:http_parser/http_parser.dart'; + import '../core/core.dart'; /// An implementation of [RequestContext] that wraps a [HttpRequest]. -class HttpRequestContextImpl extends RequestContext { - ContentType _contentType; +class HttpRequestContextImpl extends RequestContext { + MediaType _contentType; HttpRequest _io; String _override, _path; @override - ContentType get contentType { + MediaType get contentType { return _contentType; } @override List get cookies { - return io.cookies; + return rawRequest.cookies; } @override HttpHeaders get headers { - return io.headers; + return rawRequest.headers; } @override String get hostname { - return io.headers.value('host'); + return rawRequest.headers.value('host'); } /// The underlying [HttpRequest] instance underneath this context. - HttpRequest get io => _io; + HttpRequest get rawRequest => _io; @override String get method { @@ -40,7 +42,7 @@ class HttpRequestContextImpl extends RequestContext { @override String get originalMethod { - return io.method; + return rawRequest.method; } @override @@ -50,22 +52,25 @@ class HttpRequestContextImpl extends RequestContext { @override InternetAddress get remoteAddress { - return io.connectionInfo.remoteAddress; + return rawRequest.connectionInfo.remoteAddress; } @override HttpSession get session { - return io.session; + return rawRequest.session; } @override Uri get uri { - return io.uri; + return rawRequest.uri; } @override bool get xhr { - return io.headers.value("X-Requested-With")?.trim()?.toLowerCase() == + return rawRequest.headers + .value("X-Requested-With") + ?.trim() + ?.toLowerCase() == 'xmlhttprequest'; } @@ -82,7 +87,7 @@ class HttpRequestContextImpl extends RequestContext { request.method; ctx.app = app; - ctx._contentType = request.headers.contentType; + ctx._contentType = MediaType.parse(request.headers.contentType.toString()); ctx._override = override; /* @@ -134,11 +139,11 @@ class HttpRequestContextImpl extends RequestContext { @override Future parseOnce() { return parseBodyFromStream( - io, - io.headers.contentType != null - ? new MediaType.parse(io.headers.contentType.toString()) + rawRequest, + rawRequest.headers.contentType != null + ? new MediaType.parse(rawRequest.headers.contentType.toString()) : null, - io.uri, + rawRequest.uri, storeOriginalBuffer: app.storeOriginalBuffer == true); } }