OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library shelf.request; | 5 library shelf.request; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:http_parser/http_parser.dart'; | 9 import 'package:http_parser/http_parser.dart'; |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 /// If [url] and [scriptName] are omitted, they are inferred from | 64 /// If [url] and [scriptName] are omitted, they are inferred from |
65 /// [requestedUri]. | 65 /// [requestedUri]. |
66 /// | 66 /// |
67 /// Setting one of [url] or [scriptName] and not the other will throw an | 67 /// Setting one of [url] or [scriptName] and not the other will throw an |
68 /// [ArgumentError]. | 68 /// [ArgumentError]. |
69 /// | 69 /// |
70 /// The default value for [protocolVersion] is '1.1'. | 70 /// The default value for [protocolVersion] is '1.1'. |
71 // TODO(kevmoo) finish documenting the rest of the arguments. | 71 // TODO(kevmoo) finish documenting the rest of the arguments. |
72 Request(this.method, Uri requestedUri, {String protocolVersion, | 72 Request(this.method, Uri requestedUri, {String protocolVersion, |
73 Map<String, String> headers, Uri url, String scriptName, | 73 Map<String, String> headers, Uri url, String scriptName, |
74 Stream<List<int>> body}) | 74 Stream<List<int>> body, Map<String, Object> context}) |
75 : this.requestedUri = requestedUri, | 75 : this.requestedUri = requestedUri, |
76 this.protocolVersion = protocolVersion == null ? | 76 this.protocolVersion = protocolVersion == null ? |
77 '1.1' : protocolVersion, | 77 '1.1' : protocolVersion, |
78 this.url = _computeUrl(requestedUri, url, scriptName), | 78 this.url = _computeUrl(requestedUri, url, scriptName), |
79 this.scriptName = _computeScriptName(requestedUri, url, scriptName), | 79 this.scriptName = _computeScriptName(requestedUri, url, scriptName), |
80 super(body == null ? new Stream.fromIterable([]) : body, | 80 super(body == null ? new Stream.fromIterable([]) : body, |
81 headers: headers) { | 81 headers: headers, context: context) { |
82 if (method.isEmpty) throw new ArgumentError('method cannot be empty.'); | 82 if (method.isEmpty) throw new ArgumentError('method cannot be empty.'); |
83 | 83 |
84 // TODO(kevmoo) use isAbsolute property on Uri once Issue 18053 is fixed | 84 // TODO(kevmoo) use isAbsolute property on Uri once Issue 18053 is fixed |
85 if (requestedUri.scheme.isEmpty) { | 85 if (requestedUri.scheme.isEmpty) { |
86 throw new ArgumentError('requstedUri must be an absolute URI.'); | 86 throw new ArgumentError('requstedUri must be an absolute URI.'); |
87 } | 87 } |
88 | 88 |
89 if (this.scriptName.isNotEmpty && !this.scriptName.startsWith('/')) { | 89 if (this.scriptName.isNotEmpty && !this.scriptName.startsWith('/')) { |
90 throw new ArgumentError('scriptName must be empty or start with "/".'); | 90 throw new ArgumentError('scriptName must be empty or start with "/".'); |
91 } | 91 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 return ''; | 144 return ''; |
145 } | 145 } |
146 | 146 |
147 if (url != null && scriptName != null) { | 147 if (url != null && scriptName != null) { |
148 return scriptName; | 148 return scriptName; |
149 } | 149 } |
150 | 150 |
151 throw new ArgumentError( | 151 throw new ArgumentError( |
152 'url and scriptName must both be null or both be set.'); | 152 'url and scriptName must both be null or both be set.'); |
153 } | 153 } |
OLD | NEW |