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

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: 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
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,
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' : protocolVersion,
141 this.url = _computeUrl(requestedUri, url, scriptName), 143 this.url = _computeUrl(requestedUri, url, scriptName),
142 this.scriptName = _computeScriptName(requestedUri, url, scriptName), 144 this.scriptName = _computeScriptName(requestedUri, url, scriptName),
143 this._onHijack = onHijack, 145 this._onHijack = onHijack,
144 super(body == null ? new Stream.fromIterable([]) : body, 146 super(body == null ? new Stream.fromIterable([]) : body,
145 headers: headers, context: context) { 147 headers: headers, context: context) {
146 if (method.isEmpty) throw new ArgumentError('method cannot be empty.'); 148 if (method.isEmpty) throw new ArgumentError('method cannot be empty.');
147 149
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 /// [Request]. 186 /// [Request].
185 /// 187 ///
186 /// All other context and header values from the [Request] will be included 188 /// All other context and header values from the [Request] will be included
187 /// in the copied [Request] unchanged. 189 /// in the copied [Request] unchanged.
188 /// 190 ///
189 /// If [scriptName] is provided and [url] is not, [scriptName] must be a 191 /// 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 192 /// 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 193 /// removed. Useful for routing middleware that sends requests to an inner
192 /// [Handler]. 194 /// [Handler].
193 Request change({Map<String, String> headers, Map<String, Object> context, 195 Request change({Map<String, String> headers, Map<String, Object> context,
194 String scriptName, Uri url}) { 196 String scriptName, Uri url}) {
195 headers = updateMap(this.headers, headers); 197 headers = updateMap(this.headers, headers);
196 context = updateMap(this.context, context); 198 context = updateMap(this.context, context);
197 199
198 if (scriptName != null && url == null) { 200 if (scriptName != null && url == null) {
199 var path = this.url.path; 201 var path = this.url.path;
200 if (path.startsWith(scriptName)) { 202 if (path.startsWith(scriptName)) {
201 path = path.substring(scriptName.length); 203 path = path.substring(scriptName.length);
202 url = new Uri(path: path, query: this.url.query); 204 url = new Uri(path: path, query: this.url.query);
203 } else { 205 } else {
204 throw new ArgumentError('If scriptName is provided without url, it must' 206 throw new ArgumentError('If scriptName is provided without url, it must'
205 ' be a prefix of the existing url path.'); 207 ' be a prefix of the existing url path.');
206 } 208 }
207 } 209 }
208 210
209 if (url == null) url = this.url; 211 if (url == null) url = this.url;
210 if (scriptName == null) scriptName = this.scriptName; 212 if (scriptName == null) scriptName = this.scriptName;
211 213
212 return new Request._(this.method, this.requestedUri, 214 return new Request._(this.method, this.requestedUri,
213 protocolVersion: this.protocolVersion, headers: headers, url: url, 215 protocolVersion: this.protocolVersion,
214 scriptName: scriptName, body: this.read(), context: context, 216 headers: headers,
217 url: url,
218 scriptName: scriptName,
219 body: this.read(),
220 context: context,
215 onHijack: _onHijack); 221 onHijack: _onHijack);
216 } 222 }
217 223
218 /// Takes control of the underlying request socket. 224 /// Takes control of the underlying request socket.
219 /// 225 ///
220 /// Synchronously, this throws a [HijackException] that indicates to the 226 /// Synchronously, this throws a [HijackException] that indicates to the
221 /// adapter that it shouldn't emit a response itself. Asynchronously, 227 /// adapter that it shouldn't emit a response itself. Asynchronously,
222 /// [callback] is called with a [Stream<List<int>>] and 228 /// [callback] is called with a [Stream<List<int>>] and
223 /// [StreamSink<List<int>>], respectively, that provide access to the 229 /// [StreamSink<List<int>>], respectively, that provide access to the
224 /// underlying request socket. 230 /// underlying request socket.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 return ''; 301 return '';
296 } 302 }
297 303
298 if (url != null && scriptName != null) { 304 if (url != null && scriptName != null) {
299 return scriptName; 305 return scriptName;
300 } 306 }
301 307
302 throw new ArgumentError( 308 throw new ArgumentError(
303 'url and scriptName must both be null or both be set.'); 309 'url and scriptName must both be null or both be set.');
304 } 310 }
OLDNEW
« CHANGELOG.md ('K') | « lib/src/middleware.dart ('k') | lib/src/response.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698