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

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: 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
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(method, Uri requestedUri, {String protocolVersion,
nweiz 2014/10/13 18:43:43 Add a type annotation for [method].
kevmoo 2014/10/14 16:42:38 Done.
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 Request._(this.method, Uri requestedUri, {String protocolVersion,
nweiz 2014/10/13 18:43:43 Explain how this constructor is different than [ne
kevmoo 2014/10/14 16:42:38 Done.
120 Map<String, String> headers, Uri url, String scriptName, 129 Map<String, String> headers, Uri url, String scriptName,
121 Stream<List<int>> body, Map<String, Object> context, 130 Stream<List<int>> body, Map<String, Object> context,
122 OnHijackCallback onHijack}) 131 _OnHijack onHijack})
123 : this.requestedUri = requestedUri, 132 : this.requestedUri = requestedUri,
124 this.protocolVersion = protocolVersion == null ? 133 this.protocolVersion = protocolVersion == null ?
125 '1.1' : protocolVersion, 134 '1.1' : protocolVersion,
126 this.url = _computeUrl(requestedUri, url, scriptName), 135 this.url = _computeUrl(requestedUri, url, scriptName),
127 this.scriptName = _computeScriptName(requestedUri, url, scriptName), 136 this.scriptName = _computeScriptName(requestedUri, url, scriptName),
128 this._onHijack = onHijack == null ? null : new _OnHijack(onHijack), 137 this._onHijack = onHijack,
129 super(body == null ? new Stream.fromIterable([]) : body, 138 super(body == null ? new Stream.fromIterable([]) : body,
130 headers: headers, context: context) { 139 headers: headers, context: context) {
131 if (method.isEmpty) throw new ArgumentError('method cannot be empty.'); 140 if (method.isEmpty) throw new ArgumentError('method cannot be empty.');
132 141
133 if (!requestedUri.isAbsolute) { 142 if (!requestedUri.isAbsolute) {
134 throw new ArgumentError('requstedUri must be an absolute URI.'); 143 throw new ArgumentError('requstedUri must be an absolute URI.');
135 } 144 }
136 145
137 // TODO(kevmoo) if defined, check that scriptName is a fully-encoded, valid 146 // TODO(kevmoo) if defined, check that scriptName is a fully-encoded, valid
138 // path component 147 // path component
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 url = new Uri(path: path, query: this.url.query); 196 url = new Uri(path: path, query: this.url.query);
188 } else { 197 } else {
189 throw new ArgumentError('If scriptName is provided without url, it must' 198 throw new ArgumentError('If scriptName is provided without url, it must'
190 ' be a prefix of the existing url path.'); 199 ' be a prefix of the existing url path.');
191 } 200 }
192 } 201 }
193 202
194 if (url == null) url = this.url; 203 if (url == null) url = this.url;
195 if (scriptName == null) scriptName = this.scriptName; 204 if (scriptName == null) scriptName = this.scriptName;
196 205
197 return new Request(this.method, this.requestedUri, 206 return new Request._(this.method, this.requestedUri,
198 protocolVersion: this.protocolVersion, headers: headers, url: url, 207 protocolVersion: this.protocolVersion, headers: headers, url: url,
199 scriptName: scriptName, body: this.read(), context: context); 208 scriptName: scriptName, body: this.read(), context: context,
209 onHijack: _onHijack);
200 } 210 }
201 211
202 /// Takes control of the underlying request socket. 212 /// Takes control of the underlying request socket.
203 /// 213 ///
204 /// Synchronously, this throws a [HijackException] that indicates to the 214 /// Synchronously, this throws a [HijackException] that indicates to the
205 /// adapter that it shouldn't emit a response itself. Asynchronously, 215 /// adapter that it shouldn't emit a response itself. Asynchronously,
206 /// [callback] is called with a [Stream<List<int>>] and 216 /// [callback] is called with a [Stream<List<int>>] and
207 /// [StreamSink<List<int>>], respectively, that provide access to the 217 /// [StreamSink<List<int>>], respectively, that provide access to the
208 /// underlying request socket. 218 /// underlying request socket.
209 /// 219 ///
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 return ''; 289 return '';
280 } 290 }
281 291
282 if (url != null && scriptName != null) { 292 if (url != null && scriptName != null) {
283 return scriptName; 293 return scriptName;
284 } 294 }
285 295
286 throw new ArgumentError( 296 throw new ArgumentError(
287 'url and scriptName must both be null or both be set.'); 297 'url and scriptName must both be null or both be set.');
288 } 298 }
OLDNEW
« pkg/shelf/CHANGELOG.md ('K') | « pkg/shelf/CHANGELOG.md ('k') | pkg/shelf/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698