From 83bb3e37eb7ef93cc29365fa2579fa5dd7d8483f Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Tue, 22 Mar 2016 00:25:12 +1000 Subject: [PATCH 1/3] Fix "repositories" Uri's by removing leading slash - this caused the base address to have the /api/v3/ removed when talking to GHE??? --- Octokit.Tests/Clients/RepositoriesClientTests.cs | 6 +++--- Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs | 2 +- Octokit/Helpers/ApiUrls.cs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index f0f77b7dbe..4e8bd1824d 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -269,7 +269,7 @@ public void RequestsTheCorrectUrlAndReturnsRepositories() client.GetAllPublic(); connection.Received() - .GetAll(Arg.Is(u => u.ToString() == "/repositories")); + .GetAll(Arg.Is(u => u.ToString() == "repositories")); } } @@ -285,7 +285,7 @@ public void RequestsTheCorrectUrl() client.GetAllPublic(new PublicRepositoryRequest(364)); connection.Received() - .GetAll(Arg.Is(u => u.ToString() == "/repositories?since=364")); + .GetAll(Arg.Is(u => u.ToString() == "repositories?since=364")); } [Fact] @@ -297,7 +297,7 @@ public void SendsTheCorrectParameter() client.GetAllPublic(new PublicRepositoryRequest(364)); connection.Received() - .GetAll(Arg.Is(u => u.ToString() == "/repositories?since=364")); + .GetAll(Arg.Is(u => u.ToString() == "repositories?since=364")); } } diff --git a/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs index b0d257299b..a2f0e31f25 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs @@ -163,7 +163,7 @@ public class TheGetAllPublicRepositoriesSinceMethod [Fact] public async Task ReturnsEveryPageOfRepositories() { - var firstPageUrl = new Uri("/repositories?since=364", UriKind.Relative); + var firstPageUrl = new Uri("repositories?since=364", UriKind.Relative); var secondPageUrl = new Uri("https://example.com/page/2"); var firstPageLinks = new Dictionary { { "next", secondPageUrl } }; IApiResponse> firstPageResponse = new ApiResponse>( diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 54d6edaa27..b59cb950b1 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -25,7 +25,7 @@ public static partial class ApiUrls /// public static Uri AllPublicRepositories() { - return "/repositories".FormatUri(); + return "repositories".FormatUri(); } /// @@ -35,7 +35,7 @@ public static Uri AllPublicRepositories() /// The integer ID of the last Repository that you’ve seen. public static Uri AllPublicRepositories(long since) { - return "/repositories?since={0}".FormatUri(since); + return "repositories?since={0}".FormatUri(since); } /// From b364dd7d4783b37f31fb597c6f5170c4aedbea85 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Tue, 22 Mar 2016 00:57:51 +1000 Subject: [PATCH 2/3] Remove leading slash from relative Uri endpoints when constructing full Uri --- Octokit/Http/HttpClientAdapter.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Octokit/Http/HttpClientAdapter.cs b/Octokit/Http/HttpClientAdapter.cs index 1c6a65a542..d6759c87c5 100644 --- a/Octokit/Http/HttpClientAdapter.cs +++ b/Octokit/Http/HttpClientAdapter.cs @@ -109,7 +109,15 @@ protected virtual HttpRequestMessage BuildRequestMessage(IRequest request) HttpRequestMessage requestMessage = null; try { - var fullUri = new Uri(request.BaseAddress, request.Endpoint); + // Remove any leading slash from endpoint Uri (otherwise it clobbers the /api/v3/ in BaseAddress) + var endpoint = request.Endpoint; + if (!endpoint.IsAbsoluteUri && + endpoint.ToString().StartsWith("/", StringComparison.OrdinalIgnoreCase)) + { + endpoint = new Uri(endpoint.ToString().TrimStart('/'), UriKind.Relative); + } + + var fullUri = new Uri(request.BaseAddress, endpoint); requestMessage = new HttpRequestMessage(request.Method, fullUri); foreach (var header in request.Headers) From b99d1780435ff04c12df1f7892958274b1a360c3 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Tue, 29 Mar 2016 13:03:42 +1000 Subject: [PATCH 3/3] Revert "Remove leading slash from relative Uri endpoints when constructing full Uri" This reverts commit 44df426df694f031fbf2e3731ca665273c7cbabc. --- Octokit/Http/HttpClientAdapter.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Octokit/Http/HttpClientAdapter.cs b/Octokit/Http/HttpClientAdapter.cs index d6759c87c5..1c6a65a542 100644 --- a/Octokit/Http/HttpClientAdapter.cs +++ b/Octokit/Http/HttpClientAdapter.cs @@ -109,15 +109,7 @@ protected virtual HttpRequestMessage BuildRequestMessage(IRequest request) HttpRequestMessage requestMessage = null; try { - // Remove any leading slash from endpoint Uri (otherwise it clobbers the /api/v3/ in BaseAddress) - var endpoint = request.Endpoint; - if (!endpoint.IsAbsoluteUri && - endpoint.ToString().StartsWith("/", StringComparison.OrdinalIgnoreCase)) - { - endpoint = new Uri(endpoint.ToString().TrimStart('/'), UriKind.Relative); - } - - var fullUri = new Uri(request.BaseAddress, endpoint); + var fullUri = new Uri(request.BaseAddress, request.Endpoint); requestMessage = new HttpRequestMessage(request.Method, fullUri); foreach (var header in request.Headers)