| 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 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 // TODO(kevmoo): use UnmodifiableMapView from SDK once 1.4 ships | 10 // TODO(kevmoo): use UnmodifiableMapView from SDK once 1.4 ships |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 DateTime get ifModifiedSince { | 61 DateTime get ifModifiedSince { |
| 62 if (_ifModifiedSinceCache != null) return _ifModifiedSinceCache; | 62 if (_ifModifiedSinceCache != null) return _ifModifiedSinceCache; |
| 63 if (!headers.containsKey('if-modified-since')) return null; | 63 if (!headers.containsKey('if-modified-since')) return null; |
| 64 _ifModifiedSinceCache = parseHttpDate(headers['if-modified-since']); | 64 _ifModifiedSinceCache = parseHttpDate(headers['if-modified-since']); |
| 65 return _ifModifiedSinceCache; | 65 return _ifModifiedSinceCache; |
| 66 } | 66 } |
| 67 DateTime _ifModifiedSinceCache; | 67 DateTime _ifModifiedSinceCache; |
| 68 | 68 |
| 69 Request(this.pathInfo, String queryString, this.method, | 69 Request(this.pathInfo, String queryString, this.method, |
| 70 this.scriptName, this.protocolVersion, this.requestedUri, | 70 this.scriptName, this.protocolVersion, this.requestedUri, |
| 71 Map<String, String> headers, {Stream<List<int>> body}) | 71 Map<String, String> headers, {Stream<List<int>> body, |
| 72 Map<String, Object> context}) |
| 72 : this.queryString = queryString == null ? '' : queryString, | 73 : this.queryString = queryString == null ? '' : queryString, |
| 73 super(new pc.UnmodifiableMapView(new HashMap.from(headers)), | 74 super(new pc.UnmodifiableMapView(new HashMap.from(headers)), |
| 74 body == null ? new Stream.fromIterable([]) : body) { | 75 body == null ? new Stream.fromIterable([]) : body, |
| 76 new pc.UnmodifiableMapView(new HashMap.from( |
| 77 context != null ? context: {}))) { |
| 75 if (method.isEmpty) throw new ArgumentError('method cannot be empty.'); | 78 if (method.isEmpty) throw new ArgumentError('method cannot be empty.'); |
| 76 | 79 |
| 77 if (scriptName.isNotEmpty && !scriptName.startsWith('/')) { | 80 if (scriptName.isNotEmpty && !scriptName.startsWith('/')) { |
| 78 throw new ArgumentError('scriptName must be empty or start with "/".'); | 81 throw new ArgumentError('scriptName must be empty or start with "/".'); |
| 79 } | 82 } |
| 80 | 83 |
| 81 if (scriptName == '/') { | 84 if (scriptName == '/') { |
| 82 throw new ArgumentError( | 85 throw new ArgumentError( |
| 83 'scriptName can never be "/". It should be empty instead.'); | 86 'scriptName can never be "/". It should be empty instead.'); |
| 84 } | 87 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 99 /// Convenience property to access [pathInfo] data as a [List]. | 102 /// Convenience property to access [pathInfo] data as a [List]. |
| 100 List<String> get pathSegments { | 103 List<String> get pathSegments { |
| 101 var segs = p.url.split(pathInfo); | 104 var segs = p.url.split(pathInfo); |
| 102 if (segs.length > 0) { | 105 if (segs.length > 0) { |
| 103 assert(segs.first == p.url.separator); | 106 assert(segs.first == p.url.separator); |
| 104 segs.removeAt(0); | 107 segs.removeAt(0); |
| 105 } | 108 } |
| 106 return segs; | 109 return segs; |
| 107 } | 110 } |
| 108 } | 111 } |
| OLD | NEW |