tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsIHttpChannel.idl (20033B)


      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/. */
      5 
      6 #include "nsIChannel.idl"
      7 
      8 interface nsIHttpHeaderVisitor;
      9 interface nsIReferrerInfo;
     10 
     11 %{C++
     12 #include "GeckoProfiler.h"
     13 namespace mozilla::net {
     14 class DictionaryCacheEntry;
     15 }
     16 %}
     17 
     18 [ptr] native DictionaryCacheEntry(mozilla::net::DictionaryCacheEntry);
     19 
     20 native UniqueProfileChunkedBuffer(mozilla::UniquePtr<mozilla::ProfileChunkedBuffer>);
     21 
     22 /**
     23 * nsIHttpChannel
     24 *
     25 * This interface allows for the modification of HTTP request parameters and
     26 * the inspection of the resulting HTTP response status and headers when they
     27 * become available.
     28 */
     29 [builtinclass, scriptable, uuid(c5a4a073-4539-49c7-a3f2-cec3f0619c6c)]
     30 interface nsIHttpChannel : nsIIdentChannel
     31 {
     32    /**************************************************************************
     33     * REQUEST CONFIGURATION
     34     *
     35     * Modifying request parameters after asyncOpen has been called is an error.
     36     */
     37 
     38    /**
     39     * Set/get the HTTP request method (default is "GET").  Both setter and
     40     * getter are case sensitive.
     41     *
     42     * This attribute may only be set before the channel is opened.
     43     *
     44     * NOTE: The data for a "POST" or "PUT" request can be configured via
     45     * nsIUploadChannel; however, after setting the upload data, it may be
     46     * necessary to set the request method explicitly.  The documentation
     47     * for nsIUploadChannel has further details.
     48     *
     49     * @throws NS_ERROR_IN_PROGRESS if set after the channel has been opened.
     50     */
     51    [must_use] attribute ACString requestMethod;
     52 
     53    /**
     54     * Get/set the referrer information.  This contains the referrer (URI) of the
     55     * resource from which this channel's URI was obtained (see RFC2616 section
     56     * 14.36) and the referrer policy applied to the referrer.
     57     *
     58     * This attribute may only be set before the channel is opened.
     59     *
     60     * Setting this attribute will clone new referrerInfo object by default.
     61     *
     62     * NOTE: The channel may silently refuse to set the Referer header if the
     63     * URI does not pass certain security checks (e.g., a "https://" URL will
     64     * never be sent as the referrer for a plaintext HTTP request).  The
     65     * implementation is not required to throw an exception when the referrer
     66     * URI is rejected.
     67     *
     68     * @throws NS_ERROR_IN_PROGRESS if set after the channel has been opened.
     69     * @throws NS_ERROR_FAILURE if used for setting referrer during
     70     *         visitRequestHeaders. Getting the value will not throw.
     71     */
     72    [must_use, infallible] attribute nsIReferrerInfo referrerInfo;
     73 
     74    /**
     75     * Set referrer Info without clone new object.
     76     * Use this api only when you are passing a referrerInfo to the channel with
     77     * 1-1 relationship. Don't use this api if you will reuse the referrer info
     78     * object later. For example when to use:
     79     * channel.setReferrerInfoWithoutClone(new ReferrerInfo());
     80     *
     81     */
     82    [must_use, noscript]
     83    void setReferrerInfoWithoutClone(in nsIReferrerInfo aReferrerInfo);
     84 
     85    /**
     86     * Returns the network protocol used to fetch the resource as identified
     87     * by the ALPN Protocol ID.
     88     *
     89     * @throws NS_ERROR_NOT_AVAILABLE if called before the response
     90     *         has been received (before onStartRequest).
     91     */
     92    [must_use] readonly attribute ACString protocolVersion;
     93 
     94    /**
     95     * size consumed by the response header fields and the response payload body
     96     */
     97    [must_use] readonly attribute uint64_t transferSize;
     98 
     99    /**
    100     * size consumed by the request header fields and the request payload body
    101     */
    102    [must_use] readonly attribute uint64_t requestSize;
    103 
    104    /**
    105     * The size of the message body received by the client,
    106     * after removing any applied content-codings
    107     */
    108    [must_use] readonly attribute uint64_t decodedBodySize;
    109 
    110    /**
    111     * The size in octets of the payload body, prior to removing content-codings
    112     */
    113    [must_use] readonly attribute uint64_t encodedBodySize;
    114 
    115    /**
    116     * Get the value of a particular request header.
    117     *
    118     * @param aHeader
    119     *        The case-insensitive name of the request header to query (e.g.,
    120     *        "Cache-Control").
    121     *
    122     * @return the value of the request header.
    123     * @throws NS_ERROR_NOT_AVAILABLE if the header is not set.
    124     */
    125    [must_use] ACString getRequestHeader(in ACString aHeader);
    126 
    127    /**
    128     * Set the value of a particular request header.
    129     *
    130     * This method allows, for example, the cookies module to add "Cookie"
    131     * headers to the outgoing HTTP request.
    132     *
    133     * This method may only be called before the channel is opened.
    134     *
    135     * @param aHeader
    136     *        The case-insensitive name of the request header to set (e.g.,
    137     *        "Cookie").
    138     * @param aValue
    139     *        The request header value to set (e.g., "X=1").
    140     * @param aMerge
    141     *        If true, the new header value will be merged with any existing
    142     *        values for the specified header.  This flag is ignored if the
    143     *        specified header does not support merging (e.g., the "Content-
    144     *        Type" header can only have one value).  The list of headers for
    145     *        which this flag is ignored is an implementation detail.  If this
    146     *        flag is false, then the header value will be replaced with the
    147     *        contents of |aValue|.
    148     *
    149     * If aValue is empty and aMerge is false, the header will be cleared.
    150     *
    151     * @throws NS_ERROR_IN_PROGRESS if called after the channel has been
    152     *         opened.
    153     * @throws NS_ERROR_FAILURE if called during visitRequestHeaders.
    154     */
    155    [must_use] void setRequestHeader(in ACString aHeader,
    156                                     in ACString aValue,
    157                                     in boolean aMerge);
    158 
    159    /**
    160     * Creates and sets new ReferrerInfo object
    161     * @param aUrl          referrer url
    162     * @param aPolicy       referrer policy of the created object
    163     * @param aSendReferrer indicates if the referrer should not be sent or not
    164     *                      even when it's available.
    165     */
    166    [must_use] void setNewReferrerInfo(in ACString aUrl,
    167                                       in nsIReferrerInfo_ReferrerPolicyIDL aPolicy,
    168                                       in boolean aSendReferrer);
    169 
    170    /**
    171     * Set a request header with empty value.
    172     *
    173     * This should be used with caution in the cases where the behavior of
    174     * setRequestHeader ignoring empty header values is undesirable.
    175     *
    176     * This method may only be called before the channel is opened.
    177     *
    178     * @param aHeader
    179     *        The case-insensitive name of the request header to set (e.g.,
    180     *        "Cookie").
    181     *
    182     * @throws NS_ERROR_IN_PROGRESS if called after the channel has been
    183     *         opened.
    184     * @throws NS_ERROR_FAILURE if called during visitRequestHeaders.
    185     */
    186    [must_use] void setEmptyRequestHeader(in ACString aHeader);
    187 
    188    /**
    189     * Call this method to visit all request headers.  Calling setRequestHeader
    190     * while visiting request headers has undefined behavior.  Don't do it!
    191     *
    192     * @param aVisitor
    193     *        the header visitor instance.
    194     */
    195    [must_use] void visitRequestHeaders(in nsIHttpHeaderVisitor aVisitor);
    196 
    197    /**
    198     * Call this method to visit all non-default (UA-provided) request headers.
    199     * Calling setRequestHeader while visiting request headers has undefined
    200     * behavior. Don't do it!
    201     *
    202     * @param aVisitor
    203     *        the header visitor instance.
    204     */
    205    [must_use]
    206    void visitNonDefaultRequestHeaders(in nsIHttpHeaderVisitor aVisitor);
    207 
    208    /**
    209     * Call this method to see if we need to strip the request body headers
    210     * for the new http channel. This should be called during redirection.
    211     */
    212    [must_use] boolean ShouldStripRequestBodyHeader(in ACString aMethod);
    213 
    214    /**
    215     * This attribute of the channel indicates whether or not
    216     * the underlying HTTP transaction should be honor stored Strict Transport
    217     * Security directives for its principal. It defaults to true. Using
    218     * OCSP to bootstrap the HTTPs is the likely use case for setting it to
    219     * false.
    220     *
    221     * This attribute may only be set before the channel is opened.
    222     *
    223     * @throws NS_ERROR_IN_PROGRESS or NS_ERROR_ALREADY_OPENED
    224     *         if called after the channel has been opened.
    225     */
    226    [must_use] attribute boolean allowSTS;
    227 
    228    /**
    229     * This attribute specifies the number of redirects this channel is allowed
    230     * to make.  If zero, the channel will fail to redirect and will generate
    231     * a NS_ERROR_REDIRECT_LOOP failure status.
    232     *
    233     * NOTE: An HTTP redirect results in a new channel being created.  If the
    234     * new channel supports nsIHttpChannel, then it will be assigned a value
    235     * to its |redirectionLimit| attribute one less than the value of the
    236     * redirected channel's |redirectionLimit| attribute.  The initial value
    237     * for this attribute may be a configurable preference (depending on the
    238     * implementation).
    239     */
    240    [must_use] attribute unsigned long redirectionLimit;
    241 
    242    /**************************************************************************
    243     * RESPONSE INFO
    244     *
    245     * Accessing response info before the onStartRequest event is an error.
    246     */
    247 
    248    /**
    249     * Get the HTTP response code (e.g., 200).
    250     *
    251     * @throws NS_ERROR_NOT_AVAILABLE if called before the response
    252     *         has been received (before onStartRequest).
    253     */
    254    [must_use] readonly attribute unsigned long responseStatus;
    255 
    256    /**
    257     * Get the HTTP response status text (e.g., "OK").
    258     *
    259     * NOTE: This returns the raw (possibly 8-bit) text from the server.  There
    260     * are no assumptions made about the charset of the returned text.  You
    261     * have been warned!
    262     *
    263     * @throws NS_ERROR_NOT_AVAILABLE if called before the response
    264     *         has been received (before onStartRequest).
    265     */
    266    [must_use] readonly attribute ACString responseStatusText;
    267 
    268    /**
    269     * Returns true if the HTTP response code indicates success.  The value of
    270     * nsIRequest::status will be NS_OK even when processing a 404 response
    271     * because a 404 response may include a message body that (in some cases)
    272     * should be shown to the user.
    273     *
    274     * Use this attribute to distinguish server error pages from normal pages,
    275     * instead of comparing the response status manually against the set of
    276     * valid response codes, if that is required by your application.
    277     *
    278     * @throws NS_ERROR_NOT_AVAILABLE if called before the response
    279     *         has been received (before onStartRequest).
    280     */
    281    [must_use] readonly attribute boolean requestSucceeded;
    282 
    283   /** Indicates whether channel should be treated as the main one for the
    284    *  current document.  If manually set to true, will always remain true.  Otherwise,
    285    *  will be true if LOAD_DOCUMENT_URI is set in the channel's loadflags.
    286    */
    287    [must_use] attribute boolean isMainDocumentChannel;
    288 
    289    /**
    290     * Get the value of a particular response header.
    291     *
    292     * @param aHeader
    293     *        The case-insensitive name of the response header to query (e.g.,
    294     *        "Set-Cookie").
    295     *
    296     * @return the value of the response header.
    297     *
    298     * @throws NS_ERROR_NOT_AVAILABLE if called before the response
    299     *         has been received (before onStartRequest) or if the header is
    300     *         not set in the response.
    301     */
    302    [must_use] ACString getResponseHeader(in ACString header);
    303 
    304    /**
    305     * Set the value of a particular response header.
    306     *
    307     * This method allows, for example, the HTML content sink to inform the HTTP
    308     * channel about HTTP-EQUIV headers found in HTML <META> tags.
    309     *
    310     * @param aHeader
    311     *        The case-insensitive name of the response header to set (e.g.,
    312     *        "Cache-control").
    313     * @param aValue
    314     *        The response header value to set (e.g., "no-cache").
    315     * @param aMerge
    316     *        If true, the new header value will be merged with any existing
    317     *        values for the specified header.  This flag is ignored if the
    318     *        specified header does not support merging (e.g., the "Content-
    319     *        Type" header can only have one value).  The list of headers for
    320     *        which this flag is ignored is an implementation detail.  If this
    321     *        flag is false, then the header value will be replaced with the
    322     *        contents of |aValue|.
    323     *
    324     * If aValue is empty and aMerge is false, the header will be cleared.
    325     *
    326     * @throws NS_ERROR_NOT_AVAILABLE if called before the response
    327     *         has been received (before onStartRequest).
    328     * @throws NS_ERROR_ILLEGAL_VALUE if changing the value of this response
    329     *         header is not allowed.
    330     * @throws NS_ERROR_FAILURE if called during visitResponseHeaders,
    331     *         VisitOriginalResponseHeaders or getOriginalResponseHeader.
    332     */
    333    [must_use] void setResponseHeader(in ACString header,
    334                                      in ACString value,
    335                                      in boolean merge);
    336 
    337    /**
    338     * Call this method to visit all response headers.  Calling
    339     * setResponseHeader while visiting response headers has undefined
    340     * behavior.  Don't do it!
    341     *
    342     * @param aVisitor
    343     *        the header visitor instance.
    344     *
    345     * @throws NS_ERROR_NOT_AVAILABLE if called before the response
    346     *         has been received (before onStartRequest).
    347     */
    348    [must_use] void visitResponseHeaders(in nsIHttpHeaderVisitor aVisitor);
    349 
    350     /**
    351     * Get the value(s) of a particular response header in the form and order
    352     * it has been received from the remote peer. There can be multiple headers
    353     * with the same name.
    354     *
    355     * @param aHeader
    356     *        The case-insensitive name of the response header to query (e.g.,
    357     *        "Set-Cookie").
    358     *
    359     * @param aVisitor
    360     *        the header visitor instance.
    361     *
    362     * @throws NS_ERROR_NOT_AVAILABLE if called before the response
    363     *         has been received (before onStartRequest) or if the header is
    364     *         not set in the response.
    365     */
    366    [must_use] void getOriginalResponseHeader(in ACString aHeader,
    367                                              in nsIHttpHeaderVisitor aVisitor);
    368 
    369    /**
    370     * Call this method to visit all response headers in the form and order as
    371     * they have been received from the remote peer.
    372     * Calling setResponseHeader while visiting response headers has undefined
    373     * behavior.  Don't do it!
    374     *
    375     * @param aVisitor
    376     *        the header visitor instance.
    377     *
    378     * @throws NS_ERROR_NOT_AVAILABLE if called before the response
    379     *         has been received (before onStartRequest).
    380     */
    381    [must_use]
    382    void visitOriginalResponseHeaders(in nsIHttpHeaderVisitor aVisitor);
    383 
    384    /**
    385     * Returns true if the server sent a "Cache-Control: no-store" response
    386     * header.
    387     *
    388     * @throws NS_ERROR_NOT_AVAILABLE if called before the response
    389     *         has been received (before onStartRequest).
    390     */
    391    [must_use] boolean isNoStoreResponse();
    392 
    393    /**
    394     * Returns true if the server sent the equivalent of a "Cache-control:
    395     * no-cache" response header.  Equivalent response headers include:
    396     * "Pragma: no-cache", "Expires: 0", and "Expires" with a date value
    397     * in the past relative to the value of the "Date" header.
    398     *
    399     * @throws NS_ERROR_NOT_AVAILABLE if called before the response
    400     *         has been received (before onStartRequest).
    401     */
    402    [must_use] boolean isNoCacheResponse();
    403 
    404    /**
    405     * Instructs the channel to immediately redirect to a new destination.
    406     * Can only be called on channels that have not yet called their
    407     * listener's OnStartRequest(). Generally that means the latest time
    408     * this can be used is one of:
    409     *    "http-on-examine-response"
    410     *    "http-on-examine-merged-response"
    411     *    "http-on-examine-cached-response"
    412     *
    413     * When non-null URL is set before AsyncOpen:
    414     *  we attempt to redirect to the targetURI before we even start building
    415     *  and sending the request to the cache or the origin server.
    416     *  If the redirect is vetoed, we fail the channel.
    417     *
    418     * When set between AsyncOpen and first call to OnStartRequest being called:
    419     *  we attempt to redirect before we start delivery of network or cached
    420     *  response to the listener.  If vetoed, we continue with delivery of
    421     *  the original content to the channel listener.
    422     *
    423     * When passed aTargetURI is null the channel behaves normally (can be
    424     * rewritten).
    425     *
    426     * This method provides no explicit conflict resolution. The last
    427     * caller to call it wins.
    428     *
    429     * @throws NS_ERROR_NOT_AVAILABLE if called after the channel has already
    430     *         started to deliver the content to its listener.
    431     */
    432    [must_use] void redirectTo(in nsIURI aTargetURI);
    433 
    434    /**
    435     * Flags a channel to be upgraded to HTTPS.
    436     *
    437     * Upgrading to a secure channel must happen before or during
    438     * "http-on-modify-request". If redirectTo is called early as well, it
    439     * will win and upgradeToSecure will be a no-op.
    440     *
    441     * @throws NS_ERROR_NOT_AVAILABLE if called after the channel has already
    442     *         started to deliver the content to its listener.
    443     */
    444    [must_use] void upgradeToSecure();
    445 
    446    /**
    447     * Identifies the request context for this load.
    448     */
    449    [noscript, must_use] attribute uint64_t requestContextID;
    450 
    451    /**
    452     * ID of the top-level document's inner window.  Identifies the content
    453     * this channels is being load in.
    454     */
    455    [must_use] attribute uint64_t topLevelContentWindowId;
    456 
    457    /**
    458     * ID of the browser for this channel.
    459     *
    460     * NOTE: The setter of this attribute is currently for xpcshell test only.
    461     *       Don't alter it otherwise.
    462     */
    463    [must_use] attribute uint64_t browserId;
    464 
    465    /**
    466     * In e10s, the information that the CORS response blocks the load is in the
    467     * parent, which doesn't know the true window id of the request, so we may
    468     * need to proxy the request to the child.
    469     *
    470     * @param aMessage
    471     *        The message to print in the console.
    472     *
    473     * @param aCategory
    474     *        The category under which the message should be displayed.
    475     *
    476     * @param aIsWarning
    477     *        When true, this is a warning message.
    478     */
    479    void logBlockedCORSRequest(in AString aMessage,
    480                               in ACString aCategory,
    481                               in boolean aIsWarning);
    482 
    483    void logMimeTypeMismatch(in ACString aMessageName,
    484                             in boolean aWarning,
    485                             in AString aURL,
    486                             in AString aContentType);
    487 
    488    [notxpcom, nostdcall] void setSource(in UniqueProfileChunkedBuffer aSource);
    489 
    490    [must_use] attribute AString classicScriptHintCharset;
    491 
    492    [must_use] attribute AString documentCharacterSet;
    493 
    494    /**
    495     * Update the requestObserversCalled boolean flag.
    496     *
    497     * Used by WebDriver BiDi network interception to modify properties of the
    498     * request such as `method` or `body` as late as possible.
    499     */
    500    [must_use] attribute boolean requestObserversCalled;
    501 
    502    /**
    503     * Used to indicate that user agent was overridden or override was reset
    504     * and user agent on the channel is outdated.
    505     */
    506    [noscript, must_use] attribute boolean isUserAgentHeaderOutdated;
    507    /**
    508     * Dictionary for decompression, if any
    509     */
    510    [noscript] attribute DictionaryCacheEntry decompressDictionary;
    511 };