Created
June 12, 2019 16:13
-
-
Save hayabusabusa/6ab237e4768a0a068ff5f0816f0cbfe8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// HttpRequest: | |
/// Dart の基本の Request クラスを HttpRequestProtocol で拡張したもの | |
class HttpRequest extends Request { | |
final HttpRequestProtocol service; | |
HttpRequest(this.service) | |
: super( | |
service.method.value, | |
Uri.parse('${service.baseUrl}${service.path}${service.queryParameters}') | |
); | |
@override | |
Map<String, String> get headers => this.service.headers; | |
@override | |
String get body => json.encode(this.service.parameters); | |
@override | |
Uint8List get bodyBytes { | |
if (service.contentEncoding == ContentEncoding.url) { | |
final queryParameters = Uri(queryParameters: service.parameters); | |
List<int> bodyBytes = utf8.encode(queryParameters.query); | |
return bodyBytes; | |
} else { | |
final encodedBody = Utf8Codec().encode(body); | |
return Uint8List.fromList(encodedBody); | |
} | |
} | |
@override | |
MediaType get _contentType { | |
var contentType = headers['content-type']; | |
if (contentType == null) return null; | |
return new MediaType.parse(contentType); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment