/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"

%{C++
#include "nsTArray.h"
class nsCString;
%}
[ptr] native StringArray(nsTArray<nsCString>);

interface nsISocketTransport;
interface nsIAsyncInputStream;
interface nsIAsyncOutputStream;
interface nsIURI;
interface nsIProxyInfo;

/**
 * The callback interface for nsIHttpChannelInternal::HTTPUpgrade()
 */

[scriptable, uuid(4b967b6d-cd1c-49ae-a457-23ff76f5a2e8)]
interface nsIHttpUpgradeListener : nsISupports
{
    void onTransportAvailable(in nsISocketTransport   aTransport,
                              in nsIAsyncInputStream  aSocketIn,
                              in nsIAsyncOutputStream aSocketOut);
};

/**
 * Dumping ground for http.  This interface will never be frozen.  If you are
 * using any feature exposed by this interface, be aware that this interface
 * will change and you will be broken.  You have been warned.
 */
[scriptable, uuid(74d13d41-85cd-490f-9942-300d0c01c726)]
interface nsIHttpChannelInternal : nsISupports
{
    /**
     * An http channel can own a reference to the document URI
     */
    attribute nsIURI documentURI;

    /**
     * Get the major/minor version numbers for the request
     */
    void getRequestVersion(out unsigned long major, out unsigned long minor);

    /**
     * Get the major/minor version numbers for the response
     */
    void getResponseVersion(out unsigned long major, out unsigned long minor);

    /**
     * Helper method to set a cookie with a consumer-provided
     * cookie header, _but_ using the channel's other information
     * (URI's, prompters, date headers etc).
     *
     * @param aCookieHeader
     *        The cookie header to be parsed.
     */
    void setCookie(in string aCookieHeader);

    /**
     * Setup this channel as an application cache fallback channel.
     */
    void setupFallbackChannel(in string aFallbackKey);

    /**
     * Force relevant cookies to be sent with this load even if normally they
     * wouldn't be.
     */
    attribute boolean forceAllowThirdPartyCookie;

    /**
     * True iff the channel has been canceled.
     */
    readonly attribute boolean canceled;

    /**
     * External handlers may set this to true to notify the channel
     * that it is open on behalf of a download.
     */
    attribute boolean channelIsForDownload;

    /**
     * The local IP address to which this channel is bound, in the
     * format produced by PR_NetAddrToString. May be IPv4 or IPv6.
     * Note: in the presence of NAT, this may not be the same as the
     * address that the remote host thinks it's talking to.
     *
     * May throw NS_ERROR_NOT_AVAILABLE if accessed when the channel's
     * endpoints are not yet determined, or in any case when
     * nsIHttpActivityObserver.isActive is false. See bugs 534698 and 526207.
     */
    readonly attribute AUTF8String localAddress;

    /**
     * The local port number to which this channel is bound.
     *
     * May throw NS_ERROR_NOT_AVAILABLE if accessed when the channel's
     * endpoints are not yet determined, or in any case when
     * nsIHttpActivityObserver.isActive is false. See bugs 534698 and 526207.
     */
    readonly attribute int32_t localPort;

    /**
     * The IP address of the remote host that this channel is
     * connected to, in the format produced by PR_NetAddrToString.
     *
     * May throw NS_ERROR_NOT_AVAILABLE if accessed when the channel's
     * endpoints are not yet determined, or in any case when
     * nsIHttpActivityObserver.isActive is false. See bugs 534698 and 526207.
     */
    readonly attribute AUTF8String remoteAddress;

    /**
     * The remote port number that this channel is connected to.
     *
     * May throw NS_ERROR_NOT_AVAILABLE if accessed when the channel's
     * endpoints are not yet determined, or in any case when
     * nsIHttpActivityObserver.isActive is false. See bugs 534698 and 526207.
     */
    readonly attribute int32_t remotePort;

    /**
     * Transfer chain of redirected cache-keys.
     */
    [noscript] void setCacheKeysRedirectChain(in StringArray cacheKeys);

    /**
     * HTTPUpgrade allows for the use of HTTP to bootstrap another protocol
     * via the RFC 2616 Upgrade request header in conjunction with a 101 level
     * response. The nsIHttpUpgradeListener will have its 
     * onTransportAvailable() method invoked if a matching 101 is processed.
     * The arguments to onTransportAvailable provide the new protocol the low
     * level tranport streams that are no longer used by HTTP.
     *
     * The onStartRequest and onStopRequest events are still delivered and the
     * listener gets full control over the socket if and when onTransportAvailable
     * is delievered.
     *
     * @param aProtocolName
     *        The value of the HTTP Upgrade request header
     * @param aListener
     *        The callback object used to handle a successful upgrade
     */
    void HTTPUpgrade(in ACString aProtocolName,
                     in nsIHttpUpgradeListener aListener);

    /**
     * Enable/Disable Spdy negotiation on per channel basis.
     * The network.http.spdy.enabled preference is still a pre-requisite
     * for starting spdy.
     */
    attribute boolean allowSpdy;

    /**
     * Set (e.g., by the docshell) to indicate whether or not the channel
     * corresponds to content that should be given a degree of network exclusivity
     * with respect to other members of its load group.
     * Examples are js from the HTML head and css which are latency
     * sensitive and should not compete with images for bandwidth. Default false.
     */
    attribute boolean loadAsBlocking;

    /**
     * If set, this channel will load in parallel with the rest of the load
     * group even if a blocking subset of the group would normally be given
     * exclusivity. Default false.
     */
    attribute boolean loadUnblocked;
};
