Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(510)

Side by Side Diff: lib/src/request.dart

Issue 837193005: pkg/shelf: formatted code (Closed) Base URL: https://github.com/dart-lang/shelf.git@master
Patch Set: nits Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/middleware.dart ('k') | lib/src/response.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 /// An adapter can check whether a request was hijacked using [canHijack], 112 /// An adapter can check whether a request was hijacked using [canHijack],
113 /// which will be `false` for a hijacked request. The adapter may throw an 113 /// which will be `false` for a hijacked request. The adapter may throw an
114 /// error if a [HijackException] is received for a non-hijacked request, or if 114 /// error if a [HijackException] is received for a non-hijacked request, or if
115 /// no [HijackException] is received for a hijacked request. 115 /// no [HijackException] is received for a hijacked request.
116 /// 116 ///
117 /// See also [hijack]. 117 /// See also [hijack].
118 // TODO(kevmoo) finish documenting the rest of the arguments. 118 // TODO(kevmoo) finish documenting the rest of the arguments.
119 Request(String method, Uri requestedUri, {String protocolVersion, 119 Request(String method, Uri requestedUri, {String protocolVersion,
120 Map<String, String> headers, Uri url, String scriptName, 120 Map<String, String> headers, Uri url, String scriptName,
121 Stream<List<int>> body, Map<String, Object> context, 121 Stream<List<int>> body, Map<String, Object> context,
122 OnHijackCallback onHijack}) 122 OnHijackCallback onHijack}) : this._(method, requestedUri,
nweiz 2015/01/20 23:20:31 Putting ": this()" on the same line as the paramet
kevmoo 2015/01/21 00:50:18 Done https://github.com/dart-lang/dart_style/issue
123 : this._(method, requestedUri, protocolVersion: protocolVersion, 123 protocolVersion: protocolVersion,
124 headers: headers, url: url, scriptName: scriptName, 124 headers: headers,
125 body: body, context: context, 125 url: url,
126 onHijack: onHijack == null ? null : new _OnHijack(onHijack)); 126 scriptName: scriptName,
127 body: body,
128 context: context,
129 onHijack: onHijack == null ? null : new _OnHijack(onHijack));
127 130
128 /// This constructor has the same signature as [new Request] except that 131 /// This constructor has the same signature as [new Request] except that
129 /// accepts [onHijack] as [_OnHijack]. 132 /// accepts [onHijack] as [_OnHijack].
130 /// 133 ///
131 /// Any [Request] created by calling [change] will pass [_onHijack] from the 134 /// Any [Request] created by calling [change] will pass [_onHijack] from the
132 /// source [Request] to ensure that [hijack] can only be called once, even 135 /// source [Request] to ensure that [hijack] can only be called once, even
133 /// from a changed [Request]. 136 /// from a changed [Request].
134 Request._(this.method, Uri requestedUri, {String protocolVersion, 137 Request._(this.method, Uri requestedUri, {String protocolVersion,
135 Map<String, String> headers, Uri url, String scriptName, 138 Map<String, String> headers, Uri url, String scriptName,
136 Stream<List<int>> body, Map<String, Object> context, 139 Stream<List<int>> body, Map<String, Object> context, _OnHijack onHijack})
137 _OnHijack onHijack})
138 : this.requestedUri = requestedUri, 140 : this.requestedUri = requestedUri,
139 this.protocolVersion = protocolVersion == null ? 141 this.protocolVersion = protocolVersion == null
140 '1.1' : protocolVersion, 142 ? '1.1'
143 : protocolVersion,
141 this.url = _computeUrl(requestedUri, url, scriptName), 144 this.url = _computeUrl(requestedUri, url, scriptName),
142 this.scriptName = _computeScriptName(requestedUri, url, scriptName), 145 this.scriptName = _computeScriptName(requestedUri, url, scriptName),
143 this._onHijack = onHijack, 146 this._onHijack = onHijack,
144 super(body == null ? new Stream.fromIterable([]) : body, 147 super(body == null ? new Stream.fromIterable([]) : body,
145 headers: headers, context: context) { 148 headers: headers, context: context) {
146 if (method.isEmpty) throw new ArgumentError('method cannot be empty.'); 149 if (method.isEmpty) throw new ArgumentError('method cannot be empty.');
147 150
148 if (!requestedUri.isAbsolute) { 151 if (!requestedUri.isAbsolute) {
149 throw new ArgumentError('requstedUri must be an absolute URI.'); 152 throw new ArgumentError('requstedUri must be an absolute URI.');
150 } 153 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 /// [Request]. 187 /// [Request].
185 /// 188 ///
186 /// All other context and header values from the [Request] will be included 189 /// All other context and header values from the [Request] will be included
187 /// in the copied [Request] unchanged. 190 /// in the copied [Request] unchanged.
188 /// 191 ///
189 /// If [scriptName] is provided and [url] is not, [scriptName] must be a 192 /// If [scriptName] is provided and [url] is not, [scriptName] must be a
190 /// prefix of [this.url]. [url] will default to [this.url] with this prefix 193 /// prefix of [this.url]. [url] will default to [this.url] with this prefix
191 /// removed. Useful for routing middleware that sends requests to an inner 194 /// removed. Useful for routing middleware that sends requests to an inner
192 /// [Handler]. 195 /// [Handler].
193 Request change({Map<String, String> headers, Map<String, Object> context, 196 Request change({Map<String, String> headers, Map<String, Object> context,
194 String scriptName, Uri url}) { 197 String scriptName, Uri url}) {
195 headers = updateMap(this.headers, headers); 198 headers = updateMap(this.headers, headers);
196 context = updateMap(this.context, context); 199 context = updateMap(this.context, context);
197 200
198 if (scriptName != null && url == null) { 201 if (scriptName != null && url == null) {
199 var path = this.url.path; 202 var path = this.url.path;
200 if (path.startsWith(scriptName)) { 203 if (path.startsWith(scriptName)) {
201 path = path.substring(scriptName.length); 204 path = path.substring(scriptName.length);
202 url = new Uri(path: path, query: this.url.query); 205 url = new Uri(path: path, query: this.url.query);
203 } else { 206 } else {
204 throw new ArgumentError('If scriptName is provided without url, it must' 207 throw new ArgumentError('If scriptName is provided without url, it must'
205 ' be a prefix of the existing url path.'); 208 ' be a prefix of the existing url path.');
206 } 209 }
207 } 210 }
208 211
209 if (url == null) url = this.url; 212 if (url == null) url = this.url;
210 if (scriptName == null) scriptName = this.scriptName; 213 if (scriptName == null) scriptName = this.scriptName;
211 214
212 return new Request._(this.method, this.requestedUri, 215 return new Request._(this.method, this.requestedUri,
213 protocolVersion: this.protocolVersion, headers: headers, url: url, 216 protocolVersion: this.protocolVersion,
214 scriptName: scriptName, body: this.read(), context: context, 217 headers: headers,
218 url: url,
219 scriptName: scriptName,
220 body: this.read(),
221 context: context,
215 onHijack: _onHijack); 222 onHijack: _onHijack);
216 } 223 }
217 224
218 /// Takes control of the underlying request socket. 225 /// Takes control of the underlying request socket.
219 /// 226 ///
220 /// Synchronously, this throws a [HijackException] that indicates to the 227 /// Synchronously, this throws a [HijackException] that indicates to the
221 /// adapter that it shouldn't emit a response itself. Asynchronously, 228 /// adapter that it shouldn't emit a response itself. Asynchronously,
222 /// [callback] is called with a [Stream<List<int>>] and 229 /// [callback] is called with a [Stream<List<int>>] and
223 /// [StreamSink<List<int>>], respectively, that provide access to the 230 /// [StreamSink<List<int>>], respectively, that provide access to the
224 /// underlying request socket. 231 /// underlying request socket.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 return ''; 302 return '';
296 } 303 }
297 304
298 if (url != null && scriptName != null) { 305 if (url != null && scriptName != null) {
299 return scriptName; 306 return scriptName;
300 } 307 }
301 308
302 throw new ArgumentError( 309 throw new ArgumentError(
303 'url and scriptName must both be null or both be set.'); 310 'url and scriptName must both be null or both be set.');
304 } 311 }
OLDNEW
« no previous file with comments | « lib/src/middleware.dart ('k') | lib/src/response.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698