/// <summary> /// Helper method to run all plugin methods that need to be executed on <see cref="INapRequest"/> creation. /// </summary> private INapRequest CreateNapRequest(INapConfig config, string url, HttpMethod method) { try { var plugins = _setup?.Plugins.ToArray() ?? new IPlugin[] { }; // Enumerate plugins to make sure no other threads are going to add/remove plugins halfway through var request = new NapRequest(plugins, config, url, method); return(request); } catch (Exception e) { throw new Exception("Nap request creation aborted. See inner exception for details.", e); // TODO: Specific exception } }
/// <summary> /// Create a new instance of the <see cref="NapResponse"/> object, populated with response information. /// </summary> /// <param name="request">The request that generated this response.</param> /// <param name="response">The response that will generate the current nap response.</param> /// <param name="body">The body of the response.</param> internal NapResponse(NapRequest request, HttpResponseMessage response, string body) { Request = request; Url = new Uri(request.Url); StatusCode = response.StatusCode; Headers = new ReadOnlyCollection <KeyValuePair <string, string> >(response.Headers .Union(response.Content.Headers) .SelectMany(h => h.Value.Select(v => new KeyValuePair <string, string>(h.Key, v))) .ToList()); Cookies = new ReadOnlyCollection <NapCookie>(Headers.Where(h => h.Key.Equals("set-cookie", StringComparison.OrdinalIgnoreCase)) .Select(h => new NapCookie(new Uri(request.Url), h.Value)) .ToList()); Body = body; ContentHeaders = response.Content.Headers; NonContentHeaders = response.Headers; }