コード例 #1
0
        internal HttpWebResponse(
            Uri responseUri,
            string verb,
            CoreResponseData coreData,
            string mediaType,
            bool usesProxySemantics)
        {
            m_Uri                = responseUri;
            m_Verb               = verb;
            m_MediaType          = mediaType;
            m_UsesProxySemantics = usesProxySemantics;

            m_ConnectStream       = coreData.m_ConnectStream;
            m_HttpResponseHeaders = coreData.m_ResponseHeaders;
            m_ContentLength       = coreData.m_ContentLength;
            m_StatusCode          = coreData.m_StatusCode;
            m_StatusDescription   = coreData.m_StatusDescription;
            m_Version             = coreData.m_Version;

            // handle Content-Location header, by combining it with the orginal request.
            string contentLocation = m_HttpResponseHeaders[HttpKnownHeaderNames.ContentLocation];

            if (contentLocation != null)
            {
                try {
                    m_Uri = new Uri(m_Uri, contentLocation);
                } catch (Exception e) {
                    GlobalLog.Assert(false, "Exception on Uri parsing", e.ToString());
                }
            }
        }
コード例 #2
0
        public WebSocketConnectionStream(ConnectStream connectStream, string connectionGroupName)
            : base(new WebSocketConnection(connectStream.Connection), false)
        {
            Contract.Assert(connectStream != null,
                "'connectStream' MUST NOT be NULL.");
            Contract.Assert(connectStream.Connection != null,
                "'connectStream.Conection' MUST NOT be NULL.");
            Contract.Assert(connectStream.Connection.NetworkStream != null,
                "'connectStream.Conection.NetworkStream' MUST NOT be NULL.");
            Contract.Assert(!string.IsNullOrEmpty(connectionGroupName), 
                "connectionGroupName should not be null or empty.");

            m_ConnectStream = connectStream;
            m_ConnectionGroupName = connectionGroupName;
            m_CloseConnectStreamLock = new object();
            // Make sure we don't short circuit for TlsStream or custom NetworkStream implementations
            m_IsFastPathAllowed = m_ConnectStream.Connection.NetworkStream.GetType() == s_NetworkStreamType;

            if (WebSocketBase.LoggingEnabled)
            {
                Logging.Associate(Logging.WebSockets, this, m_ConnectStream.Connection);
            }

            ConsumeConnectStreamBuffer(connectStream);
        }
コード例 #3
0
        public WebSocketConnectionStream(ConnectStream connectStream, string connectionGroupName)
            : base(new WebSocketConnection(connectStream.Connection), false)
        {
            Contract.Assert(connectStream != null,
                            "'connectStream' MUST NOT be NULL.");
            Contract.Assert(connectStream.Connection != null,
                            "'connectStream.Conection' MUST NOT be NULL.");
            Contract.Assert(connectStream.Connection.NetworkStream != null,
                            "'connectStream.Conection.NetworkStream' MUST NOT be NULL.");
            Contract.Assert(!string.IsNullOrEmpty(connectionGroupName),
                            "connectionGroupName should not be null or empty.");

            m_ConnectStream          = connectStream;
            m_ConnectionGroupName    = connectionGroupName;
            m_CloseConnectStreamLock = new object();
            // Make sure we don't short circuit for TlsStream or custom NetworkStream implementations
            m_IsFastPathAllowed = m_ConnectStream.Connection.NetworkStream.GetType() == s_NetworkStreamType;

            if (WebSocketBase.LoggingEnabled)
            {
                Logging.Associate(Logging.WebSockets, this, m_ConnectStream.Connection);
            }

            ConsumeConnectStreamBuffer(connectStream);
        }
コード例 #4
0
        internal void Abort()
        {
            ConnectStream chkConnectStream = m_ConnectStream;

            if (chkConnectStream != null)
            {
                chkConnectStream.Abort();
            }
        }
コード例 #5
0
        /*++
         *
         *  Close - Closes the Response after the use.
         *
         *  This causes the read stream to be closed.
         *
         * --*/

        /// <include file='doc\HttpWebResponse.uex' path='docs/doc[@for="HttpWebResponse.Close"]/*' />
        public override void Close()
        {
            ConnectStream chkConnectStream = m_ConnectStream;

            if (chkConnectStream != null)
            {
                chkConnectStream.Close();
            }
        }
        internal unsafe HttpResponseStreamAsyncResult(object asyncObject, object userState, AsyncCallback callback, byte[] buffer, int offset, int size, bool chunked, bool sentHeaders) : base(asyncObject, userState, callback)
        {
            this.m_SentHeaders = sentHeaders;
            Overlapped overlapped = new Overlapped {
                AsyncResult = this
            };

            if (size == 0)
            {
                this.m_DataChunks  = null;
                this.m_pOverlapped = overlapped.Pack(s_IOCallback, null);
            }
            else
            {
                this.m_DataChunks = new UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK[chunked ? 3 : 1];
                object[] userData = new object[1 + this.m_DataChunks.Length];
                userData[this.m_DataChunks.Length] = this.m_DataChunks;
                int    num = 0;
                byte[] arr = null;
                if (chunked)
                {
                    arr = ConnectStream.GetChunkHeader(size, out num);
                    this.m_DataChunks[0] = new UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK();
                    this.m_DataChunks[0].DataChunkType = UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory;
                    this.m_DataChunks[0].BufferLength  = (uint)(arr.Length - num);
                    userData[0]          = arr;
                    this.m_DataChunks[1] = new UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK();
                    this.m_DataChunks[1].DataChunkType = UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory;
                    this.m_DataChunks[1].BufferLength  = (uint)size;
                    userData[1]          = buffer;
                    this.m_DataChunks[2] = new UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK();
                    this.m_DataChunks[2].DataChunkType = UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory;
                    this.m_DataChunks[2].BufferLength  = (uint)NclConstants.CRLF.Length;
                    userData[2] = NclConstants.CRLF;
                }
                else
                {
                    this.m_DataChunks[0] = new UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK();
                    this.m_DataChunks[0].DataChunkType = UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory;
                    this.m_DataChunks[0].BufferLength  = (uint)size;
                    userData[0] = buffer;
                }
                this.m_pOverlapped = overlapped.Pack(s_IOCallback, userData);
                if (chunked)
                {
                    this.m_DataChunks[0].pBuffer = (byte *)Marshal.UnsafeAddrOfPinnedArrayElement(arr, num);
                    this.m_DataChunks[1].pBuffer = (byte *)Marshal.UnsafeAddrOfPinnedArrayElement(buffer, offset);
                    this.m_DataChunks[2].pBuffer = (byte *)Marshal.UnsafeAddrOfPinnedArrayElement(NclConstants.CRLF, 0);
                }
                else
                {
                    this.m_DataChunks[0].pBuffer = (byte *)Marshal.UnsafeAddrOfPinnedArrayElement(buffer, offset);
                }
            }
        }
コード例 #7
0
        /*++
         *
         *  Close - Closes the Response after the use.
         *
         *  This causes the read stream to be closed.
         *
         * --*/

        public override void Close()
        {
            if (Logging.On)
            {
                Logging.Enter(Logging.Web, this, "Close", "");
            }
            if (!m_disposed)
            {
                m_disposed = true;
                try
                {
                    Stream   stream   = m_ConnectStream;
                    ICloseEx icloseEx = stream as ICloseEx;
                    if (icloseEx != null)
                    {
                        icloseEx.CloseEx(CloseExState.Normal /* | CloseExState.Silent */);
                    }
                    else if (stream != null)
                    {
                        stream.Close();
                    }
                }
                finally
                {
                    if (this.IsWebSocketResponse)
                    {
                        ConnectStream connectStream = m_ConnectStream as ConnectStream;
                        if (connectStream != null && connectStream.Connection != null)
                        {
                            connectStream.Connection.ServicePoint.CloseConnectionGroup(ConnectionGroupName);
                        }
                    }
                }
            }
            if (Logging.On)
            {
                Logging.Exit(Logging.Web, this, "Close", "");
            }
        }
コード例 #8
0
        /*++
         *
         *  ResponseStream - Return the response stream.
         *
         *  This property returns the response stream for this response. The
         *  response stream will do de-chunking, etc. as needed.
         *
         *  Input: Nothing. Property is readonly.
         *
         *  Returns: Response stream for response.
         *
         * --*/


        /// <devdoc>
        ///    <para>Gets the stream used for reading the body of the response from the
        ///       server.</para>
        /// </devdoc>
        public override Stream GetResponseStream()
        {
            if (Logging.On)
            {
                Logging.Enter(Logging.Web, this, "GetResponseStream", "");
            }
            CheckDisposed();
            if (Logging.On)
            {
                Logging.PrintInfo(Logging.Web, "ContentLength=" + m_ContentLength);
            }

            Stream result;

            if (m_IsWebSocketResponse && m_StatusCode == HttpStatusCode.SwitchingProtocols) // HTTP 101
            {
                if (this.m_WebSocketConnectionStream == null)
                {
                    ConnectStream connectStream = m_ConnectStream as ConnectStream;
                    GlobalLog.Assert(connectStream != null, "HttpWebResponse.m_ConnectStream should always be a ConnectStream in WebSocket cases.");
                    GlobalLog.Assert(connectStream.Connection != null, "HttpWebResponse.m_ConnectStream.Connection should never be null in WebSocket cases.");
                    this.m_WebSocketConnectionStream = new WebSocketConnectionStream(connectStream, this.ConnectionGroupName);
                }
                result = this.m_WebSocketConnectionStream;
            }
            else
            {
                result = m_ConnectStream;
            }

            if (Logging.On)
            {
                Logging.Exit(Logging.Web, this, "GetResponseStream", result);
            }
            return(result);
        }
コード例 #9
0
        private void ConsumeConnectStreamBuffer(ConnectStream connectStream)
        {
            if (connectStream.Eof)
            {
                return;
            }

            byte[] buffer = new byte[1024];
            int    count;
            int    offset = 0;
            int    size   = buffer.Length;

            while ((count = connectStream.FillFromBufferedData(buffer, ref offset, ref size)) > 0)
            {
                if (WebSocketBase.LoggingEnabled)
                {
                    Logging.Dump(Logging.WebSockets, this, "ConsumeConnectStreamBuffer", buffer, 0, count);
                }

                Append(buffer, 0, count);
                offset = 0;
                size   = buffer.Length;
            }
        }
コード例 #10
0
        internal HttpResponseStreamAsyncResult(object asyncObject, object userState, AsyncCallback callback, byte[] buffer, int offset, int size, bool chunked, bool sentHeaders) : base(asyncObject, userState, callback)
        {
            m_SentHeaders = sentHeaders;
            Overlapped overlapped = new Overlapped();

            overlapped.AsyncResult = this;

            if (size == 0)
            {
                m_DataChunks  = null;
                m_pOverlapped = overlapped.Pack(s_IOCallback, null);
            }
            else
            {
                m_DataChunks = new UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK[chunked ? 3 : 1];

                GlobalLog.Print("HttpResponseStreamAsyncResult#" + ValidationHelper.HashString(this) + "::.ctor() m_pOverlapped:0x" + ((IntPtr)m_pOverlapped).ToString("x8"));

                object[] objectsToPin = new object[1 + m_DataChunks.Length];
                objectsToPin[m_DataChunks.Length] = m_DataChunks;


                int    chunkHeaderOffset = 0;
                byte[] chunkHeaderBuffer = null;
                if (chunked)
                {
                    chunkHeaderBuffer = ConnectStream.GetChunkHeader(size, out chunkHeaderOffset);

                    m_DataChunks[0] = new UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK();
                    m_DataChunks[0].DataChunkType = UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory;
                    m_DataChunks[0].BufferLength  = (uint)(chunkHeaderBuffer.Length - chunkHeaderOffset);

                    objectsToPin[0] = chunkHeaderBuffer;

                    m_DataChunks[1] = new UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK();
                    m_DataChunks[1].DataChunkType = UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory;
                    m_DataChunks[1].BufferLength  = (uint)size;

                    objectsToPin[1] = buffer;

                    m_DataChunks[2] = new UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK();
                    m_DataChunks[2].DataChunkType = UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory;
                    m_DataChunks[2].BufferLength  = (uint)NclConstants.CRLF.Length;

                    objectsToPin[2] = NclConstants.CRLF;
                }
                else
                {
                    m_DataChunks[0] = new UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK();
                    m_DataChunks[0].DataChunkType = UnsafeNclNativeMethods.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory;
                    m_DataChunks[0].BufferLength  = (uint)size;

                    objectsToPin[0] = buffer;
                }

                // This call will pin needed memory
                m_pOverlapped = overlapped.Pack(s_IOCallback, objectsToPin);

                if (chunked)
                {
                    m_DataChunks[0].pBuffer = (byte *)(Marshal.UnsafeAddrOfPinnedArrayElement(chunkHeaderBuffer, chunkHeaderOffset));
                    m_DataChunks[1].pBuffer = (byte *)(Marshal.UnsafeAddrOfPinnedArrayElement(buffer, offset));
                    m_DataChunks[2].pBuffer = (byte *)(Marshal.UnsafeAddrOfPinnedArrayElement(NclConstants.CRLF, 0));
                }
                else
                {
                    m_DataChunks[0].pBuffer = (byte *)(Marshal.UnsafeAddrOfPinnedArrayElement(buffer, offset));
                }
            }
        }
コード例 #11
0
 public StreamChunkBytes(ConnectStream connectStream)
 {
     this.ChunkStream = connectStream;
 }
コード例 #12
0
 public StreamChunkBytes(ConnectStream connectStream)
 {
     ChunkStream = connectStream;
     return;
 }
コード例 #13
0
        private void ConsumeConnectStreamBuffer(ConnectStream connectStream)
        {
            if (connectStream.Eof)
            {
                return;
            }

            byte[] buffer = new byte[1024];
            int count;
            int offset = 0;
            int size = buffer.Length;

            while ((count = connectStream.FillFromBufferedData(buffer, ref offset, ref size)) > 0)
            {
                if (WebSocketBase.LoggingEnabled)
                {
                    Logging.Dump(Logging.WebSockets, this, "ConsumeConnectStreamBuffer", buffer, 0, count);
                }

                Append(buffer, 0, count);
                offset = 0;
                size = buffer.Length;
            }
        }
コード例 #14
0
ファイル: TransportContext.cs プロジェクト: dox0/DotNet471RS3
 internal ConnectStreamContext(ConnectStream connectStream)
 {
     GlobalLog.Assert(connectStream != null, "ConnectStreamContext..ctor(): Not expecting a null connectStream!");
     this.connectStream = connectStream;
 }
コード例 #15
0
 internal WriteHeadersCallbackState(HttpWebRequest request, ConnectStream stream)
 {
     this.request = request;
     this.stream  = stream;
 }
コード例 #16
0
 internal ConnectStreamContext(ConnectStream connectStream)
 {
     this.connectStream = connectStream;
 }