8000 Trim trailing `/` from hostUrl by tstivers1990 · Pull Request #615 · reactiveui/refit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Trim trailing / from hostUrl #615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Refit.Tests/InterfaceStubGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void GenerateTemplateInfoForInterfaceListSmokeTest()
.ToList();

var result = fixture.GenerateTemplateInfoForInterfaceList(input);
Assert.Equal(10, result.ClassList.Count);
Assert.Equal(11, result.ClassList.Count);
}

[Fact]
Expand Down
32 changes: 32 additions & 0 deletions Refit.Tests/RefitStubs.Net46.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,38 @@ public virtual Task<ApiResponse<Stream>> GetRemoteFileWithMetadata(string filena
}
}

namespace Refit.Tests
{
using Refit.Tests.RefitInternalGenerated;

/// <inheritdoc />
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.Diagnostics.DebuggerNonUserCode]
[Preserve]
[global::System.Reflection.Obfuscation(Exclude=true)]
partial class AutoGeneratedITrimTrailingForwardSlashApi : ITrimTrailingForwardSlashApi
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly IRequestBuilder requestBuilder;

/// <inheritdoc />
public AutoGeneratedITrimTrailingForwardSlashApi(HttpClient client, IRequestBuilder requestBuilder)
{
Client = client;
this.requestBuilder = requestBuilder;
}

/// <inheritdoc />
public virtual Task Get()
{
var arguments = new object[] { };
var func = requestBuilder.BuildRestResultFuncForMethod("Get", new Type[] { });
return (Task)func(Client, arguments);
}
}
}

namespace Refit.Tests
{
using Refit.Tests.RefitInternalGenerated;
Expand Down
32 changes: 32 additions & 0 deletions Refit.Tests/RefitStubs.NetCore2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,38 @@ public virtual Task<ApiResponse<Stream>> GetRemoteFileWithMetadata(string filena
}
}

namespace Refit.Tests
{
using Refit.Tests.RefitInternalGenerated;

/// <inheritdoc />
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.Diagnostics.DebuggerNonUserCode]
[Preserve]
[global::System.Reflection.Obfuscation(Exclude=true)]
partial class AutoGeneratedITrimTrailingForwardSlashApi : ITrimTrailingForwardSlashApi
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly IRequestBuilder requestBuilder;

/// <inheritdoc />
public AutoGeneratedITrimTrailingForwardSlashApi(HttpClient client, IRequestBuilder requestBuilder)
{
Client = client;
this.requestBuilder = requestBuilder;
8000 }

/// <inheritdoc />
public virtual Task Get()
{
var arguments = new object[] { };
var func = requestBuilder.BuildRestResultFuncForMethod("Get", new Type[] { });
return (Task)func(Client, arguments);
}
}
}

namespace Refit.Tests
{
using Refit.Tests.RefitInternalGenerated;
Expand Down
19 changes: 19 additions & 0 deletions Refit.Tests/RestService.cs
8000
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ public interface IBodylessApi
Task Head();
}

public interface ITrimTrailingForwardSlashApi
{
HttpClient Client { get; }

[Get("/someendpoint")]
Task Get();
}

public class HttpBinGet
{
public Dictionary<string, object> Args { get; set; }
Expand Down Expand Up @@ -1187,5 +1195,16 @@ public async Task CanSerializeContentAsXml()

mockHttp.VerifyNoOutstandingExpectation();
}

[Fact]
public void ShouldTrimTrailingForwardSlashFromBaseUrl()
{
var expectedBaseAddress = "http://example.com/api";
var inputBaseAddress = "http://example.com/api/";

var fixture = RestService.For<ITrimTrailingForwardSlashApi>(inputBaseAddress);

Assert.Equal(fixture.Client.BaseAddress.AbsoluteUri, expectedBaseAddress);
}
}
}
2 changes: 1 addition & 1 deletion Refit/RestService.cs
< 45D0 td class="blob-code blob-code-context js-file-line"> return For<T>(client, settings);
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static T For<T>(string hostUrl, RefitSettings settings)
}
}

var client = new HttpClient(innerHandler ?? new HttpClientHandler()) { BaseAddress = new Uri(hostUrl) };
var client = new HttpClient(innerHandler ?? new HttpClientHandler()) { BaseAddress = new Uri(hostUrl?.TrimEnd('/')) };
}

Expand Down
0