bagetter / BaGetter

A lightweight NuGet and symbol server
https://www.bagetter.com
MIT License
166 stars 38 forks source link

It may be better if the base URL ends in /. #153

Open toras9000 opened 2 weeks ago

toras9000 commented 2 weeks ago

Proposal

I think that it is better for service resource URLs included in the package's service index that are used as base URLs to end in /.
Specifically, it refers to the following.

https://github.com/bagetter/BaGetter/blob/0e744432d73248ce6bc458459ba074a404ad7391/src/BaGetter.Web/BaGetterUrlGenerator.cs#L31 https://github.com/bagetter/BaGetter/blob/0e744432d73248ce6bc458459ba074a404ad7391/src/BaGetter.Web/BaGetterUrlGenerator.cs#L36

Reasons for Proposal

It may depend on the application implementation, but if the base URL is not terminated with a /, it may result in a different URL than expected when combined with a relative URL.
For example, if you use the .NET Uri class as it is, the following differences will appear depending on the presence or absence of the trailing /.

var baseUri1 = new Uri("http://server.example/v3/package");
var fullUri1 = new Uri(baseUri1, "relative/path");
// fullUri1.AbsoluteUri is "http://server.example/v3/relative/path"

var baseUri2 = new Uri("http://server.example/v3/package/");
var fullUri2 = new Uri(baseUri2, "relative/path");
// fullUri2.AbsoluteUri is "http://server.example/v3/package/relative/path"

I think something similar could happen outside of .NET Uri.
I believe that terminating the base URL with a / will reduce the likelihood of encountering such handling problems.
Note that the index https://api.nuget.org/v3/index.json on nuget.org also terminates the addresses of PackageBaseAddress and PackageBaseAddress with a /.

I can give one specific example of an application that encounters the above mentioned problem.
The following extension cannot display package information correctly when using the Bagetter v1.4.2 service index.
Based on my research into the operation of this application I have made the above suggestions.
https://marketplace.visualstudio.com/items?itemName=FullStackSpider.visual-nuget

etc.

I rely on translation tools. I'm sorry if there is a strange sentence.

Regenhardt commented 2 weeks ago

Thanks for the proposal. I Agree that the v3 endpoints should be terminated with / like the ones on nuget.org. Will get to it eventually, but I'd appreciate any PR amending the v3 endpoints as well, as I don't have much time currently.