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

Side by Side Diff: pkg/http_server/test/http_mock.dart

Issue 721213002: Fix a number of issues with the Range header handling for serving files (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 6 years, 1 month 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/http_server/pubspec.yaml ('k') | pkg/http_server/test/utils.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 library http_mock; 1 library http_mock;
2 2
3 import 'dart:async'; 3 import 'dart:async';
4 import 'dart:collection'; 4 import 'dart:collection';
5 import 'dart:convert'; 5 import 'dart:convert';
6 import 'dart:io'; 6 import 'dart:io';
7 7
8 class MockHttpHeaders implements HttpHeaders { 8 class MockHttpHeaders implements HttpHeaders {
9 final Map<String, List<String>> _headers = 9 final Map<String, List<String>> _headers =
10 new HashMap<String, List<String>>(); 10 new HashMap<String, List<String>>();
11 11
12 operator[](key) => _headers[key];
13
14 int get contentLength => int.parse(_headers[HttpHeaders.CONTENT_LENGTH][0]);
12 15
13 DateTime get ifModifiedSince { 16 DateTime get ifModifiedSince {
14 List<String> values = _headers[HttpHeaders.IF_MODIFIED_SINCE]; 17 List<String> values = _headers[HttpHeaders.IF_MODIFIED_SINCE];
15 if (values != null) { 18 if (values != null) {
16 try { 19 try {
17 return HttpDate.parse(values[0]); 20 return HttpDate.parse(values[0]);
18 } on Exception catch (e) { 21 } on Exception catch (e) {
19 return null; 22 return null;
20 } 23 }
21 } 24 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 assert(name == name.toLowerCase()); 93 assert(name == name.toLowerCase());
91 List<String> values = new List<String>(); 94 List<String> values = new List<String>();
92 _headers[name] = values; 95 _headers[name] = values;
93 values.add(value); 96 values.add(value);
94 } 97 }
95 98
96 /* 99 /*
97 * Implemented to remove editor warnings 100 * Implemented to remove editor warnings
98 */ 101 */
99 dynamic noSuchMethod(Invocation invocation) { 102 dynamic noSuchMethod(Invocation invocation) {
100 print([invocation.memberName, invocation.isGetter, invocation.isSetter, invo cation.isMethod, invocation.isAccessor]); 103 print([invocation.memberName,
104 invocation.isGetter,
105 invocation.isSetter,
106 invocation.isMethod,
107 invocation.isAccessor]);
101 return super.noSuchMethod(invocation); 108 return super.noSuchMethod(invocation);
102 } 109 }
103 } 110 }
104 111
105 class MockHttpRequest implements HttpRequest { 112 class MockHttpRequest implements HttpRequest {
106 final Uri uri; 113 final Uri uri;
107 final MockHttpResponse response = new MockHttpResponse(); 114 final MockHttpResponse response = new MockHttpResponse();
108 final HttpHeaders headers = new MockHttpHeaders(); 115 final HttpHeaders headers = new MockHttpHeaders();
109 final String method = 'GET'; 116 final String method = 'GET';
110 final bool followRedirects; 117 final bool followRedirects;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 182 }
176 183
177 /* 184 /*
178 * Implemented to remove editor warnings 185 * Implemented to remove editor warnings
179 */ 186 */
180 dynamic noSuchMethod(Invocation invocation) => 187 dynamic noSuchMethod(Invocation invocation) =>
181 super.noSuchMethod(invocation); 188 super.noSuchMethod(invocation);
182 189
183 String get mockContent => UTF8.decode(_buffer); 190 String get mockContent => UTF8.decode(_buffer);
184 191
192 List<int> get mockContentBinary => _buffer;
193
185 bool get mockDone => _isDone; 194 bool get mockDone => _isDone;
186 195
187 // Copied from SDK http_impl.dart @ 845 on 2014-01-05 196 // Copied from SDK http_impl.dart @ 845 on 2014-01-05
188 // TODO: file an SDK bug to expose this on HttpStatus in some way 197 // TODO: file an SDK bug to expose this on HttpStatus in some way
189 String _findReasonPhrase(int statusCode) { 198 String _findReasonPhrase(int statusCode) {
190 if (_reasonPhrase != null) { 199 if (_reasonPhrase != null) {
191 return _reasonPhrase; 200 return _reasonPhrase;
192 } 201 }
193 202
194 switch (statusCode) { 203 switch (statusCode) {
195 case HttpStatus.NOT_FOUND: return "Not Found"; 204 case HttpStatus.NOT_FOUND: return "Not Found";
196 default: return "Status $statusCode"; 205 default: return "Status $statusCode";
197 } 206 }
198 } 207 }
199 } 208 }
OLDNEW
« no previous file with comments | « pkg/http_server/pubspec.yaml ('k') | pkg/http_server/test/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698