/// <inheritdoc /> public HttpVersion GetHttpVersion(HttpVersionType version) { try { return(KnownHttpVersions[version]); } catch (KeyNotFoundException) { throw new UnknownHttpVersionException($"Unknown HTTP protocol version: {version}"); } }
public void GetHttpVersion_GivenValidHttpVersionType_ReturnsHttpVersionObjectContainingTheSameValue( HttpVersionType type) { // Arrange var repository = new HttpVersionRepository(); // Act var version = repository.GetHttpVersion(type); // Assert Assert.AreEqual(type, version.Version); }
public void Reset() { _onStarting = null; _onCompleted = null; _responseStarted = false; _keepAlive = false; _autoChunk = false; _applicationException = null; _requestHeaders.Reset(); ResetResponseHeaders(); ResetFeatureCollection(); Scheme = null; Method = null; RequestUri = null; PathBase = null; Path = null; QueryString = null; _httpVersion = HttpVersionType.Unknown; RequestHeaders = _requestHeaders; RequestBody = null; StatusCode = 200; ReasonPhrase = null; ResponseHeaders = _responseHeaders; ResponseBody = null; DuplexStream = null; var httpConnectionFeature = this as IHttpConnectionFeature; httpConnectionFeature.RemoteIpAddress = _remoteEndPoint?.Address; httpConnectionFeature.RemotePort = _remoteEndPoint?.Port ?? 0; httpConnectionFeature.LocalIpAddress = _localEndPoint?.Address; httpConnectionFeature.LocalPort = _localEndPoint?.Port ?? 0; if (_remoteEndPoint != null && _localEndPoint != null) { httpConnectionFeature.IsLocal = _remoteEndPoint.Address.Equals(_localEndPoint.Address); } else { httpConnectionFeature.IsLocal = false; } _prepareRequest?.Invoke(this); _manuallySetRequestAbortToken = null; _abortedCts = null; }
public void SetHttpVersion_GivenVersion_ReturnsTheSameVersion(HttpVersionType httpVersionType) { // Act var request = _requestBuilder .SetMethod(HttpMethodType.Connect) .SetTarget(UniformResourceIdentifier.FromString("/index.html")) .SetHttpVersion(httpVersionType) .SetHeader("Host", "example.com") .SetBody("Hello World!", Encoding.Default) .Build(); // Assert Assert.AreEqual(httpVersionType, request.HttpVersion); }
/// <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 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); }
public void Reset() { ResetComponents(); _onStarting = null; _onCompleted = null; _responseStarted = false; _keepAlive = false; _autoChunk = false; _applicationException = null; ResetFeatureCollection(); Scheme = null; Method = null; RequestUri = null; PathBase = null; Path = null; QueryString = null; _httpVersion = HttpVersionType.Unknown; StatusCode = 200; ReasonPhrase = null; var httpConnectionFeature = this as IHttpConnectionFeature; httpConnectionFeature.RemoteIpAddress = RemoteEndPoint?.Address; httpConnectionFeature.RemotePort = RemoteEndPoint?.Port ?? 0; httpConnectionFeature.LocalIpAddress = LocalEndPoint?.Address; httpConnectionFeature.LocalPort = LocalEndPoint?.Port ?? 0; httpConnectionFeature.ConnectionId = ConnectionId; PrepareRequest?.Invoke(this); _manuallySetRequestAbortToken = null; _abortedCts = null; }
public void Reset() { FrameRequestHeaders?.Reset(); FrameResponseHeaders?.Reset(); _onStarting = null; _onCompleted = null; _requestProcessingStatus = RequestProcessingStatus.RequestPending; _keepAlive = false; _autoChunk = false; _applicationException = null; ResetFeatureCollection(); Scheme = null; Method = null; PathBase = null; Path = null; QueryString = null; _httpVersion = HttpVersionType.Unset; StatusCode = 200; ReasonPhrase = null; RemoteIpAddress = RemoteEndPoint?.Address; RemotePort = RemoteEndPoint?.Port ?? 0; LocalIpAddress = LocalEndPoint?.Address; LocalPort = LocalEndPoint?.Port ?? 0; ConnectionIdFeature = ConnectionId; PrepareRequest?.Invoke(this); _manuallySetRequestAbortToken = null; _abortedCts = null; }
/// <summary> /// This method sets the HTTP version of the request. /// </summary> /// <param name="httpVersionType"> /// The HTTP version of the request. /// </param> /// <returns> /// This instance. /// </returns> public RequestBuilder SetHttpVersion(HttpVersionType httpVersionType) { _httpVersion = _httpVersionRepository.GetHttpVersion(httpVersionType); return(this); }
/// <summary> /// This constructor is used to set the <see cref="Version" /> property to the given /// <paramref name="version" />. /// </summary> /// <param name="version"> /// This value represents a HTTP-version. /// </param> internal HttpVersion(HttpVersionType version) { Version = version; }
/// <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> /// 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; }