internal async Task <RegistryApiResponse <Stream> > MakeRequestForStreamedResponseAsync( CancellationToken cancellationToken, HttpMethod method, string path, IQueryString queryString = null) { var response = await this.InternalMakeRequestAsync( InfiniteTimeout, HttpCompletionOption.ResponseHeadersRead, method, path, queryString, null, null, cancellationToken); var body = await response.Content.ReadAsStreamAsync(); var apiResponse = new RegistryApiResponse <Stream>( response.StatusCode, body, response.Headers); this.HandleIfErrorResponse(apiResponse); return(apiResponse); }
private void HandleIfErrorResponse(RegistryApiResponse response) { // If no customer handlers just default the response. foreach (var handler in this._errorHandlers) { handler(response); } // No custom handler was fired. Default the response for generic success/failures. if (response.StatusCode < HttpStatusCode.OK || response.StatusCode >= HttpStatusCode.BadRequest) { throw new RegistryApiException(response); } }
internal async Task <RegistryApiResponse <string> > MakeRequestAsync( CancellationToken cancellationToken, HttpMethod method, string path, IQueryString queryString = null, IDictionary <string, string> headers = null, Func <HttpContent> content = null) { //Console.WriteLine( // "Requesting Path: {0} Method: {1} QueryString: {2}", // path, // method, // queryString?.GetQueryString()); using (var response = await this.InternalMakeRequestAsync( this.DefaultTimeout, HttpCompletionOption.ResponseContentRead, method, path, queryString, headers, content, cancellationToken)) { var responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var apiResponse = new RegistryApiResponse <string>( response.StatusCode, responseBody, response.Headers); this.HandleIfErrorResponse(apiResponse); return(apiResponse); } }
internal RegistryApiException(RegistryApiResponse response) : base($"Docker API responded with status code={response.StatusCode}") { this.StatusCode = response.StatusCode; this.Headers = response.Headers; }