From 44df426df694f031fbf2e3731ca665273c7cbabc Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Tue, 22 Mar 2016 00:57:51 +1000 Subject: [PATCH] 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 8f4f6d8345..846beaa056 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)