1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include
"nsIChannel.idl"
8 interface nsIHttpHeaderVisitor
;
9 interface nsIReferrerInfo
;
12 #include
"GeckoProfiler.h"
15 native UniqueProfileChunkedBuffer
(mozilla
::UniquePtr
<mozilla
::ProfileChunkedBuffer
>);
20 * This interface allows for the modification of HTTP request parameters and
21 * the inspection of the resulting HTTP response status and headers when they
24 [builtinclass
, scriptable
, uuid(c5a4a073
-4539-49c7
-a3f2
-cec3f0619c6c
)]
25 interface nsIHttpChannel
: nsIIdentChannel
27 /**************************************************************************
28 * REQUEST CONFIGURATION
30 * Modifying request parameters after asyncOpen has been called is an error.
34 * Set/get the HTTP request method (default is "GET"). Both setter and
35 * getter are case sensitive.
37 * This attribute may only be set before the channel is opened.
39 * NOTE: The data for a "POST" or "PUT" request can be configured via
40 * nsIUploadChannel; however, after setting the upload data, it may be
41 * necessary to set the request method explicitly. The documentation
42 * for nsIUploadChannel has further details.
44 * @throws NS_ERROR_IN_PROGRESS if set after the channel has been opened.
46 [must_use
] attribute ACString requestMethod
;
49 * Get/set the referrer information. This contains the referrer (URI) of the
50 * resource from which this channel's URI was obtained (see RFC2616 section
51 * 14.36) and the referrer policy applied to the referrer.
53 * This attribute may only be set before the channel is opened.
55 * Setting this attribute will clone new referrerInfo object by default.
57 * NOTE: The channel may silently refuse to set the Referer header if the
58 * URI does not pass certain security checks (e.g., a "https://" URL will
59 * never be sent as the referrer for a plaintext HTTP request). The
60 * implementation is not required to throw an exception when the referrer
63 * @throws NS_ERROR_IN_PROGRESS if set after the channel has been opened.
64 * @throws NS_ERROR_FAILURE if used for setting referrer during
65 * visitRequestHeaders. Getting the value will not throw.
67 [must_use
, infallible
] attribute nsIReferrerInfo referrerInfo
;
70 * Set referrer Info without clone new object.
71 * Use this api only when you are passing a referrerInfo to the channel with
72 * 1-1 relationship. Don't use this api if you will reuse the referrer info
73 * object later. For example when to use:
74 * channel.setReferrerInfoWithoutClone(new ReferrerInfo());
78 void setReferrerInfoWithoutClone
(in nsIReferrerInfo aReferrerInfo
);
81 * Returns the network protocol used to fetch the resource as identified
82 * by the ALPN Protocol ID.
84 * @throws NS_ERROR_NOT_AVAILABLE if called before the response
85 * has been received (before onStartRequest).
87 [must_use
] readonly attribute ACString protocolVersion
;
90 * size consumed by the response header fields and the response payload body
92 [must_use
] readonly attribute uint64_t transferSize
;
95 * size consumed by the request header fields and the request payload body
97 [must_use
] readonly attribute uint64_t requestSize
;
100 * The size of the message body received by the client,
101 * after removing any applied content-codings
103 [must_use
] readonly attribute uint64_t decodedBodySize
;
106 * The size in octets of the payload body, prior to removing content-codings
108 [must_use
] readonly attribute uint64_t encodedBodySize
;
111 * Get the value of a particular request header.
114 * The case-insensitive name of the request header to query (e.g.,
117 * @return the value of the request header.
118 * @throws NS_ERROR_NOT_AVAILABLE if the header is not set.
120 [must_use
] ACString getRequestHeader
(in ACString aHeader
);
123 * Set the value of a particular request header.
125 * This method allows, for example, the cookies module to add "Cookie"
126 * headers to the outgoing HTTP request.
128 * This method may only be called before the channel is opened.
131 * The case-insensitive name of the request header to set (e.g.,
134 * The request header value to set (e.g., "X=1").
136 * If true, the new header value will be merged with any existing
137 * values for the specified header. This flag is ignored if the
138 * specified header does not support merging (e.g., the "Content-
139 * Type" header can only have one value). The list of headers for
140 * which this flag is ignored is an implementation detail. If this
141 * flag is false, then the header value will be replaced with the
142 * contents of |aValue|.
144 * If aValue is empty and aMerge is false, the header will be cleared.
146 * @throws NS_ERROR_IN_PROGRESS if called after the channel has been
148 * @throws NS_ERROR_FAILURE if called during visitRequestHeaders.
150 [must_use
] void setRequestHeader
(in ACString aHeader
,
155 * Creates and sets new ReferrerInfo object
156 * @param aUrl referrer url
157 * @param aPolicy referrer policy of the created object
158 * @param aSendReferrer indicates if the referrer should not be sent or not
159 * even when it's available.
161 [must_use
] void setNewReferrerInfo
(in ACString aUrl
,
162 in nsIReferrerInfo_ReferrerPolicyIDL aPolicy
,
163 in boolean aSendReferrer
);
166 * Set a request header with empty value.
168 * This should be used with caution in the cases where the behavior of
169 * setRequestHeader ignoring empty header values is undesirable.
171 * This method may only be called before the channel is opened.
174 * The case-insensitive name of the request header to set (e.g.,
177 * @throws NS_ERROR_IN_PROGRESS if called after the channel has been
179 * @throws NS_ERROR_FAILURE if called during visitRequestHeaders.
181 [must_use
] void setEmptyRequestHeader
(in ACString aHeader
);
184 * Call this method to visit all request headers. Calling setRequestHeader
185 * while visiting request headers has undefined behavior. Don't do it!
188 * the header visitor instance.
190 [must_use
] void visitRequestHeaders
(in nsIHttpHeaderVisitor aVisitor
);
193 * Call this method to visit all non-default (UA-provided) request headers.
194 * Calling setRequestHeader while visiting request headers has undefined
195 * behavior. Don't do it!
198 * the header visitor instance.
201 void visitNonDefaultRequestHeaders
(in nsIHttpHeaderVisitor aVisitor
);
204 * Call this method to see if we need to strip the request body headers
205 * for the new http channel. This should be called during redirection.
207 [must_use
] bool ShouldStripRequestBodyHeader
(in ACString aMethod
);
210 * This attribute of the channel indicates whether or not
211 * the underlying HTTP transaction should be honor stored Strict Transport
212 * Security directives for its principal. It defaults to true. Using
213 * OCSP to bootstrap the HTTPs is the likely use case for setting it to
216 * This attribute may only be set before the channel is opened.
218 * @throws NS_ERROR_IN_PROGRESS or NS_ERROR_ALREADY_OPENED
219 * if called after the channel has been opened.
221 [must_use
] attribute
boolean allowSTS
;
224 * This attribute specifies the number of redirects this channel is allowed
225 * to make. If zero, the channel will fail to redirect and will generate
226 * a NS_ERROR_REDIRECT_LOOP failure status.
228 * NOTE: An HTTP redirect results in a new channel being created. If the
229 * new channel supports nsIHttpChannel, then it will be assigned a value
230 * to its |redirectionLimit| attribute one less than the value of the
231 * redirected channel's |redirectionLimit| attribute. The initial value
232 * for this attribute may be a configurable preference (depending on the
235 [must_use
] attribute
unsigned long redirectionLimit
;
237 /**************************************************************************
240 * Accessing response info before the onStartRequest event is an error.
244 * Get the HTTP response code (e.g., 200).
246 * @throws NS_ERROR_NOT_AVAILABLE if called before the response
247 * has been received (before onStartRequest).
249 [must_use
] readonly attribute
unsigned long responseStatus
;
252 * Get the HTTP response status text (e.g., "OK").
254 * NOTE: This returns the raw (possibly 8-bit) text from the server. There
255 * are no assumptions made about the charset of the returned text. You
258 * @throws NS_ERROR_NOT_AVAILABLE if called before the response
259 * has been received (before onStartRequest).
261 [must_use
] readonly attribute ACString responseStatusText
;
264 * Returns true if the HTTP response code indicates success. The value of
265 * nsIRequest::status will be NS_OK even when processing a 404 response
266 * because a 404 response may include a message body that (in some cases)
267 * should be shown to the user.
269 * Use this attribute to distinguish server error pages from normal pages,
270 * instead of comparing the response status manually against the set of
271 * valid response codes, if that is required by your application.
273 * @throws NS_ERROR_NOT_AVAILABLE if called before the response
274 * has been received (before onStartRequest).
276 [must_use
] readonly attribute
boolean requestSucceeded
;
278 /** Indicates whether channel should be treated as the main one for the
279 * current document. If manually set to true, will always remain true. Otherwise,
280 * will be true if LOAD_DOCUMENT_URI is set in the channel's loadflags.
282 [must_use
] attribute
boolean isMainDocumentChannel
;
285 * Get the value of a particular response header.
288 * The case-insensitive name of the response header to query (e.g.,
291 * @return the value of the response header.
293 * @throws NS_ERROR_NOT_AVAILABLE if called before the response
294 * has been received (before onStartRequest) or if the header is
295 * not set in the response.
297 [must_use
] ACString getResponseHeader
(in ACString header
);
300 * Set the value of a particular response header.
302 * This method allows, for example, the HTML content sink to inform the HTTP
303 * channel about HTTP-EQUIV headers found in HTML <META> tags.
306 * The case-insensitive name of the response header to set (e.g.,
309 * The response header value to set (e.g., "no-cache").
311 * If true, the new header value will be merged with any existing
312 * values for the specified header. This flag is ignored if the
313 * specified header does not support merging (e.g., the "Content-
314 * Type" header can only have one value). The list of headers for
315 * which this flag is ignored is an implementation detail. If this
316 * flag is false, then the header value will be replaced with the
317 * contents of |aValue|.
319 * If aValue is empty and aMerge is false, the header will be cleared.
321 * @throws NS_ERROR_NOT_AVAILABLE if called before the response
322 * has been received (before onStartRequest).
323 * @throws NS_ERROR_ILLEGAL_VALUE if changing the value of this response
324 * header is not allowed.
325 * @throws NS_ERROR_FAILURE if called during visitResponseHeaders,
326 * VisitOriginalResponseHeaders or getOriginalResponseHeader.
328 [must_use
] void setResponseHeader
(in ACString header
,
333 * Call this method to visit all response headers. Calling
334 * setResponseHeader while visiting response headers has undefined
335 * behavior. Don't do it!
338 * the header visitor instance.
340 * @throws NS_ERROR_NOT_AVAILABLE if called before the response
341 * has been received (before onStartRequest).
343 [must_use
] void visitResponseHeaders
(in nsIHttpHeaderVisitor aVisitor
);
346 * Get the value(s) of a particular response header in the form and order
347 * it has been received from the remote peer. There can be multiple headers
348 * with the same name.
351 * The case-insensitive name of the response header to query (e.g.,
355 * the header visitor instance.
357 * @throws NS_ERROR_NOT_AVAILABLE if called before the response
358 * has been received (before onStartRequest) or if the header is
359 * not set in the response.
361 [must_use
] void getOriginalResponseHeader
(in ACString aHeader
,
362 in nsIHttpHeaderVisitor aVisitor
);
365 * Call this method to visit all response headers in the form and order as
366 * they have been received from the remote peer.
367 * Calling setResponseHeader while visiting response headers has undefined
368 * behavior. Don't do it!
371 * the header visitor instance.
373 * @throws NS_ERROR_NOT_AVAILABLE if called before the response
374 * has been received (before onStartRequest).
377 void visitOriginalResponseHeaders
(in nsIHttpHeaderVisitor aVisitor
);
380 * Returns true if the server sent a "Cache-Control: no-store" response
383 * @throws NS_ERROR_NOT_AVAILABLE if called before the response
384 * has been received (before onStartRequest).
386 [must_use
] boolean isNoStoreResponse
();
389 * Returns true if the server sent the equivalent of a "Cache-control:
390 * no-cache" response header. Equivalent response headers include:
391 * "Pragma: no-cache", "Expires: 0", and "Expires" with a date value
392 * in the past relative to the value of the "Date" header.
394 * @throws NS_ERROR_NOT_AVAILABLE if called before the response
395 * has been received (before onStartRequest).
397 [must_use
] boolean isNoCacheResponse
();
400 * Returns true if the server sent a "Cache-Control: private" response
403 * @throws NS_ERROR_NOT_AVAILABLE if called before the response
404 * has been received (before onStartRequest).
406 [must_use
] boolean isPrivateResponse
();
409 * Instructs the channel to immediately redirect to a new destination.
410 * Can only be called on channels that have not yet called their
411 * listener's OnStartRequest(). Generally that means the latest time
412 * this can be used is one of:
413 * "http-on-examine-response"
414 * "http-on-examine-merged-response"
415 * "http-on-examine-cached-response"
417 * When non-null URL is set before AsyncOpen:
418 * we attempt to redirect to the targetURI before we even start building
419 * and sending the request to the cache or the origin server.
420 * If the redirect is vetoed, we fail the channel.
422 * When set between AsyncOpen and first call to OnStartRequest being called:
423 * we attempt to redirect before we start delivery of network or cached
424 * response to the listener. If vetoed, we continue with delivery of
425 * the original content to the channel listener.
427 * When passed aTargetURI is null the channel behaves normally (can be
430 * This method provides no explicit conflict resolution. The last
431 * caller to call it wins.
433 * @throws NS_ERROR_NOT_AVAILABLE if called after the channel has already
434 * started to deliver the content to its listener.
436 [must_use
] void redirectTo
(in nsIURI aTargetURI
);
439 * Flags a channel to be upgraded to HTTPS.
441 * Upgrading to a secure channel must happen before or during
442 * "http-on-modify-request". If redirectTo is called early as well, it
443 * will win and upgradeToSecure will be a no-op.
445 * @throws NS_ERROR_NOT_AVAILABLE if called after the channel has already
446 * started to deliver the content to its listener.
448 [must_use
] void upgradeToSecure
();
451 * Identifies the request context for this load.
453 [noscript
, must_use
] attribute uint64_t requestContextID
;
456 * ID of the top-level document's inner window. Identifies the content
457 * this channels is being load in.
459 [must_use
] attribute uint64_t topLevelContentWindowId
;
462 * ID of the browser for this channel.
464 * NOTE: The setter of this attribute is currently for xpcshell test only.
465 * Don't alter it otherwise.
467 [must_use
] attribute uint64_t browserId
;
470 * In e10s, the information that the CORS response blocks the load is in the
471 * parent, which doesn't know the true window id of the request, so we may
472 * need to proxy the request to the child.
475 * The message to print in the console.
478 * The category under which the message should be displayed.
481 * When true, this is a warning message.
483 void logBlockedCORSRequest
(in AString aMessage
,
484 in ACString aCategory
,
485 in boolean aIsWarning
);
487 void logMimeTypeMismatch
(in ACString aMessageName
,
490 in AString aContentType
);
492 [notxpcom
, nostdcall
] void setSource
(in UniqueProfileChunkedBuffer aSource
);
494 [must_use
] attribute AString classicScriptHintCharset
;
496 [must_use
] attribute AString documentCharacterSet
;