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

Side by Side Diff: runtime/bin/http.dart

Issue 10407002: Add special handling of the content type HTTP header (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 8 years, 7 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 | « no previous file | runtime/bin/http_impl.dart » ('j') | runtime/bin/http_impl.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * HTTP status codes. 6 * HTTP status codes.
7 */ 7 */
8 interface HttpStatus { 8 interface HttpStatus {
9 static final int CONTINUE = 100; 9 static final int CONTINUE = 100;
10 static final int SWITCHING_PROTOCOLS = 101; 10 static final int SWITCHING_PROTOCOLS = 101;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 IF-UNMODIFIED-SINCE, 218 IF-UNMODIFIED-SINCE,
219 MAX-FORWARDS, 219 MAX-FORWARDS,
220 PROXY-AUTHORIZATION, 220 PROXY-AUTHORIZATION,
221 RANGE, 221 RANGE,
222 REFERER, 222 REFERER,
223 TE, 223 TE,
224 USER-AGENT]; 224 USER-AGENT];
225 225
226 /** 226 /**
227 * Returns the list of values for the header named [name]. If there 227 * Returns the list of values for the header named [name]. If there
228 * is no headers with the provided name null will be returned. 228 * is no headers with the provided name [:null:] will be returned.
229 */ 229 */
230 List<String> operator[](String name); 230 List<String> operator[](String name);
231 231
232 /** 232 /**
233 * Convenience method for the value for a single values header. If 233 * Convenience method for the value for a single values header. If
234 * there is no header with the provided name null will be 234 * there is no header with the provided name [:null:] will be
235 * returned. If the header has more than one value an exception is 235 * returned. If the header has more than one value an exception is
236 * thrown. 236 * thrown.
237 */ 237 */
238 String value(String name); 238 String value(String name);
239 239
240 /** 240 /**
241 * Adds a header value. The header named [name] will have the value 241 * Adds a header value. The header named [name] will have the value
242 * [value] added to its list of values. Some headers are single 242 * [value] added to its list of values. Some headers are single
243 * values and for these adding a value will replace the previous 243 * values and for these adding a value will replace the previous
244 * value. If the value is of type Date a HTTP date format will be 244 * value. If the value is of type Date a HTTP date format will be
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 * Gets and sets the host part of the "Host" header for the 292 * Gets and sets the host part of the "Host" header for the
293 * connection. 293 * connection.
294 */ 294 */
295 String host; 295 String host;
296 296
297 /** 297 /**
298 * Gets and sets the port part of the "Host" header for the 298 * Gets and sets the port part of the "Host" header for the
299 * connection. 299 * connection.
300 */ 300 */
301 int port; 301 int port;
302
303 /**
304 * Gets and sets the content type.
305 */
306 ContentType contentType;
302 } 307 }
303 308
304 309
310 /**
311 * Representation of a header value in the form:
312 *
313 * [:value; parameter1=value1; parameter2=value2:]
314 *
315 * [HeaderValue] can be used to conveniently build and parse header
316 * values on this form.
317 *
318 * To build an [:Accepts:] header with the value
319 *
320 * text/plain; q=0.3, text/html
321 *
322 * use code like this:
323 *
324 * HttpClientRequest request = ...;
325 * var v = new HeaderValue();
326 * v.value = "text/plain";
327 * v.parameters["q"] = "0.3"
328 * request.headers.add(HttpHeaders.ACCEPT, v);
329 * request.headers.add(HttpHeaders.ACCEPT, "text/html");
330 *
331 * To parse the header values use the [:fromString:] constructor.
332 *
333 * HttpRequest request = ...;
334 * List<String> values = request.headers[HttpHeaders.ACCEPT];
335 * values.forEach((value) {
336 * HeaderValue v = new HeaderValue.fromString(value);
337 * // Use v.value and v.parameters
338 * });
339 */
340 interface HeaderValue default _HeaderValue {
341 /**
342 * Creates a new header value object setting the value part.
343 */
344 HeaderValue([String value]);
345
346 /**
347 * Creates a new header value object from parsing a header value
348 * string with both value and optional parameters.
349 */
350 HeaderValue.fromString(String value);
351
352 /**
353 * Gets and sets the header value.
354 */
355 String value;
356
357 /**
358 * Gets the map of parameters.
359 */
360 Map<String, String> get parameters();
361
362 /**
363 * Returns the formatted string representation in the form:
364 *
365 * value; parameter1=value1; parameter2=value2
366 */
367 String toString();
368
369 }
370
371
372 /**
373 * Representation of a content type.
374 */
375 interface ContentType extends HeaderValue default _ContentType {
376 /**
377 * Creates a new content type object setting the primary type and
378 * sub type. If either is not passed their values will be the empty
379 * string.
380 */
381 ContentType([String primaryType, String subType]);
382
383 /**
384 * Creates a new content type object from parsing a Content-Type
385 * header value. As primary type, sub type and parameter names and
386 * values are not case sensitive all these values will be converted
387 * to lower case. Parsing this string
388 *
389 * text/html; charset=utf-8
390 *
391 * will create a content type object with primary type [:text:], sub
392 * type [:html:] and parameter [:charset:] with value [:utf-8:].
393 */
394 ContentType.fromString(String value);
395
396 /**
397 * Gets and sets the content type in the form "primaryType/subType".
398 */
399 String value;
400
401 /**
402 * Gets and sets the primary type.
403 */
404 String primaryType;
405
406 /**
407 * Gets and sets the sub type.
408 */
409 String subType;
410
411 /**
412 * Gets and sets the character set.
413 */
414 String charset;
415 }
416
417
305 /** 418 /**
306 * Http request delivered to the HTTP server callback. 419 * Http request delivered to the HTTP server callback.
307 */ 420 */
308 interface HttpRequest default _HttpRequest { 421 interface HttpRequest default _HttpRequest {
309 /** 422 /**
310 * Returns the content length of the request body. If the size of 423 * Returns the content length of the request body. If the size of
311 * the request body is not known in advance this -1. 424 * the request body is not known in advance this -1.
312 */ 425 */
313 int get contentLength(); 426 int get contentLength();
314 427
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 class RedirectLimitExceededException extends RedirectException { 785 class RedirectLimitExceededException extends RedirectException {
673 const RedirectLimitExceededException(List<RedirectInfo> redirects) 786 const RedirectLimitExceededException(List<RedirectInfo> redirects)
674 : super("Redirect limit exceeded", redirects); 787 : super("Redirect limit exceeded", redirects);
675 } 788 }
676 789
677 790
678 class RedirectLoopException extends RedirectException { 791 class RedirectLoopException extends RedirectException {
679 const RedirectLoopException(List<RedirectInfo> redirects) 792 const RedirectLoopException(List<RedirectInfo> redirects)
680 : super("Redirect loop detected", redirects); 793 : super("Redirect loop detected", redirects);
681 } 794 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/http_impl.dart » ('j') | runtime/bin/http_impl.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698