Wed, 31 Dec 2014 06:55:46 +0100
Added tag TORBROWSER_REPLICA for changeset 6474c204b198
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "nsISupports.idl" |
michael@0 | 6 | |
michael@0 | 7 | interface nsIInputStream; |
michael@0 | 8 | interface nsIFile; |
michael@0 | 9 | interface nsIOutputStream; |
michael@0 | 10 | interface nsISimpleEnumerator; |
michael@0 | 11 | |
michael@0 | 12 | interface nsIHttpServer; |
michael@0 | 13 | interface nsIHttpServerStoppedCallback; |
michael@0 | 14 | interface nsIHttpRequestHandler; |
michael@0 | 15 | interface nsIHttpRequest; |
michael@0 | 16 | interface nsIHttpResponse; |
michael@0 | 17 | interface nsIHttpServerIdentity; |
michael@0 | 18 | |
michael@0 | 19 | /** |
michael@0 | 20 | * An interface which represents an HTTP server. |
michael@0 | 21 | */ |
michael@0 | 22 | [scriptable, uuid(cea8812e-faa6-4013-9396-f9936cbb74ec)] |
michael@0 | 23 | interface nsIHttpServer : nsISupports |
michael@0 | 24 | { |
michael@0 | 25 | /** |
michael@0 | 26 | * Starts up this server, listening upon the given port. |
michael@0 | 27 | * |
michael@0 | 28 | * @param port |
michael@0 | 29 | * the port upon which listening should happen, or -1 if no specific port is |
michael@0 | 30 | * desired |
michael@0 | 31 | * @throws NS_ERROR_ALREADY_INITIALIZED |
michael@0 | 32 | * if this server is already started |
michael@0 | 33 | * @throws NS_ERROR_NOT_AVAILABLE |
michael@0 | 34 | * if the server is not started and cannot be started on the desired port |
michael@0 | 35 | * (perhaps because the port is already in use or because the process does |
michael@0 | 36 | * not have privileges to do so) |
michael@0 | 37 | * @note |
michael@0 | 38 | * Behavior is undefined if this method is called after stop() has been |
michael@0 | 39 | * called on this but before the provided callback function has been |
michael@0 | 40 | * called. |
michael@0 | 41 | */ |
michael@0 | 42 | void start(in long port); |
michael@0 | 43 | |
michael@0 | 44 | /** |
michael@0 | 45 | * Shuts down this server if it is running (including the period of time after |
michael@0 | 46 | * stop() has been called but before the provided callback has been called). |
michael@0 | 47 | * |
michael@0 | 48 | * @param callback |
michael@0 | 49 | * an asynchronous callback used to notify the user when this server is |
michael@0 | 50 | * stopped and all pending requests have been fully served |
michael@0 | 51 | * @throws NS_ERROR_NULL_POINTER |
michael@0 | 52 | * if callback is null |
michael@0 | 53 | * @throws NS_ERROR_UNEXPECTED |
michael@0 | 54 | * if this server is not running |
michael@0 | 55 | */ |
michael@0 | 56 | void stop(in nsIHttpServerStoppedCallback callback); |
michael@0 | 57 | |
michael@0 | 58 | /** |
michael@0 | 59 | * Associates the local file represented by the string file with all requests |
michael@0 | 60 | * which match request. |
michael@0 | 61 | * |
michael@0 | 62 | * @param path |
michael@0 | 63 | * the path which is to be mapped to the given file; must begin with "/" and |
michael@0 | 64 | * be a valid URI path (i.e., no query string, hash reference, etc.) |
michael@0 | 65 | * @param file |
michael@0 | 66 | * the file to serve for the given path, or null to remove any mapping that |
michael@0 | 67 | * might exist; this file must exist for the lifetime of the server |
michael@0 | 68 | */ |
michael@0 | 69 | void registerFile(in string path, in nsIFile file); |
michael@0 | 70 | |
michael@0 | 71 | /** |
michael@0 | 72 | * Registers a custom path handler. |
michael@0 | 73 | * |
michael@0 | 74 | * @param path |
michael@0 | 75 | * the path on the server (beginning with a "/") which is to be handled by |
michael@0 | 76 | * handler; this path must not include a query string or hash component; it |
michael@0 | 77 | * also should usually be canonicalized, since most browsers will do so |
michael@0 | 78 | * before sending otherwise-matching requests |
michael@0 | 79 | * @param handler |
michael@0 | 80 | * an object which will handle any requests for the given path, or null to |
michael@0 | 81 | * remove any existing handler; if while the server is running the handler |
michael@0 | 82 | * throws an exception while responding to a request, an HTTP 500 response |
michael@0 | 83 | * will be returned |
michael@0 | 84 | * @throws NS_ERROR_INVALID_ARG |
michael@0 | 85 | * if path does not begin with a "/" |
michael@0 | 86 | */ |
michael@0 | 87 | void registerPathHandler(in string path, in nsIHttpRequestHandler handler); |
michael@0 | 88 | |
michael@0 | 89 | /** |
michael@0 | 90 | * Registers a custom prefix handler. |
michael@0 | 91 | * |
michael@0 | 92 | * @param prefix |
michael@0 | 93 | * the path on the server (beginning and ending with "/") which is to be |
michael@0 | 94 | * handled by handler; this path must not include a query string or hash |
michael@0 | 95 | * component. All requests that start with this prefix will be directed to |
michael@0 | 96 | * the given handler. |
michael@0 | 97 | * @param handler |
michael@0 | 98 | * an object which will handle any requests for the given path, or null to |
michael@0 | 99 | * remove any existing handler; if while the server is running the handler |
michael@0 | 100 | * throws an exception while responding to a request, an HTTP 500 response |
michael@0 | 101 | * will be returned |
michael@0 | 102 | * @throws NS_ERROR_INVALID_ARG |
michael@0 | 103 | * if path does not begin with a "/" or does not end with a "/" |
michael@0 | 104 | */ |
michael@0 | 105 | void registerPrefixHandler(in string prefix, in nsIHttpRequestHandler handler); |
michael@0 | 106 | |
michael@0 | 107 | /** |
michael@0 | 108 | * Registers a custom error page handler. |
michael@0 | 109 | * |
michael@0 | 110 | * @param code |
michael@0 | 111 | * the error code which is to be handled by handler |
michael@0 | 112 | * @param handler |
michael@0 | 113 | * an object which will handle any requests which generate the given status |
michael@0 | 114 | * code, or null to remove any existing handler. If the handler throws an |
michael@0 | 115 | * exception during server operation, fallback is to the genericized error |
michael@0 | 116 | * handler (the x00 version), then to 500, using a user-defined error |
michael@0 | 117 | * handler if one exists or the server default handler otherwise. Fallback |
michael@0 | 118 | * will never occur from a user-provided handler that throws to the same |
michael@0 | 119 | * handler as provided by the server, e.g. a throwing user 404 falls back to |
michael@0 | 120 | * 400, not a server-provided 404 that might not throw. |
michael@0 | 121 | * @note |
michael@0 | 122 | * If the error handler handles HTTP 500 and throws, behavior is undefined. |
michael@0 | 123 | */ |
michael@0 | 124 | void registerErrorHandler(in unsigned long code, in nsIHttpRequestHandler handler); |
michael@0 | 125 | |
michael@0 | 126 | /** |
michael@0 | 127 | * Maps all requests to paths beneath path to the corresponding file beneath |
michael@0 | 128 | * dir. |
michael@0 | 129 | * |
michael@0 | 130 | * @param path |
michael@0 | 131 | * the absolute path on the server against which requests will be served |
michael@0 | 132 | * from dir (e.g., "/", "/foo/", etc.); must begin and end with a forward |
michael@0 | 133 | * slash |
michael@0 | 134 | * @param dir |
michael@0 | 135 | * the directory to be used to serve all requests for paths underneath path |
michael@0 | 136 | * (except those further overridden by another, deeper path registered with |
michael@0 | 137 | * another directory); if null, any current mapping for the given path is |
michael@0 | 138 | * removed |
michael@0 | 139 | * @throws NS_ERROR_INVALID_ARG |
michael@0 | 140 | * if dir is non-null and does not exist or is not a directory, or if path |
michael@0 | 141 | * does not begin with and end with a forward slash |
michael@0 | 142 | */ |
michael@0 | 143 | void registerDirectory(in string path, in nsIFile dir); |
michael@0 | 144 | |
michael@0 | 145 | /** |
michael@0 | 146 | * Associates files with the given extension with the given Content-Type when |
michael@0 | 147 | * served by this server, in the absence of any file-specific information |
michael@0 | 148 | * about the desired Content-Type. If type is empty, removes any extant |
michael@0 | 149 | * mapping, if one is present. |
michael@0 | 150 | * |
michael@0 | 151 | * @throws NS_ERROR_INVALID_ARG |
michael@0 | 152 | * if the given type is not a valid header field value, i.e. if it doesn't |
michael@0 | 153 | * match the field-value production in RFC 2616 |
michael@0 | 154 | * @note |
michael@0 | 155 | * No syntax checking is done of the given type, beyond ensuring that it is |
michael@0 | 156 | * a valid header field value. Behavior when not given a string matching |
michael@0 | 157 | * the media-type production in RFC 2616 section 3.7 is undefined. |
michael@0 | 158 | * Implementations may choose to define specific behavior for types which do |
michael@0 | 159 | * not match the production, such as for CGI functionality. |
michael@0 | 160 | * @note |
michael@0 | 161 | * Implementations MAY treat type as a trusted argument; users who fail to |
michael@0 | 162 | * generate this string from trusted data risk security vulnerabilities. |
michael@0 | 163 | */ |
michael@0 | 164 | void registerContentType(in string extension, in string type); |
michael@0 | 165 | |
michael@0 | 166 | /** |
michael@0 | 167 | * Sets the handler used to display the contents of a directory if |
michael@0 | 168 | * the directory contains no index page. |
michael@0 | 169 | * |
michael@0 | 170 | * @param handler |
michael@0 | 171 | * an object which will handle any requests for directories which |
michael@0 | 172 | * do not contain index pages, or null to reset to the default |
michael@0 | 173 | * index handler; if while the server is running the handler |
michael@0 | 174 | * throws an exception while responding to a request, an HTTP 500 |
michael@0 | 175 | * response will be returned. An nsIFile corresponding to the |
michael@0 | 176 | * directory is available from the metadata object passed to the |
michael@0 | 177 | * handler, under the key "directory". |
michael@0 | 178 | */ |
michael@0 | 179 | void setIndexHandler(in nsIHttpRequestHandler handler); |
michael@0 | 180 | |
michael@0 | 181 | /** Represents the locations at which this server is reachable. */ |
michael@0 | 182 | readonly attribute nsIHttpServerIdentity identity; |
michael@0 | 183 | |
michael@0 | 184 | /** |
michael@0 | 185 | * Retrieves the string associated with the given key in this, for the given |
michael@0 | 186 | * path's saved state. All keys are initially associated with the empty |
michael@0 | 187 | * string. |
michael@0 | 188 | */ |
michael@0 | 189 | AString getState(in AString path, in AString key); |
michael@0 | 190 | |
michael@0 | 191 | /** |
michael@0 | 192 | * Sets the string associated with the given key in this, for the given path's |
michael@0 | 193 | * saved state. |
michael@0 | 194 | */ |
michael@0 | 195 | void setState(in AString path, in AString key, in AString value); |
michael@0 | 196 | |
michael@0 | 197 | /** |
michael@0 | 198 | * Retrieves the string associated with the given key in this, in |
michael@0 | 199 | * entire-server saved state. All keys are initially associated with the |
michael@0 | 200 | * empty string. |
michael@0 | 201 | */ |
michael@0 | 202 | AString getSharedState(in AString key); |
michael@0 | 203 | |
michael@0 | 204 | /** |
michael@0 | 205 | * Sets the string associated with the given key in this, in entire-server |
michael@0 | 206 | * saved state. |
michael@0 | 207 | */ |
michael@0 | 208 | void setSharedState(in AString key, in AString value); |
michael@0 | 209 | |
michael@0 | 210 | /** |
michael@0 | 211 | * Retrieves the object associated with the given key in this in |
michael@0 | 212 | * object-valued saved state. All keys are initially associated with null. |
michael@0 | 213 | */ |
michael@0 | 214 | nsISupports getObjectState(in AString key); |
michael@0 | 215 | |
michael@0 | 216 | /** |
michael@0 | 217 | * Sets the object associated with the given key in this in object-valued |
michael@0 | 218 | * saved state. The value may be null. |
michael@0 | 219 | */ |
michael@0 | 220 | void setObjectState(in AString key, in nsISupports value); |
michael@0 | 221 | }; |
michael@0 | 222 | |
michael@0 | 223 | /** |
michael@0 | 224 | * An interface through which a notification of the complete stopping (socket |
michael@0 | 225 | * closure, in-flight requests all fully served and responded to) of an HTTP |
michael@0 | 226 | * server may be received. |
michael@0 | 227 | */ |
michael@0 | 228 | [scriptable, function, uuid(925a6d33-9937-4c63-abe1-a1c56a986455)] |
michael@0 | 229 | interface nsIHttpServerStoppedCallback : nsISupports |
michael@0 | 230 | { |
michael@0 | 231 | /** Called when the corresponding server has been fully stopped. */ |
michael@0 | 232 | void onStopped(); |
michael@0 | 233 | }; |
michael@0 | 234 | |
michael@0 | 235 | /** |
michael@0 | 236 | * Represents a set of names for a server, one of which is the primary name for |
michael@0 | 237 | * the server and the rest of which are secondary. By default every server will |
michael@0 | 238 | * contain ("http", "localhost", port) and ("http", "127.0.0.1", port) as names, |
michael@0 | 239 | * where port is what was provided to the corresponding server when started; |
michael@0 | 240 | * however, except for their being removed when the corresponding server stops |
michael@0 | 241 | * they have no special importance. |
michael@0 | 242 | */ |
michael@0 | 243 | [scriptable, uuid(a89de175-ae8e-4c46-91a5-0dba99bbd284)] |
michael@0 | 244 | interface nsIHttpServerIdentity : nsISupports |
michael@0 | 245 | { |
michael@0 | 246 | /** |
michael@0 | 247 | * The primary scheme at which the corresponding server is located, defaulting |
michael@0 | 248 | * to 'http'. This name will be the value of nsIHttpRequest.scheme for |
michael@0 | 249 | * HTTP/1.0 requests. |
michael@0 | 250 | * |
michael@0 | 251 | * This value is always set when the corresponding server is running. If the |
michael@0 | 252 | * server is not running, this value is set only if it has been set to a |
michael@0 | 253 | * non-default name using setPrimary. In this case reading this value will |
michael@0 | 254 | * throw NS_ERROR_NOT_INITIALIZED. |
michael@0 | 255 | */ |
michael@0 | 256 | readonly attribute string primaryScheme; |
michael@0 | 257 | |
michael@0 | 258 | /** |
michael@0 | 259 | * The primary name by which the corresponding server is known, defaulting to |
michael@0 | 260 | * 'localhost'. This name will be the value of nsIHttpRequest.host for |
michael@0 | 261 | * HTTP/1.0 requests. |
michael@0 | 262 | * |
michael@0 | 263 | * This value is always set when the corresponding server is running. If the |
michael@0 | 264 | * server is not running, this value is set only if it has been set to a |
michael@0 | 265 | * non-default name using setPrimary. In this case reading this value will |
michael@0 | 266 | * throw NS_ERROR_NOT_INITIALIZED. |
michael@0 | 267 | */ |
michael@0 | 268 | readonly attribute string primaryHost; |
michael@0 | 269 | |
michael@0 | 270 | /** |
michael@0 | 271 | * The primary port on which the corresponding server runs, defaulting to the |
michael@0 | 272 | * associated server's port. This name will be the value of |
michael@0 | 273 | * nsIHttpRequest.port for HTTP/1.0 requests. |
michael@0 | 274 | * |
michael@0 | 275 | * This value is always set when the corresponding server is running. If the |
michael@0 | 276 | * server is not running, this value is set only if it has been set to a |
michael@0 | 277 | * non-default name using setPrimary. In this case reading this value will |
michael@0 | 278 | * throw NS_ERROR_NOT_INITIALIZED. |
michael@0 | 279 | */ |
michael@0 | 280 | readonly attribute long primaryPort; |
michael@0 | 281 | |
michael@0 | 282 | /** |
michael@0 | 283 | * Adds a location at which this server may be accessed. |
michael@0 | 284 | * |
michael@0 | 285 | * @throws NS_ERROR_ILLEGAL_VALUE |
michael@0 | 286 | * if scheme or host do not match the scheme or host productions imported |
michael@0 | 287 | * into RFC 2616 from RFC 2396, or if port is not a valid port number |
michael@0 | 288 | */ |
michael@0 | 289 | void add(in string scheme, in string host, in long port); |
michael@0 | 290 | |
michael@0 | 291 | /** |
michael@0 | 292 | * Removes this name from the list of names by which the corresponding server |
michael@0 | 293 | * is known. If name is also the primary name for the server, the primary |
michael@0 | 294 | * name reverts to 'http://127.0.0.1' with the associated server's port. |
michael@0 | 295 | * |
michael@0 | 296 | * @throws NS_ERROR_ILLEGAL_VALUE |
michael@0 | 297 | * if scheme or host do not match the scheme or host productions imported |
michael@0 | 298 | * into RFC 2616 from RFC 2396, or if port is not a valid port number |
michael@0 | 299 | * @returns |
michael@0 | 300 | * true if the given name was a name for this server, false otherwise |
michael@0 | 301 | */ |
michael@0 | 302 | boolean remove(in string scheme, in string host, in long port); |
michael@0 | 303 | |
michael@0 | 304 | /** |
michael@0 | 305 | * Returns true if the given name is in this, false otherwise. |
michael@0 | 306 | * |
michael@0 | 307 | * @throws NS_ERROR_ILLEGAL_VALUE |
michael@0 | 308 | * if scheme or host do not match the scheme or host productions imported |
michael@0 | 309 | * into RFC 2616 from RFC 2396, or if port is not a valid port number |
michael@0 | 310 | */ |
michael@0 | 311 | boolean has(in string scheme, in string host, in long port); |
michael@0 | 312 | |
michael@0 | 313 | /** |
michael@0 | 314 | * Returns the scheme for the name with the given host and port, if one is |
michael@0 | 315 | * present; otherwise returns the empty string. |
michael@0 | 316 | * |
michael@0 | 317 | * @throws NS_ERROR_ILLEGAL_VALUE |
michael@0 | 318 | * if host does not match the host production imported into RFC 2616 from |
michael@0 | 319 | * RFC 2396, or if port is not a valid port number |
michael@0 | 320 | */ |
michael@0 | 321 | string getScheme(in string host, in long port); |
michael@0 | 322 | |
michael@0 | 323 | /** |
michael@0 | 324 | * Designates the given name as the primary name in this and adds it to this |
michael@0 | 325 | * if it is not already present. |
michael@0 | 326 | * |
michael@0 | 327 | * @throws NS_ERROR_ILLEGAL_VALUE |
michael@0 | 328 | * if scheme or host do not match the scheme or host productions imported |
michael@0 | 329 | * into RFC 2616 from RFC 2396, or if port is not a valid port number |
michael@0 | 330 | */ |
michael@0 | 331 | void setPrimary(in string scheme, in string host, in long port); |
michael@0 | 332 | }; |
michael@0 | 333 | |
michael@0 | 334 | /** |
michael@0 | 335 | * A representation of a handler for HTTP requests. The handler is used by |
michael@0 | 336 | * calling its .handle method with data for an incoming request; it is the |
michael@0 | 337 | * handler's job to use that data as it sees fit to make the desired response. |
michael@0 | 338 | * |
michael@0 | 339 | * @note |
michael@0 | 340 | * This interface uses the [function] attribute, so you can pass a |
michael@0 | 341 | * script-defined function with the functionality of handle() to any |
michael@0 | 342 | * method which has a nsIHttpRequestHandler parameter, instead of wrapping |
michael@0 | 343 | * it in an otherwise empty object. |
michael@0 | 344 | */ |
michael@0 | 345 | [scriptable, function, uuid(2bbb4db7-d285-42b3-a3ce-142b8cc7e139)] |
michael@0 | 346 | interface nsIHttpRequestHandler : nsISupports |
michael@0 | 347 | { |
michael@0 | 348 | /** |
michael@0 | 349 | * Processes an HTTP request and initializes the passed-in response to reflect |
michael@0 | 350 | * the correct HTTP response. |
michael@0 | 351 | * |
michael@0 | 352 | * If this method throws an exception, externally observable behavior depends |
michael@0 | 353 | * upon whether is being processed asynchronously. If such is the case, the |
michael@0 | 354 | * output is some prefix (perhaps all, perhaps none, perhaps only some) of the |
michael@0 | 355 | * data which would have been sent if, instead, the response had been finished |
michael@0 | 356 | * at that point. If no data has been written, the response has not had |
michael@0 | 357 | * seizePower() called on it, and it is not being asynchronously created, an |
michael@0 | 358 | * error handler will be invoked (usually 500 unless otherwise specified). |
michael@0 | 359 | * |
michael@0 | 360 | * Some uses of nsIHttpRequestHandler may require this method to never throw |
michael@0 | 361 | * an exception; in the general case, however, this method may throw an |
michael@0 | 362 | * exception (causing an HTTP 500 response to occur, if the above conditions |
michael@0 | 363 | * are met). |
michael@0 | 364 | * |
michael@0 | 365 | * @param request |
michael@0 | 366 | * data representing an HTTP request |
michael@0 | 367 | * @param response |
michael@0 | 368 | * an initially-empty response which must be modified to reflect the data |
michael@0 | 369 | * which should be sent as the response to the request described by metadata |
michael@0 | 370 | */ |
michael@0 | 371 | void handle(in nsIHttpRequest request, in nsIHttpResponse response); |
michael@0 | 372 | }; |
michael@0 | 373 | |
michael@0 | 374 | |
michael@0 | 375 | /** |
michael@0 | 376 | * A representation of the data included in an HTTP request. |
michael@0 | 377 | */ |
michael@0 | 378 | [scriptable, uuid(978cf30e-ad73-42ee-8f22-fe0aaf1bf5d2)] |
michael@0 | 379 | interface nsIHttpRequest : nsISupports |
michael@0 | 380 | { |
michael@0 | 381 | /** |
michael@0 | 382 | * The request type for this request (see RFC 2616, section 5.1.1). |
michael@0 | 383 | */ |
michael@0 | 384 | readonly attribute string method; |
michael@0 | 385 | |
michael@0 | 386 | /** |
michael@0 | 387 | * The scheme of the requested path, usually 'http' but might possibly be |
michael@0 | 388 | * 'https' if some form of SSL tunneling is in use. Note that this value |
michael@0 | 389 | * cannot be accurately determined unless the incoming request used the |
michael@0 | 390 | * absolute-path form of the request line; it defaults to 'http', so only |
michael@0 | 391 | * if it is something else can you be entirely certain it's correct. |
michael@0 | 392 | */ |
michael@0 | 393 | readonly attribute string scheme; |
michael@0 | 394 | |
michael@0 | 395 | /** |
michael@0 | 396 | * The host of the data being requested (e.g. "localhost" for the |
michael@0 | 397 | * http://localhost:8080/file resource). Note that the relevant port on the |
michael@0 | 398 | * host is specified in this.port. This value is in the ASCII character |
michael@0 | 399 | * encoding. |
michael@0 | 400 | */ |
michael@0 | 401 | readonly attribute string host; |
michael@0 | 402 | |
michael@0 | 403 | /** |
michael@0 | 404 | * The port on the server on which the request was received. |
michael@0 | 405 | */ |
michael@0 | 406 | readonly attribute unsigned long port; |
michael@0 | 407 | |
michael@0 | 408 | /** |
michael@0 | 409 | * The requested path, without any query string (e.g. "/dir/file.txt"). It is |
michael@0 | 410 | * guaranteed to begin with a "/". The individual components in this string |
michael@0 | 411 | * are URL-encoded. |
michael@0 | 412 | */ |
michael@0 | 413 | readonly attribute string path; |
michael@0 | 414 | |
michael@0 | 415 | /** |
michael@0 | 416 | * The URL-encoded query string associated with this request, not including |
michael@0 | 417 | * the initial "?", or "" if no query string was present. |
michael@0 | 418 | */ |
michael@0 | 419 | readonly attribute string queryString; |
michael@0 | 420 | |
michael@0 | 421 | /** |
michael@0 | 422 | * A string containing the HTTP version of the request (i.e., "1.1"). Leading |
michael@0 | 423 | * zeros for either component of the version will be omitted. (In other |
michael@0 | 424 | * words, if the request contains the version "1.01", this attribute will be |
michael@0 | 425 | * "1.1"; see RFC 2616, section 3.1.) |
michael@0 | 426 | */ |
michael@0 | 427 | readonly attribute string httpVersion; |
michael@0 | 428 | |
michael@0 | 429 | /** |
michael@0 | 430 | * Returns the value for the header in this request specified by fieldName. |
michael@0 | 431 | * |
michael@0 | 432 | * @param fieldName |
michael@0 | 433 | * the name of the field whose value is to be gotten; note that since HTTP |
michael@0 | 434 | * header field names are case-insensitive, this method produces equivalent |
michael@0 | 435 | * results for "HeAdER" and "hEADer" as fieldName |
michael@0 | 436 | * @returns |
michael@0 | 437 | * The result is a string containing the individual values of the header, |
michael@0 | 438 | * usually separated with a comma. The headers WWW-Authenticate, |
michael@0 | 439 | * Proxy-Authenticate, and Set-Cookie violate the HTTP specification, |
michael@0 | 440 | * however, and for these headers only the separator string is '\n'. |
michael@0 | 441 | * |
michael@0 | 442 | * @throws NS_ERROR_INVALID_ARG |
michael@0 | 443 | * if fieldName does not constitute a valid header field name |
michael@0 | 444 | * @throws NS_ERROR_NOT_AVAILABLE |
michael@0 | 445 | * if the given header does not exist in this |
michael@0 | 446 | */ |
michael@0 | 447 | string getHeader(in string fieldName); |
michael@0 | 448 | |
michael@0 | 449 | /** |
michael@0 | 450 | * Returns true if a header with the given field name exists in this, false |
michael@0 | 451 | * otherwise. |
michael@0 | 452 | * |
michael@0 | 453 | * @param fieldName |
michael@0 | 454 | * the field name whose existence is to be determined in this; note that |
michael@0 | 455 | * since HTTP header field names are case-insensitive, this method produces |
michael@0 | 456 | * equivalent results for "HeAdER" and "hEADer" as fieldName |
michael@0 | 457 | * @throws NS_ERROR_INVALID_ARG |
michael@0 | 458 | * if fieldName does not constitute a valid header field name |
michael@0 | 459 | */ |
michael@0 | 460 | boolean hasHeader(in string fieldName); |
michael@0 | 461 | |
michael@0 | 462 | /** |
michael@0 | 463 | * An nsISimpleEnumerator of nsISupportsStrings over the names of the headers |
michael@0 | 464 | * in this request. The header field names in the enumerator may not |
michael@0 | 465 | * necessarily have the same case as they do in the request itself. |
michael@0 | 466 | */ |
michael@0 | 467 | readonly attribute nsISimpleEnumerator headers; |
michael@0 | 468 | |
michael@0 | 469 | /** |
michael@0 | 470 | * A stream from which data appearing in the body of this request can be read. |
michael@0 | 471 | */ |
michael@0 | 472 | readonly attribute nsIInputStream bodyInputStream; |
michael@0 | 473 | }; |
michael@0 | 474 | |
michael@0 | 475 | |
michael@0 | 476 | /** |
michael@0 | 477 | * Represents an HTTP response, as described in RFC 2616, section 6. |
michael@0 | 478 | */ |
michael@0 | 479 | [scriptable, uuid(1acd16c2-dc59-42fa-9160-4f26c43c1c21)] |
michael@0 | 480 | interface nsIHttpResponse : nsISupports |
michael@0 | 481 | { |
michael@0 | 482 | /** |
michael@0 | 483 | * Sets the status line for this. If this method is never called on this, the |
michael@0 | 484 | * status line defaults to "HTTP/", followed by the server's default HTTP |
michael@0 | 485 | * version (e.g. "1.1"), followed by " 200 OK". |
michael@0 | 486 | * |
michael@0 | 487 | * @param httpVersion |
michael@0 | 488 | * the HTTP version of this, as a string (e.g. "1.1"); if null, the server |
michael@0 | 489 | * default is used |
michael@0 | 490 | * @param code |
michael@0 | 491 | * the numeric HTTP status code for this |
michael@0 | 492 | * @param description |
michael@0 | 493 | * a human-readable description of code; may be null if no description is |
michael@0 | 494 | * desired |
michael@0 | 495 | * @throws NS_ERROR_INVALID_ARG |
michael@0 | 496 | * if httpVersion is not a valid HTTP version string, statusCode is greater |
michael@0 | 497 | * than 999, or description contains invalid characters |
michael@0 | 498 | * @throws NS_ERROR_NOT_AVAILABLE |
michael@0 | 499 | * if this response is being processed asynchronously and data has been |
michael@0 | 500 | * written to this response's body, or if seizePower() has been called on |
michael@0 | 501 | * this |
michael@0 | 502 | */ |
michael@0 | 503 | void setStatusLine(in string httpVersion, |
michael@0 | 504 | in unsigned short statusCode, |
michael@0 | 505 | in string description); |
michael@0 | 506 | |
michael@0 | 507 | /** |
michael@0 | 508 | * Sets the specified header in this. |
michael@0 | 509 | * |
michael@0 | 510 | * @param name |
michael@0 | 511 | * the name of the header; must match the field-name production per RFC 2616 |
michael@0 | 512 | * @param value |
michael@0 | 513 | * the value of the header; must match the field-value production per RFC |
michael@0 | 514 | * 2616 |
michael@0 | 515 | * @param merge |
michael@0 | 516 | * when true, if the given header already exists in this, the values passed |
michael@0 | 517 | * to this function will be merged into the existing header, per RFC 2616 |
michael@0 | 518 | * header semantics (except for the Set-Cookie, WWW-Authenticate, and |
michael@0 | 519 | * Proxy-Authenticate headers, which will treat each such merged header as |
michael@0 | 520 | * an additional instance of the header, for real-world compatibility |
michael@0 | 521 | * reasons); when false, replaces any existing header of the given name (if |
michael@0 | 522 | * any exists) with a new header with the specified value |
michael@0 | 523 | * @throws NS_ERROR_INVALID_ARG |
michael@0 | 524 | * if name or value is not a valid header component |
michael@0 | 525 | * @throws NS_ERROR_NOT_AVAILABLE |
michael@0 | 526 | * if this response is being processed asynchronously and data has been |
michael@0 | 527 | * written to this response's body, or if seizePower() has been called on |
michael@0 | 528 | * this |
michael@0 | 529 | */ |
michael@0 | 530 | void setHeader(in string name, in string value, in boolean merge); |
michael@0 | 531 | |
michael@0 | 532 | /** |
michael@0 | 533 | * A stream to which data appearing in the body of this response (or in the |
michael@0 | 534 | * totality of the response if seizePower() is called) should be written. |
michael@0 | 535 | * After this response has been designated as being processed asynchronously, |
michael@0 | 536 | * or after seizePower() has been called on this, subsequent writes will no |
michael@0 | 537 | * longer be buffered and will be written to the underlying transport without |
michael@0 | 538 | * delaying until the entire response is constructed. Write-through may or |
michael@0 | 539 | * may not be synchronous in the implementation, and in any case particular |
michael@0 | 540 | * behavior may not be observable to the HTTP client as intermediate buffers |
michael@0 | 541 | * both in the server socket and in the client may delay written data; be |
michael@0 | 542 | * prepared for delays at any time. |
michael@0 | 543 | * |
michael@0 | 544 | * @throws NS_ERROR_NOT_AVAILABLE |
michael@0 | 545 | * if accessed after this response is fully constructed |
michael@0 | 546 | */ |
michael@0 | 547 | readonly attribute nsIOutputStream bodyOutputStream; |
michael@0 | 548 | |
michael@0 | 549 | /** |
michael@0 | 550 | * Writes a string to the response's output stream. This method is merely a |
michael@0 | 551 | * convenient shorthand for writing the same data to bodyOutputStream |
michael@0 | 552 | * directly. |
michael@0 | 553 | * |
michael@0 | 554 | * @note |
michael@0 | 555 | * This method is only guaranteed to work with ASCII data. |
michael@0 | 556 | * @throws NS_ERROR_NOT_AVAILABLE |
michael@0 | 557 | * if called after this response has been fully constructed |
michael@0 | 558 | */ |
michael@0 | 559 | void write(in string data); |
michael@0 | 560 | |
michael@0 | 561 | /** |
michael@0 | 562 | * Signals that this response is being constructed asynchronously. Requests |
michael@0 | 563 | * are typically completely constructed during nsIHttpRequestHandler.handle; |
michael@0 | 564 | * however, responses which require significant resources (time, memory, |
michael@0 | 565 | * processing) to construct can be created and sent incrementally by calling |
michael@0 | 566 | * this method during the call to nsIHttpRequestHandler.handle. This method |
michael@0 | 567 | * only has this effect when called during nsIHttpRequestHandler.handle; |
michael@0 | 568 | * behavior is undefined if it is called at a later time. It may be called |
michael@0 | 569 | * multiple times with no ill effect, so long as each call occurs before |
michael@0 | 570 | * finish() is called. |
michael@0 | 571 | * |
michael@0 | 572 | * @throws NS_ERROR_UNEXPECTED |
michael@0 | 573 | * if not initially called within a nsIHttpRequestHandler.handle call or if |
michael@0 | 574 | * called after this response has been finished |
michael@0 | 575 | * @throws NS_ERROR_NOT_AVAILABLE |
michael@0 | 576 | * if seizePower() has been called on this |
michael@0 | 577 | */ |
michael@0 | 578 | void processAsync(); |
michael@0 | 579 | |
michael@0 | 580 | /** |
michael@0 | 581 | * Seizes complete control of this response (and its connection) from the |
michael@0 | 582 | * server, allowing raw and unfettered access to data being sent in the HTTP |
michael@0 | 583 | * response. Once this method has been called the only property which may be |
michael@0 | 584 | * accessed without an exception being thrown is bodyOutputStream, and the |
michael@0 | 585 | * only methods which may be accessed without an exception being thrown are |
michael@0 | 586 | * write(), finish(), and seizePower() (which may be called multiple times |
michael@0 | 587 | * without ill effect so long as all calls are otherwise allowed). |
michael@0 | 588 | * |
michael@0 | 589 | * After a successful call, all data subsequently written to the body of this |
michael@0 | 590 | * response is written directly to the corresponding connection. (Previously- |
michael@0 | 591 | * written data is silently discarded.) No status line or headers are sent |
michael@0 | 592 | * before doing so; if the response handler wishes to write such data, it must |
michael@0 | 593 | * do so manually. Data generation completes only when finish() is called; it |
michael@0 | 594 | * is not enough to simply call close() on bodyOutputStream. |
michael@0 | 595 | * |
michael@0 | 596 | * @throws NS_ERROR_NOT_AVAILABLE |
michael@0 | 597 | * if processAsync() has been called on this |
michael@0 | 598 | * @throws NS_ERROR_UNEXPECTED |
michael@0 | 599 | * if finish() has been called on this |
michael@0 | 600 | */ |
michael@0 | 601 | void seizePower(); |
michael@0 | 602 | |
michael@0 | 603 | /** |
michael@0 | 604 | * Signals that construction of this response is complete and that it may be |
michael@0 | 605 | * sent over the network to the client, or if seizePower() has been called |
michael@0 | 606 | * signals that all data has been written and that the underlying connection |
michael@0 | 607 | * may be closed. This method may only be called after processAsync() or |
michael@0 | 608 | * seizePower() has been called. This method is idempotent. |
michael@0 | 609 | * |
michael@0 | 610 | * @throws NS_ERROR_UNEXPECTED |
michael@0 | 611 | * if processAsync() or seizePower() has not already been properly called |
michael@0 | 612 | */ |
michael@0 | 613 | void finish(); |
michael@0 | 614 | }; |