示例#1
0
 protected AbstractFormulateRequestor()
 {
     _contents = _appConfiguration.Contents;
     _headers  = _appConfiguration.Headers;
     _config   = _appConfiguration.Config;
     _maxRun   = _config.MaxRun;
 }
示例#2
0
        public async Task <IRequestStatus> ExecuteAsync(Uri uri, IHeaderHolder headers)
        {
            var status = new RequestStatus();

            var requestHandler = new WebRequestHandler
            {
                CookieContainer = GetCookies(uri, headers)
            };

            var authorizationHeader = GetAuthorizationToken(headers);

            using (var httpClient = new HttpClient(requestHandler))
            {
                using (var request = new HttpRequestMessage(HttpMethod.Get, uri))
                {
                    request.Headers.Clear();
                    request.Headers.Authorization = authorizationHeader;
                    headers.Where(x => !_skipHeaders.Contains(x.Key)).ToList().ForEach(x => request.Headers.Add(x.Key, x.Value));

                    var response = await httpClient.SendAsync(request);

                    status.Status = response.StatusCode.ToString();
                    response.EnsureSuccessStatusCode();
                }
            }

            return(status);
        }
示例#3
0
        public async Task InitializeAsync(string configFile, string headerFile, string contentFile)
        {
            _config = await Processor.ProcessConfigFile(configFile);

            _header = await Processor.ProcessHeaderFile(headerFile);

            _contents = await Processor.ProcessContentFile(contentFile);

            _isInitialized = true;
        }
示例#4
0
        private static AuthenticationHeaderValue GetAuthorizationToken(IHeaderHolder headers)
        {
            AuthenticationHeaderValue authenticationHeader = null;
            var auth = headers.Where(x => x.Key == PredefinedHeaders.Authorization.ToString()).FirstOrDefault().Value;

            if (auth != null)
            {
                var index  = auth.IndexOf(' ');
                var scheme = auth.Substring(0, index);
                var value  = auth.Substring(index + 1, auth.Length - index - 1);

                authenticationHeader = new AuthenticationHeaderValue(scheme, value);
            }

            return(authenticationHeader);
        }
示例#5
0
        private static CookieContainer GetCookies(Uri uri, IHeaderHolder headers)
        {
            var cookieContainer = new CookieContainer();
            var cookieValue     = headers.Where(x => x.Key == PredefinedHeaders.Cookie.ToString()).FirstOrDefault().Value;

            if (cookieValue != null)
            {
                var cookies = cookieValue.Split(new[] { ';' });
                foreach (var cookie in cookies)
                {
                    var c = cookie.Split(new[] { '=' });
                    cookieContainer.Add(uri, new Cookie(c[0]?.Trim(), c[1]?.Trim()));
                }
            }

            return(cookieContainer);
        }
示例#6
0
 public Executor(IHttpRequestExecutor httpRequestExecutor)
 {
     _config              = _appConfiguration.Config;
     _headers             = _appConfiguration.Headers;
     _httpRequestExecutor = httpRequestExecutor;
 }