Esempio n. 1
0
        private RestResponse ConvertToRestResponse(IRestRequest request, HttpResponse httpResponse)
        {
            var restResponse = new RestResponse();
            restResponse.Content = httpResponse.Content;
            restResponse.ContentEncoding = httpResponse.ContentEncoding;
            restResponse.ContentLength = httpResponse.ContentLength;
            restResponse.ContentType = httpResponse.ContentType;
            restResponse.ErrorException = httpResponse.ErrorException;
            restResponse.ErrorMessage = httpResponse.ErrorMessage;
            restResponse.RawBytes = httpResponse.RawBytes;
            restResponse.ResponseStatus = httpResponse.ResponseStatus;
            restResponse.ResponseUri = httpResponse.ResponseUri;
            restResponse.Server = httpResponse.Server;
            restResponse.StatusCode = httpResponse.StatusCode;
            restResponse.StatusDescription = httpResponse.StatusDescription;
            restResponse.Request = request;

            foreach (var header in httpResponse.Headers)
            {
                restResponse.Headers.Add(new Parameter { Name = header.Name, Value = header.Value, Type = ParameterType.HttpHeader });
            }

            foreach (var cookie in httpResponse.Cookies)
            {
                restResponse.Cookies.Add(new RestResponseCookie {
                    Comment = cookie.Comment,
                    CommentUri = cookie.CommentUri,
                    Discard = cookie.Discard,
                    Domain = cookie.Domain,
                    Expired = cookie.Expired,
                    Expires = cookie.Expires,
                    HttpOnly = cookie.HttpOnly,
                    Name = cookie.Name,
                    Path = cookie.Path,
                    Port = cookie.Port,
                    Secure = cookie.Secure,
                    TimeStamp = cookie.TimeStamp,
                    Value = cookie.Value,
                    Version = cookie.Version
                });
            }

            return restResponse;
        }
Esempio n. 2
0
		private async Task<IRestResponse> ExecuteInternal(IRestRequest request, string httpMethod, Func<IHttp, string, Task<HttpResponse>> getResponse)
		{
			AuthenticateIfNeeded(this, request);

			// add Accept header based on registered deserializers
			var accepts = string.Join(", ", AcceptTypes.ToArray());
			this.AddDefaultParameter("Accept", accepts, ParameterType.HttpHeader);

			IRestResponse response = new RestResponse();
			try
			{
				var http = HttpFactory.Create();

				ConfigureHttp(request, http);

                //TODO: Add support for Proxy
				//ConfigureProxy(http);

				response = ConvertToRestResponse(request, await getResponse(http, httpMethod));
				response.Request = request;
				response.Request.IncreaseNumAttempts();

			}
			catch (Exception ex)
			{
				response.ResponseStatus = ResponseStatus.Error;
				response.ErrorMessage = ex.Message;
				response.ErrorException = ex;
			}

			return response;
		}