public static async Task <IHalHttpResponseMessage> CreateAsync(HttpResponseMessage response, IHalJsonParser parser) { if (response == null) { throw new ArgumentNullException(nameof(response)); } if (parser == null) { throw new ArgumentNullException(nameof(parser)); } var message = new HalHttpResponseMessage(response); if (message.IsHalResponse || message.IsJsonResponse) { var content = await response.Content.ReadAsStringAsync(); if (content.Length > 0) { var result = parser.Parse(content); message.Resource = new RootResourceObject(result); } else { message.Resource = new RootResourceObject(); } } return(message); }
private async Task <IHalHttpResponseMessage> ProcessResponseMessage(HttpResponseMessage response) { if (Configuration.AutoFollowRedirects && (response.StatusCode == HttpStatusCode.Redirect || response.StatusCode == HttpStatusCode.SeeOther || response.StatusCode == HttpStatusCode.RedirectMethod)) { return(await GetAsync(response.Headers.Location)); } var message = await HalHttpResponseMessage.CreateAsync(response, _parser); if (response.IsSuccessStatusCode || !Configuration.ThrowOnError) { return(message); } throw new HalHttpRequestException(response.StatusCode, response.ReasonPhrase, message.Resource); }