/// <inheritdoc /> public Task <IResponse> Send(IRequest request, CancellationToken cancellationToken) { if (request.Method.Method == HttpMethod.Post.Method) { logger.LogTrace("Octokit POST:\n{0}", request.Body); } return(httpClientAdapter.Send(request, cancellationToken)); }
public async Task CanCancelARequest() { var httpClient = new HttpClientAdapter(HttpMessageHandlerFactory.CreateDefault); var request = new Request { BaseAddress = new Uri("https://github.global.ssl.fastly.net/", UriKind.Absolute), Endpoint = new Uri("/images/icons/emoji/poop.png?v=5", UriKind.RelativeOrAbsolute), Method = HttpMethod.Get, Timeout = TimeSpan.FromMilliseconds(10) }; var response = httpClient.Send(request, CancellationToken.None); await Task.Delay(TimeSpan.FromSeconds(2)); Assert.True(response.IsCanceled); }
public async Task CanDownloadImage() { var httpClient = new HttpClientAdapter(); var request = new Request { BaseAddress = new Uri("https://github.global.ssl.fastly.net/", UriKind.Absolute), Endpoint = new Uri("/images/icons/emoji/poop.png?v=5", UriKind.RelativeOrAbsolute), AllowAutoRedirect = true, Method = HttpMethod.Get }; var imageBytes = await httpClient.Send<byte[]>(request, CancellationToken.None); // Spot check some of dem bytes. Assert.Equal(137, imageBytes.BodyAsObject[0]); Assert.Equal(80, imageBytes.BodyAsObject[1]); Assert.Equal(78, imageBytes.BodyAsObject[2]); Assert.Equal(130, imageBytes.BodyAsObject.Last()); }
public async Task CanDownloadImage() { var httpClient = new HttpClientAdapter(HttpMessageHandlerFactory.CreateDefault); var request = new Request { BaseAddress = new Uri("https://github.global.ssl.fastly.net/", UriKind.Absolute), Endpoint = new Uri("/images/icons/emoji/poop.png?v=5", UriKind.RelativeOrAbsolute), Method = HttpMethod.Get }; var response = await httpClient.Send(request, CancellationToken.None); // Spot check some of dem bytes. var imageBytes = (byte[])response.Body; Assert.Equal(137, imageBytes[0]); Assert.Equal(80, imageBytes[1]); Assert.Equal(78, imageBytes[2]); Assert.Equal(130, imageBytes.Last()); }
public Task <IResponse> Send(IRequest request, CancellationToken cancellationToken) { request.Headers.Add("Time-Zone", "UTC"); return(_client.Send(request, cancellationToken)); }