public async Task <IHttpResponseModel> Execute(IHttpRequestModel httpRequest)
        {
            if (!(httpRequest is HttpRequestModel request))
            {
                throw new ArgumentException("Client does not support request object type");
            }

            IHttpResponseModel response = null;
            Exception          caughtEx = null;

            try
            {
                ValidateRequest(request);

                response = await Send(request);

                return(response);
            }
            catch (Exception ex)
            {
                caughtEx = ex;

                throw;
            }
            finally
            {
                CommunicationLoggerEventManager.NotifyHttpRequestCompleted(
                    this, new HttpCommunicationEventArgs(request, response, caughtEx));
            }
        }
        private string FormatRequestForLog(IHttpRequestModel request)
        {
            var sb = new StringBuilder();

            sb.AppendLine("API Request:");
            sb.AppendFormat("{0} {1} HTTP/1.1\n", request.Method, request.FullUri);

            FormatAndPrintHeaders(sb, request.Headers);

            sb.AppendFormat("Host: {0}\n", request.FullUri);
            sb.AppendLine("Body:");

            string body = request.GetBodyAsString();

            if (string.IsNullOrEmpty(body))
            {
                sb.AppendLine(body);
            }

            return(sb.ToString());
        }
Exemplo n.º 3
0
        public static void AddBasicAuth(this IHttpRequestModel request, string username, string password)
        {
            var asciiBytes = Encoding.ASCII.GetBytes(username + ":" + password);

            request.Authorization = "Basic " + Convert.ToBase64String(asciiBytes);
        }
 public HttpCommunicationEventArgs(IHttpRequestModel request, IHttpResponseModel response, Exception caughtEx)
 {
     Request         = request;
     Response        = response;
     CaughtException = caughtEx;
 }