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

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

Issue 616463004: pkg/shelf: include the original `onHijack` callback for Request.change (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: cl nits Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « pkg/shelf/CHANGELOG.md ('k') | pkg/shelf/pubspec.yaml » ('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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 /// sending a response or notifying the user of an error if a 109 /// sending a response or notifying the user of an error if a
110 /// [HijackException] is caught. 110 /// [HijackException] is caught.
111 /// 111 ///
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(this.method, Uri requestedUri, {String protocolVersion, 119 Request(String method, Uri requestedUri, {String protocolVersion,
120 Map<String, String> headers, Uri url, String scriptName,
121 Stream<List<int>> body, Map<String, Object> context,
122 OnHijackCallback onHijack})
123 : this._(method, requestedUri, protocolVersion: protocolVersion,
124 headers: headers, url: url, scriptName: scriptName,
125 body: body, context: context,
126 onHijack: onHijack == null ? null : new _OnHijack(onHijack));
127
128 /// This constructor has the same signature as [new Request] except that
129 /// accepts [onHijack] as [_OnHijack].
130 ///
131 /// Any [Request] created by calling [change] will pass [_onHijack] from the
132 /// source [Request] to ensure that [hijack] can only be called once, even
133 /// from a changed [Request].
134 Request._(this.method, Uri requestedUri, {String protocolVersion,
120 Map<String, String> headers, Uri url, String scriptName, 135 Map<String, String> headers, Uri url, String scriptName,
121 Stream<List<int>> body, Map<String, Object> context, 136 Stream<List<int>> body, Map<String, Object> context,
122 OnHijackCallback onHijack}) 137 _OnHijack onHijack})
123 : this.requestedUri = requestedUri, 138 : this.requestedUri = requestedUri,
124 this.protocolVersion = protocolVersion == null ? 139 this.protocolVersion = protocolVersion == null ?
125 '1.1' : protocolVersion, 140 '1.1' : protocolVersion,
126 this.url = _computeUrl(requestedUri, url, scriptName), 141 this.url = _computeUrl(requestedUri, url, scriptName),
127 this.scriptName = _computeScriptName(requestedUri, url, scriptName), 142 this.scriptName = _computeScriptName(requestedUri, url, scriptName),
128 this._onHijack = onHijack == null ? null : new _OnHijack(onHijack), 143 this._onHijack = onHijack,
129 super(body == null ? new Stream.fromIterable([]) : body, 144 super(body == null ? new Stream.fromIterable([]) : body,
130 headers: headers, context: context) { 145 headers: headers, context: context) {
131 if (method.isEmpty) throw new ArgumentError('method cannot be empty.'); 146 if (method.isEmpty) throw new ArgumentError('method cannot be empty.');
132 147
133 if (!requestedUri.isAbsolute) { 148 if (!requestedUri.isAbsolute) {
134 throw new ArgumentError('requstedUri must be an absolute URI.'); 149 throw new ArgumentError('requstedUri must be an absolute URI.');
135 } 150 }
136 151
137 // TODO(kevmoo) if defined, check that scriptName is a fully-encoded, valid 152 // TODO(kevmoo) if defined, check that scriptName is a fully-encoded, valid
138 // path component 153 // path component
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 url = new Uri(path: path, query: this.url.query); 202 url = new Uri(path: path, query: this.url.query);
188 } else { 203 } else {
189 throw new ArgumentError('If scriptName is provided without url, it must' 204 throw new ArgumentError('If scriptName is provided without url, it must'
190 ' be a prefix of the existing url path.'); 205 ' be a prefix of the existing url path.');
191 } 206 }
192 } 207 }
193 208
194 if (url == null) url = this.url; 209 if (url == null) url = this.url;
195 if (scriptName == null) scriptName = this.scriptName; 210 if (scriptName == null) scriptName = this.scriptName;
196 211
197 return new Request(this.method, this.requestedUri, 212 return new Request._(this.method, this.requestedUri,
198 protocolVersion: this.protocolVersion, headers: headers, url: url, 213 protocolVersion: this.protocolVersion, headers: headers, url: url,
199 scriptName: scriptName, body: this.read(), context: context); 214 scriptName: scriptName, body: this.read(), context: context,
215 onHijack: _onHijack);
200 } 216 }
201 217
202 /// Takes control of the underlying request socket. 218 /// Takes control of the underlying request socket.
203 /// 219 ///
204 /// Synchronously, this throws a [HijackException] that indicates to the 220 /// Synchronously, this throws a [HijackException] that indicates to the
205 /// adapter that it shouldn't emit a response itself. Asynchronously, 221 /// adapter that it shouldn't emit a response itself. Asynchronously,
206 /// [callback] is called with a [Stream<List<int>>] and 222 /// [callback] is called with a [Stream<List<int>>] and
207 /// [StreamSink<List<int>>], respectively, that provide access to the 223 /// [StreamSink<List<int>>], respectively, that provide access to the
208 /// underlying request socket. 224 /// underlying request socket.
209 /// 225 ///
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 return ''; 295 return '';
280 } 296 }
281 297
282 if (url != null && scriptName != null) { 298 if (url != null && scriptName != null) {
283 return scriptName; 299 return scriptName;
284 } 300 }
285 301
286 throw new ArgumentError( 302 throw new ArgumentError(
287 'url and scriptName must both be null or both be set.'); 303 'url and scriptName must both be null or both be set.');
288 } 304 }
OLDNEW
« no previous file with comments | « pkg/shelf/CHANGELOG.md ('k') | pkg/shelf/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698