Completely remove RequestContext.io
This commit is contained in:
parent
ffbbb75c8c
commit
697a1a788f
2 changed files with 25 additions and 18 deletions
|
@ -17,4 +17,6 @@ single type argument to determine how to parse a value.
|
||||||
* In addition, this method was also made `static`.
|
* In addition, this method was also made `static`.
|
||||||
* `RequestContext` and `ResponseContext` are now generic, and take a
|
* `RequestContext` and `ResponseContext` are now generic, and take a
|
||||||
single type argument pointing to the underlying request/response type,
|
single type argument pointing to the underlying request/response type,
|
||||||
respectively.
|
respectively.
|
||||||
|
* `RequestContext.io` and `ResponseContext.io` are now permanently
|
||||||
|
gone.
|
|
@ -1,37 +1,39 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:body_parser/body_parser.dart';
|
import 'package:body_parser/body_parser.dart';
|
||||||
import 'package:http_parser/http_parser.dart';
|
import 'package:http_parser/http_parser.dart';
|
||||||
|
|
||||||
import '../core/core.dart';
|
import '../core/core.dart';
|
||||||
|
|
||||||
/// An implementation of [RequestContext] that wraps a [HttpRequest].
|
/// An implementation of [RequestContext] that wraps a [HttpRequest].
|
||||||
class HttpRequestContextImpl extends RequestContext {
|
class HttpRequestContextImpl extends RequestContext<HttpRequest> {
|
||||||
ContentType _contentType;
|
MediaType _contentType;
|
||||||
HttpRequest _io;
|
HttpRequest _io;
|
||||||
String _override, _path;
|
String _override, _path;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ContentType get contentType {
|
MediaType get contentType {
|
||||||
return _contentType;
|
return _contentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Cookie> get cookies {
|
List<Cookie> get cookies {
|
||||||
return io.cookies;
|
return rawRequest.cookies;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
HttpHeaders get headers {
|
HttpHeaders get headers {
|
||||||
return io.headers;
|
return rawRequest.headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get hostname {
|
String get hostname {
|
||||||
return io.headers.value('host');
|
return rawRequest.headers.value('host');
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The underlying [HttpRequest] instance underneath this context.
|
/// The underlying [HttpRequest] instance underneath this context.
|
||||||
HttpRequest get io => _io;
|
HttpRequest get rawRequest => _io;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get method {
|
String get method {
|
||||||
|
@ -40,7 +42,7 @@ class HttpRequestContextImpl extends RequestContext {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get originalMethod {
|
String get originalMethod {
|
||||||
return io.method;
|
return rawRequest.method;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -50,22 +52,25 @@ class HttpRequestContextImpl extends RequestContext {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InternetAddress get remoteAddress {
|
InternetAddress get remoteAddress {
|
||||||
return io.connectionInfo.remoteAddress;
|
return rawRequest.connectionInfo.remoteAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
HttpSession get session {
|
HttpSession get session {
|
||||||
return io.session;
|
return rawRequest.session;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Uri get uri {
|
Uri get uri {
|
||||||
return io.uri;
|
return rawRequest.uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get xhr {
|
bool get xhr {
|
||||||
return io.headers.value("X-Requested-With")?.trim()?.toLowerCase() ==
|
return rawRequest.headers
|
||||||
|
.value("X-Requested-With")
|
||||||
|
?.trim()
|
||||||
|
?.toLowerCase() ==
|
||||||
'xmlhttprequest';
|
'xmlhttprequest';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +87,7 @@ class HttpRequestContextImpl extends RequestContext {
|
||||||
request.method;
|
request.method;
|
||||||
|
|
||||||
ctx.app = app;
|
ctx.app = app;
|
||||||
ctx._contentType = request.headers.contentType;
|
ctx._contentType = MediaType.parse(request.headers.contentType.toString());
|
||||||
ctx._override = override;
|
ctx._override = override;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -134,11 +139,11 @@ class HttpRequestContextImpl extends RequestContext {
|
||||||
@override
|
@override
|
||||||
Future<BodyParseResult> parseOnce() {
|
Future<BodyParseResult> parseOnce() {
|
||||||
return parseBodyFromStream(
|
return parseBodyFromStream(
|
||||||
io,
|
rawRequest,
|
||||||
io.headers.contentType != null
|
rawRequest.headers.contentType != null
|
||||||
? new MediaType.parse(io.headers.contentType.toString())
|
? new MediaType.parse(rawRequest.headers.contentType.toString())
|
||||||
: null,
|
: null,
|
||||||
io.uri,
|
rawRequest.uri,
|
||||||
storeOriginalBuffer: app.storeOriginalBuffer == true);
|
storeOriginalBuffer: app.storeOriginalBuffer == true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue