Пример #1
0
        /// <summary>
        /// Send HTTP request for the full content and receive HTTP response from the server.
        /// </summary>
        /// <param name="httpVersion">he HTTP version.</param>
        /// <param name="request">The HTTP reqeust.</param>
        /// <param name="timeOut">The time out to wait the response.</param>
        /// <returns>Returns the recieved HTTP response.</returns>
        public PccrtpResponse SendHttpRequest(
            HttpVersionType httpVersion,
            PccrtpRequest request,
            int timeOut)
        {
            byte[] payloadBuffer = null;

            if (this.logger != null)
            {
                this.httpClientTransport = new HttpClientTransport(
                    TransferProtocol.HTTP,
                    request.ServerAddress,
                    request.Port,
                    request.RequestFileName,
                    this.logger);
            }
            else
            {
                this.httpClientTransport = new HttpClientTransport(
                    TransferProtocol.HTTP,
                    request.ServerAddress,
                    request.Port,
                    request.RequestFileName);
            }

            if (HttpVersionType.HttpVersion10 == (HttpVersionType)httpVersion)
            {
                this.httpClientTransport.Send(HttpVersion.Version10, request.HttpHeader, null, HttpMethod.GET, timeOut);
            }
            else
            {
                // The default version of HTTP to use for the request is HTTP 1.1.
                this.httpClientTransport.Send(HttpVersion.Version11, request.HttpHeader, null, HttpMethod.GET, timeOut);
            }

            this.httpWebResponse = this.httpClientTransport.Receive(ref payloadBuffer);

            this.pccrtpResponse.DecodeHttpHeader(this.httpWebResponse);
            this.pccrtpResponse.PayloadData  = payloadBuffer;
            this.pccrtpResponse.HttpResponse = this.httpWebResponse;

            return(this.pccrtpResponse);
        }
        /// <summary>
        /// Send HTTP request for partial content and receive HTTP response from the server.
        /// </summary>
        /// <param name="httpVersion">The HTTP version.</param>
        /// <param name="request">The PCCRTP request.</param>
        /// <param name="timeOut">The number of milliseconds to wait before the request times out</param>
        /// <param name="rangeFrom">The start position at which to the requested data.</param>
        /// <param name="rangeTo">The end position at which to the requested data.</param>
        /// <returns>Returns the PCCRTP response.</returns>
        public PccrtpResponse SendHttpRequest(
            HttpVersionType httpVersion,
            PccrtpRequest request,
            int timeOut,
            int rangeFrom,
            int rangeTo)
        {
            byte[] payloadBuffer = null;

            if (this.logger != null)
            {
                this.httpClientTransport = new HttpClientTransport(
                    TransferProtocol.HTTP,
                    request.ServerAddress,
                    request.Port,
                    request.RequestFileName,
                    this.logger);
            }
            else
            {
                this.httpClientTransport = new HttpClientTransport(
                    TransferProtocol.HTTP,
                    request.ServerAddress,
                    request.Port,
                    request.RequestFileName);
            }

            if (HttpVersionType.HttpVersion10 == (HttpVersionType)httpVersion)
            {
                this.httpClientTransport.Send(
                    HttpVersion.Version10,
                    request.HttpHeader,
                    null,
                    HttpMethod.GET,
                    timeOut,
                    rangeFrom,
                    rangeTo);
            }
            else
            {
                // The default version of HTTP to use for the request is HTTP 1.1.
                this.httpClientTransport.Send(
                    HttpVersion.Version11,
                    request.HttpHeader,
                    null,
                    HttpMethod.GET,
                    timeOut,
                    rangeFrom,
                    rangeTo);
            }

            this.httpWebResponse = this.httpClientTransport.Receive(ref payloadBuffer);

            this.pccrtpResponse.DecodeHttpHeader(this.httpWebResponse);
            this.pccrtpResponse.PayloadData = payloadBuffer;
            this.pccrtpResponse.HttpResponse = this.httpWebResponse;

            this.pccrtpResponse.HttpResponse = this.httpWebResponse;

            return this.pccrtpResponse;
        }
        /// <summary>
        /// Receive a PCCRTP request message from the HTTP/1.1 client (SUT) when testing client endpoint.
        /// </summary>
        /// <returns>Return the PCCRTP request message received.</returns>
        public PccrtpRequest ReceivePccrtpRequestMessage()
        {
            TimeSpan timeOut = TimeSpan.FromSeconds(double.Parse(Site.Properties["PCCRTP.Protocol.TimeOut"]));
            this.pccrtpRequest = this.pccrtpServerStack.ReceivePccrtpRequest(timeOut);
            this.pccrtpRequest.DecodeHttpHeader(this.pccrtpRequest.HttpRequest);
            PccrtpBothRoleCapture.VerifyTransport(this.pccrtpRequest.HttpRequest.ProtocolVersion.ToString());
            PccrtpBothRoleCapture.VerifyPccrtpCommonHeader(this.pccrtpRequest.HttpHeader);
            this.VerifyPccrtpRequestRequirements();

            return this.pccrtpRequest;
        }
        /// <summary>
        /// Send a PCCRTP request message and receive a PCCRTP response message.
        /// </summary>
        /// <param name="httpVersion">Indicates the HTTP version type used.</param>
        /// <param name="isRequestPartialContent">Indicates it is requesting partical content or not.</param>
        /// <param name="uri">Indicates the URI on the SUT requested by the client.</param>
        /// <returns>Return the PCCRTP response message received.</returns>
        public PccrtpResponse SendPccrtpRequestMessage(
            HttpVersionType httpVersion,
            bool isRequestPartialContent,
            string uri)
        {
            PccrtpRequest pccrtpRequest = new PccrtpRequest();
            PccrtpResponse pccrtpResponse = new PccrtpResponse();
            string serverAddress = this.GetProperty("Environment.ContentServer.MachineName");
            int port = int.Parse(this.GetProperty("Environment.ContentServer.HTTP.Port"));
            int timeOut = (int)TimeSpan.FromSeconds(
                double.Parse(this.GetProperty("PCCRTP.Protocol.TimeOut"))).TotalMilliseconds;
            int rangeFrom = int.Parse(this.GetProperty("PCCRTP.Protocol.RangeFrom"));
            int rangeTo = int.Parse(this.GetProperty("PCCRTP.Protocol.RangeTo"));

            if (isRequestPartialContent)
            {
                pccrtpRequest = this.pccrtpClientStack.CreatePccrtpRequest(serverAddress, port, uri);
                pccrtpResponse = this.pccrtpClientStack.SendHttpRequest(
                    httpVersion,
                    pccrtpRequest,
                    timeOut,
                    rangeFrom,
                    rangeTo);
            }
            else
            {
                pccrtpRequest = this.pccrtpClientStack.CreatePccrtpRequest(serverAddress, port, uri);
                pccrtpResponse = this.pccrtpClientStack.SendHttpRequest(httpVersion, pccrtpRequest, timeOut);
            }

            if (pccrtpResponse.HttpResponse.ContentEncoding.Equals("peerdist"))
            {
                PccrtpBothRoleCapture.VerifyTransport(pccrtpResponse.HttpResponse.ProtocolVersion.ToString());
                PccrtpBothRoleCapture.VerifyPccrtpCommonHeader(pccrtpResponse.HttpHeader);
                this.VerifyPccrtpResponse(pccrtpResponse);
                this.VerifyContentInfomationStructure(pccrtpResponse);
            }

            return pccrtpResponse;
        }