| OLD | NEW |
| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 void set onRequest(void callback(HttpRequest, HttpResponse)); | 93 void set onRequest(void callback(HttpRequest, HttpResponse)); |
| 94 | 94 |
| 95 /** | 95 /** |
| 96 * Sets the error handler that is called when a connection error occurs. | 96 * Sets the error handler that is called when a connection error occurs. |
| 97 */ | 97 */ |
| 98 void set onError(void callback(Exception e)); | 98 void set onError(void callback(Exception e)); |
| 99 } | 99 } |
| 100 | 100 |
| 101 | 101 |
| 102 /** | 102 /** |
| 103 * Access to the HTTP headers for requests and responses. In some |
| 104 * situations the headers will be imutable and the mutating methods |
| 105 * will then throw exceptions. |
| 106 * |
| 107 * For all operation on HTTP headers the header name is |
| 108 * case-insensitive. |
| 109 */ |
| 110 interface HttpHeaders default _HttpHeaders { |
| 111 static final ACCEPT = "Accept"; |
| 112 static final ACCEPT_CHARSET = "Accept-Charset"; |
| 113 static final ACCEPT_ENCODING = "Accept-Encoding"; |
| 114 static final ACCEPT_LANGUAGE = "Accept-Language"; |
| 115 static final ACCEPT_RANGES = "Accept-Ranges"; |
| 116 static final AGE = "Age"; |
| 117 static final ALLOW = "Allow"; |
| 118 static final AUTHORIZATION = "Authorization"; |
| 119 static final CACHE_CONTROL = "Cache-Control"; |
| 120 static final CONNECTION = "Connection"; |
| 121 static final CONTENT_ENCODING = "Content-Encoding"; |
| 122 static final CONTENT_LANGUAGE = "Content-Language"; |
| 123 static final CONTENT_LENGTH = "Content-Length"; |
| 124 static final CONTENT_LOCATION = "Content-Location"; |
| 125 static final CONTENT_MD5 = "Content-MD5"; |
| 126 static final CONTENT_RANGE = "Content-Range"; |
| 127 static final CONTENT_TYPE = "Content-Type"; |
| 128 static final DATE = "Date"; |
| 129 static final ETAG = "ETag"; |
| 130 static final EXPECT = "Expect"; |
| 131 static final EXPIRES = "Expires"; |
| 132 static final FROM = "From"; |
| 133 static final HOST = "Host"; |
| 134 static final IF_MATCH = "If-Match"; |
| 135 static final IF_MODIFIED_SINCE = "If-Modified-Since"; |
| 136 static final IF_NONE_MATCH = "If-None-Match"; |
| 137 static final IF_RANGE = "If-Range"; |
| 138 static final IF_UNMODIFIED_SINCE = "If-Unmodified-Since"; |
| 139 static final LAST_MODIFIED = "Last-Modified"; |
| 140 static final LOCATION = "Location"; |
| 141 static final MAX_FORWARDS = "Max-Forwards"; |
| 142 static final PRAGMA = "Pragma"; |
| 143 static final PROXY_AUTHENTICATE = "Proxy-Authenticate"; |
| 144 static final PROXY_AUTHORIZATION = "Proxy-Authorization"; |
| 145 static final RANGE = "Range"; |
| 146 static final REFERER = "Referer"; |
| 147 static final RETRY_AFTER = "Retry-After"; |
| 148 static final SERVER = "Server"; |
| 149 static final TE = "TE"; |
| 150 static final TRAILER = "Trailer"; |
| 151 static final TRANSFER_ENCODING = "Transfer-Encoding"; |
| 152 static final UPGRADE = "Upgrade"; |
| 153 static final USER_AGENT = "User-Agent"; |
| 154 static final VARY = "Vary"; |
| 155 static final VIA = "Via"; |
| 156 static final WARNING = "Warning"; |
| 157 static final WWW_AUTHENTICATE = "WWW-Authenticate"; |
| 158 |
| 159 static final GENERAL_HEADERS = const [CACHE_CONTROL, |
| 160 CONNECTION, |
| 161 DATE, |
| 162 PRAGMA, |
| 163 TRAILER, |
| 164 TRANSFER_ENCODING, |
| 165 UPGRADE, |
| 166 VIA, |
| 167 WARNING]; |
| 168 |
| 169 static final ENTITY_HEADERS = const [ALLOW, |
| 170 CONTENT-ENCODING, |
| 171 CONTENT-LANGUAGE, |
| 172 CONTENT-LENGTH, |
| 173 CONTENT-LOCATION, |
| 174 CONTENT-MD5, |
| 175 CONTENT-RANGE, |
| 176 CONTENT-TYPE, |
| 177 EXPIRES, |
| 178 LAST-MODIFIED]; |
| 179 |
| 180 |
| 181 static final RESPONSE_HEADERS = const [ACCEPT-RANGES, |
| 182 AGE, |
| 183 ETAG, |
| 184 LOCATION, |
| 185 PROXY-AUTHENTICATE, |
| 186 RETRY-AFTER, |
| 187 SERVER, |
| 188 VARY, |
| 189 WWW-AUTHENTICATE]; |
| 190 |
| 191 static final REQUEST_HEADERS = const [ACCEPT, |
| 192 ACCEPT-CHARSET, |
| 193 ACCEPT-ENCODING, |
| 194 ACCEPT-LANGUAGE, |
| 195 AUTHORIZATION, |
| 196 EXPECT, |
| 197 FROM, |
| 198 HOST, |
| 199 IF-MATCH, |
| 200 IF-MODIFIED-SINCE, |
| 201 IF-NONE-MATCH, |
| 202 IF-RANGE, |
| 203 IF-UNMODIFIED-SINCE, |
| 204 MAX-FORWARDS, |
| 205 PROXY-AUTHORIZATION, |
| 206 RANGE, |
| 207 REFERER, |
| 208 TE, |
| 209 USER-AGENT]; |
| 210 |
| 211 /** |
| 212 * Returns the list of values for the header named [name]. If there |
| 213 * is no headers with the provided name null will be returned. |
| 214 */ |
| 215 List<String> operator[](String name); |
| 216 |
| 217 /** |
| 218 * Convenience method for the value for a single values header. If |
| 219 * there is no header with the provided name null will be |
| 220 * returned. If the header has more than one value an exception is |
| 221 * thrown. |
| 222 */ |
| 223 String value(String name); |
| 224 |
| 225 /** |
| 226 * Adds a header value. The header named [name] will have the value |
| 227 * [value] added to its list of values. Some headers are single |
| 228 * values and for these adding a value will replace the previous |
| 229 * value. If the value is of type Date a HTTP date format will be |
| 230 * applied. If the value is a [:List:] each element of the list will |
| 231 * be added separately. For all other types the default [:toString:] |
| 232 * method will be used. |
| 233 */ |
| 234 void add(String name, Object value); |
| 235 |
| 236 /** |
| 237 * Sets a header. The header named [name] will have all its values |
| 238 * cleared before the value [value] is added as its value. |
| 239 */ |
| 240 void set(String name, Object value); |
| 241 |
| 242 /** |
| 243 * Removes a specific value for a header name. Some headers have |
| 244 * system supplied values and for these the system supplied values |
| 245 * will still be added to the collection of values for the header. |
| 246 */ |
| 247 void remove(String name, Object value); |
| 248 |
| 249 /** |
| 250 * Remove all values for the specified header name. Some headers |
| 251 * have system supplied values and for these the system supplied |
| 252 * values will still be added to the collection of values for the |
| 253 * header. |
| 254 */ |
| 255 void removeAll(String name); |
| 256 } |
| 257 |
| 258 |
| 259 /** |
| 103 * Http request delivered to the HTTP server callback. | 260 * Http request delivered to the HTTP server callback. |
| 104 */ | 261 */ |
| 105 interface HttpRequest default _HttpRequest { | 262 interface HttpRequest default _HttpRequest { |
| 106 /** | 263 /** |
| 107 * Returns the content length of the request body. If the size of | 264 * Returns the content length of the request body. If the size of |
| 108 * the request body is not known in advance this -1. | 265 * the request body is not known in advance this -1. |
| 109 */ | 266 */ |
| 110 int get contentLength(); | 267 int get contentLength(); |
| 111 | 268 |
| 112 /** | 269 /** |
| (...skipping 17 matching lines...) Expand all Loading... |
| 130 String get queryString(); | 287 String get queryString(); |
| 131 | 288 |
| 132 /** | 289 /** |
| 133 * Returns the parsed query string. | 290 * Returns the parsed query string. |
| 134 */ | 291 */ |
| 135 Map<String, String> get queryParameters(); | 292 Map<String, String> get queryParameters(); |
| 136 | 293 |
| 137 /** | 294 /** |
| 138 * Returns the request headers. | 295 * Returns the request headers. |
| 139 */ | 296 */ |
| 140 Map<String, String> get headers(); | 297 HttpHeaders get headers(); |
| 141 | 298 |
| 142 /** | 299 /** |
| 143 * Returns the input stream for the request. This is used to read | 300 * Returns the input stream for the request. This is used to read |
| 144 * the request data. | 301 * the request data. |
| 145 */ | 302 */ |
| 146 InputStream get inputStream(); | 303 InputStream get inputStream(); |
| 147 } | 304 } |
| 148 | 305 |
| 149 | 306 |
| 150 /** | 307 /** |
| (...skipping 20 matching lines...) Expand all Loading... |
| 171 */ | 328 */ |
| 172 String reasonPhrase; | 329 String reasonPhrase; |
| 173 | 330 |
| 174 /** | 331 /** |
| 175 * Gets and sets the expiry date. The value of this property will | 332 * Gets and sets the expiry date. The value of this property will |
| 176 * reflect the "Expires" header | 333 * reflect the "Expires" header |
| 177 */ | 334 */ |
| 178 Date expires; | 335 Date expires; |
| 179 | 336 |
| 180 /** | 337 /** |
| 181 * Sets a header on the response. NOTE: If the same header name is | |
| 182 * set more than once only the last value will be part of the | |
| 183 * response. | |
| 184 */ | |
| 185 void setHeader(String name, String value); | |
| 186 | |
| 187 /** | |
| 188 * Returns the response headers. | 338 * Returns the response headers. |
| 189 */ | 339 */ |
| 190 Map<String, String> get headers(); | 340 HttpHeaders get headers(); |
| 191 | 341 |
| 192 /** | 342 /** |
| 193 * Returns the output stream for the response. This is used to write | 343 * Returns the output stream for the response. This is used to write |
| 194 * the response data. When all response data has been written close | 344 * the response data. When all response data has been written close |
| 195 * the stream to indicate the end of the response. | 345 * the stream to indicate the end of the response. |
| 196 * | 346 * |
| 197 * When this is accessed for the first time the response header is | 347 * When this is accessed for the first time the response header is |
| 198 * send. Calling any methods that will change the header after | 348 * send. Calling any methods that will change the header after |
| 199 * having retrieved the output stream will throw an exception. | 349 * having retrieved the output stream will throw an exception. |
| 200 */ | 350 */ |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 String host; | 460 String host; |
| 311 | 461 |
| 312 /** | 462 /** |
| 313 * Gets and sets the port part of the "Host" header for the | 463 * Gets and sets the port part of the "Host" header for the |
| 314 * connection. By default this will be set to the value of the port | 464 * connection. By default this will be set to the value of the port |
| 315 * used when initiating the connection. | 465 * used when initiating the connection. |
| 316 */ | 466 */ |
| 317 int port; | 467 int port; |
| 318 | 468 |
| 319 /** | 469 /** |
| 320 * Sets a header on the request. NOTE: If the same header name is | |
| 321 * set more than once only the last value set will be part of the | |
| 322 * request. | |
| 323 */ | |
| 324 void setHeader(String name, String value); | |
| 325 | |
| 326 /** | |
| 327 * Returns the request headers. | 470 * Returns the request headers. |
| 328 */ | 471 */ |
| 329 Map<String, String> get headers(); | 472 HttpHeaders get headers(); |
| 330 | 473 |
| 331 /** | 474 /** |
| 332 * Returns the output stream for the request. This is used to write | 475 * Returns the output stream for the request. This is used to write |
| 333 * the request data. When all request data has been written close | 476 * the request data. When all request data has been written close |
| 334 * the stream to indicate the end of the request. | 477 * the stream to indicate the end of the request. |
| 335 * | 478 * |
| 336 * When this is accessed for the first time the request header is | 479 * When this is accessed for the first time the request header is |
| 337 * send. Calling any methods that will change the header after | 480 * send. Calling any methods that will change the header after |
| 338 * having retrieved the output stream will throw an exception. | 481 * having retrieved the output stream will throw an exception. |
| 339 */ | 482 */ |
| (...skipping 25 matching lines...) Expand all Loading... |
| 365 * Returns the date value for the "Expires" header. Returns null if | 508 * Returns the date value for the "Expires" header. Returns null if |
| 366 * the response has no "Expires" header. Throws a HttpException if | 509 * the response has no "Expires" header. Throws a HttpException if |
| 367 * the response has an "Expires" header which is not formatted as a | 510 * the response has an "Expires" header which is not formatted as a |
| 368 * valid HTTP date. | 511 * valid HTTP date. |
| 369 */ | 512 */ |
| 370 Date get expires(); | 513 Date get expires(); |
| 371 | 514 |
| 372 /** | 515 /** |
| 373 * Returns the response headers. | 516 * Returns the response headers. |
| 374 */ | 517 */ |
| 375 Map<String, String> get headers(); | 518 HttpHeaders get headers(); |
| 376 | 519 |
| 377 /** | 520 /** |
| 378 * Returns the input stream for the response. This is used to read | 521 * Returns the input stream for the response. This is used to read |
| 379 * the response data. | 522 * the response data. |
| 380 */ | 523 */ |
| 381 InputStream get inputStream(); | 524 InputStream get inputStream(); |
| 382 } | 525 } |
| 383 | 526 |
| 384 | 527 |
| 385 class HttpException implements Exception { | 528 class HttpException implements Exception { |
| 386 const HttpException([String this.message = ""]); | 529 const HttpException([String this.message = ""]); |
| 387 String toString() => "HttpException: $message"; | 530 String toString() => "HttpException: $message"; |
| 388 final String message; | 531 final String message; |
| 389 } | 532 } |
| OLD | NEW |