| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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("http"); | 5 #library("http"); |
| 6 #source("http_impl.dart"); | 6 #source("http_impl.dart"); |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * HTTP status codes. | 9 * HTTP status codes. |
| 10 */ | 10 */ |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 static final int BAD_GATEWAY = 502; | 49 static final int BAD_GATEWAY = 502; |
| 50 static final int SERVICE_UNAVAILABLE = 503; | 50 static final int SERVICE_UNAVAILABLE = 503; |
| 51 static final int GATEWAY_TIMEOUT = 504; | 51 static final int GATEWAY_TIMEOUT = 504; |
| 52 static final int HTTP_VERSION_NOT_SUPPORTED = 505; | 52 static final int HTTP_VERSION_NOT_SUPPORTED = 505; |
| 53 } | 53 } |
| 54 | 54 |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * HTTP server. | 57 * HTTP server. |
| 58 */ | 58 */ |
| 59 interface HTTPServer factory HTTPServerImplementation { | 59 interface HTTPServer default HTTPServerImplementation { |
| 60 HTTPServer(); | 60 HTTPServer(); |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * Start listening on the specified [host] and [port]. For each HTTP | 63 * Start listening on the specified [host] and [port]. For each HTTP |
| 64 * request the specified [callback] will be invoked. If a [port] of | 64 * request the specified [callback] will be invoked. If a [port] of |
| 65 * 0 is specified the server will choose an ephemeral port. The | 65 * 0 is specified the server will choose an ephemeral port. The |
| 66 * optional argument [backlog] can be used to specify the listen | 66 * optional argument [backlog] can be used to specify the listen |
| 67 * backlog for the underlying OS listen setup. | 67 * backlog for the underlying OS listen setup. |
| 68 */ | 68 */ |
| 69 void listen(String host, | 69 void listen(String host, |
| 70 int port, | 70 int port, |
| 71 void callback(HTTPRequest, HTTPResponse), | 71 void callback(HTTPRequest, HTTPResponse), |
| 72 [int backlog]); | 72 [int backlog]); |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * Stop server listening. | 75 * Stop server listening. |
| 76 */ | 76 */ |
| 77 void close(); | 77 void close(); |
| 78 | 78 |
| 79 /** | 79 /** |
| 80 * Returns the port that the server is listening on. | 80 * Returns the port that the server is listening on. |
| 81 */ | 81 */ |
| 82 int get port(); | 82 int get port(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 | 85 |
| 86 /** | 86 /** |
| 87 * HTTP request delivered to the HTTP server callback. | 87 * HTTP request delivered to the HTTP server callback. |
| 88 */ | 88 */ |
| 89 interface HTTPRequest factory HTTPRequestImplementation { | 89 interface HTTPRequest default HTTPRequestImplementation { |
| 90 /** | 90 /** |
| 91 * Returns the content length of the request body. If the size of | 91 * Returns the content length of the request body. If the size of |
| 92 * the request body is not known in advance this -1. | 92 * the request body is not known in advance this -1. |
| 93 */ | 93 */ |
| 94 int get contentLength(); | 94 int get contentLength(); |
| 95 | 95 |
| 96 /** | 96 /** |
| 97 * Returns the keep alive state of the connection. | 97 * Returns the keep alive state of the connection. |
| 98 */ | 98 */ |
| 99 bool get keepAlive(); | 99 bool get keepAlive(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 * argument will be [null] otherwise it will be the result of UTF-8 | 142 * argument will be [null] otherwise it will be the result of UTF-8 |
| 143 * decoding the request body, | 143 * decoding the request body, |
| 144 */ | 144 */ |
| 145 void set dataEnd(void callback(String data)); | 145 void set dataEnd(void callback(String data)); |
| 146 } | 146 } |
| 147 | 147 |
| 148 | 148 |
| 149 /** | 149 /** |
| 150 * HTTP response to be send back to the client. | 150 * HTTP response to be send back to the client. |
| 151 */ | 151 */ |
| 152 interface HTTPResponse factory HTTPResponseImplementation { | 152 interface HTTPResponse default HTTPResponseImplementation { |
| 153 /** | 153 /** |
| 154 * Gets and sets the content length of the response. If the size of | 154 * Gets and sets the content length of the response. If the size of |
| 155 * the response is not known in advance set the content length to | 155 * the response is not known in advance set the content length to |
| 156 * -1 - which is also the default if not set. | 156 * -1 - which is also the default if not set. |
| 157 */ | 157 */ |
| 158 void set contentLength(int contentLength); | 158 void set contentLength(int contentLength); |
| 159 int get contentLength(); | 159 int get contentLength(); |
| 160 | 160 |
| 161 /** | 161 /** |
| 162 * Gets and sets the keep alive state of the connection. If the | 162 * Gets and sets the keep alive state of the connection. If the |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 /** | 197 /** |
| 198 * Indicate that all the response data has been written. | 198 * Indicate that all the response data has been written. |
| 199 */ | 199 */ |
| 200 void writeDone(); | 200 void writeDone(); |
| 201 } | 201 } |
| 202 | 202 |
| 203 | 203 |
| 204 /** | 204 /** |
| 205 * HTTP client factory. | 205 * HTTP client factory. |
| 206 */ | 206 */ |
| 207 interface HTTPClient factory HTTPClientImplementation { | 207 interface HTTPClient default HTTPClientImplementation { |
| 208 HTTPClient(); | 208 HTTPClient(); |
| 209 | 209 |
| 210 /** | 210 /** |
| 211 * Open a HTTP connection. The [openHandler] is called with an | 211 * Open a HTTP connection. The [openHandler] is called with an |
| 212 * HTTPClientRequest when the connection has been successfully | 212 * HTTPClientRequest when the connection has been successfully |
| 213 * opened. | 213 * opened. |
| 214 */ | 214 */ |
| 215 void open(String method, String host, int port, String path); | 215 void open(String method, String host, int port, String path); |
| 216 | 216 |
| 217 /** | 217 /** |
| 218 * Shutdown the HTTP client releasing all resources. | 218 * Shutdown the HTTP client releasing all resources. |
| 219 */ | 219 */ |
| 220 void shutdown(); | 220 void shutdown(); |
| 221 | 221 |
| 222 /** | 222 /** |
| 223 * Set the open handler that is called on successful open operations. | 223 * Set the open handler that is called on successful open operations. |
| 224 */ | 224 */ |
| 225 void set openHandler(void handler(HTTPClientRequest request)); | 225 void set openHandler(void handler(HTTPClientRequest request)); |
| 226 } | 226 } |
| 227 | 227 |
| 228 | 228 |
| 229 /** | 229 /** |
| 230 * HTTP request for a client connection. | 230 * HTTP request for a client connection. |
| 231 */ | 231 */ |
| 232 interface HTTPClientRequest factory HTTPClientRequestImplementation { | 232 interface HTTPClientRequest default HTTPClientRequestImplementation { |
| 233 /** | 233 /** |
| 234 * Gets and sets the content length of the request. If the size of | 234 * Gets and sets the content length of the request. If the size of |
| 235 * the request is not known in advance set content length to -1, | 235 * the request is not known in advance set content length to -1, |
| 236 * which is also the default. | 236 * which is also the default. |
| 237 */ | 237 */ |
| 238 void set contentLength(int contentLength); | 238 void set contentLength(int contentLength); |
| 239 int get contentLength(); | 239 int get contentLength(); |
| 240 | 240 |
| 241 /** | 241 /** |
| 242 * Gets and sets the keep alive state of the connection. | 242 * Gets and sets the keep alive state of the connection. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 * ready for processing the callback set with [setResponseReceived] | 286 * ready for processing the callback set with [setResponseReceived] |
| 287 * is called. | 287 * is called. |
| 288 */ | 288 */ |
| 289 void writeDone(); | 289 void writeDone(); |
| 290 } | 290 } |
| 291 | 291 |
| 292 | 292 |
| 293 /** | 293 /** |
| 294 * HTTP response for a client connection. | 294 * HTTP response for a client connection. |
| 295 */ | 295 */ |
| 296 interface HTTPClientResponse factory HTTPClientResponseImplementation { | 296 interface HTTPClientResponse default HTTPClientResponseImplementation { |
| 297 /** | 297 /** |
| 298 * Returns the status code. | 298 * Returns the status code. |
| 299 */ | 299 */ |
| 300 int get statusCode(); | 300 int get statusCode(); |
| 301 | 301 |
| 302 /** | 302 /** |
| 303 * Returns the reason phrase associated with the status code. | 303 * Returns the reason phrase associated with the status code. |
| 304 */ | 304 */ |
| 305 String get reasonPhrase(); | 305 String get reasonPhrase(); |
| 306 | 306 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 } else { | 397 } else { |
| 398 value = queryString.substring(currentPosition, position); | 398 value = queryString.substring(currentPosition, position); |
| 399 currentPosition = position + 1; | 399 currentPosition = position + 1; |
| 400 } | 400 } |
| 401 result[HTTPUtil.decodeUrlEncodedString(name)] = | 401 result[HTTPUtil.decodeUrlEncodedString(name)] = |
| 402 HTTPUtil.decodeUrlEncodedString(value); | 402 HTTPUtil.decodeUrlEncodedString(value); |
| 403 } | 403 } |
| 404 return result; | 404 return result; |
| 405 } | 405 } |
| 406 } | 406 } |
| OLD | NEW |