예제 #1
0
        private ResponseContainer IssueRequestInternal(HttpRequestMessage request, bool save = true)
        {
            if (save && _retry == 0)
            {
                _original = CloneHttpRequestMessage(request);
            }
            try
            {
                HttpResponseMessage response = _httpClient.SendAsync(request).Sync();
                LastRequestUtc = DateTime.UtcNow;

                ResponseContainer result = new ResponseContainer(request, _original, response);
                _retry = 0;
                return(result);
            }
            catch (HttpRequestException ex)
            {
                if (_retry++ < 3)
                {
                    Console.WriteLine($"[!!!] Proxy request failed: {ex.Message}, retrying...");
                    return(IssueRequestInternal(CloneHttpRequestMessage(_original), false));
                }

                else
                {
                    throw ex.InnerException;
                }
            }
        }
예제 #2
0
        private ResponseContainer IssueRequestInternal(HttpRequestMessage request)
        {
            HttpResponseMessage response = _httpClient.SendAsync(request).Sync();

            LastRequestUtc = DateTime.UtcNow;

            ResponseContainer result = new ResponseContainer(request, response);

            return(result);
        }
예제 #3
0
 protected virtual void PostRequest(ResponseContainer response)
 {
 }
예제 #4
0
        public ResponseContainer IssueRequest(HttpRequestMessage request)
        {
            using (EnterExclusive())
            {
                ResponseContainer result = IssueRequestInternal(request);

                // Check interventions
                foreach (IInterventionHandler handler in _interventionHandlers)
                {
                    if (handler.DoIntervention(result))
                    {
                        // Woops, intervention needs to be handled
                        InterventionResult interventionResult = handler.Handle(result);

                        if (interventionResult.IntermediateTask != null)
                        {
                            // Process intermediate request
                            // TODO: Should we recurse?
                            IssueRequestInternal(request);
                        }

                        switch (interventionResult.State)
                        {
                        case InterventionResultState.Abort:
                            throw new Exception("Unable to process request");

                        case InterventionResultState.RetryCurrentTask:
                            // Retry same request
                            IssueRequest(request);
                            break;

                        case InterventionResultState.Continue:
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    }
                }

                // Process all parsers
                foreach (BaseParser parser in _parsers)
                {
                    if (!parser.ShouldProcess(result))
                    {
                        continue;
                    }

                    foreach (DataObject dataObject in parser.Process(this, result))
                    {
                        result.ParsedObjects.Add(dataObject);
                    }
                }

                // Call childs custom logic
                PostRequest(result);

                // Return
                return(result);
            }
        }
예제 #5
0
 public virtual string Inject(string body, ResponseContainer container, string host, int port)
 {
     return(body);
 }