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
Fix so that BaseURL can be used without the trailing slash #690
Conversation
@@ -281,7 +283,9 @@ func (c *Client) NewUploadRequest(urlStr string, reader io.Reader, size int64, m | |||
return nil, err | |||
} | |||
|
|||
u := c.UploadURL.ResolveReference(rel) | |||
u := *c.BaseURL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's valid to change c.UploadURL
for c.BaseURL
.
I would prefer a solution that checks and reports a helpful error message if the BaseURL doesn't have a trailing slash. It's easy, and can be done in if !strings.HasSuffix(c.BaseURL.Path, "/") {
return nil, fmt.Errorf("BaseURL must have a trailing slash, but %q does not", c.BaseURL.String())
}
u := c.BaseURL.ResolveReference(rel) Currently, there's only one canonical way to specify a BaseURL–that is with the trailing slash. I think that's a valuable property and worth preserving. If you remove that requirement, there will be more than one way to specify a BaseURL. I don't think that's an improvement. I say this because I don't think it's any harder to specify a URL with a trailing slash than without, so trying to do it automatically doesn't gain much convenience for users. |
Thank you so much for review! |
Sounds good. Thank you @178inaba! |
This PR provides logic to return an error if there is no slash at the end of BaseURL or UploadURL. Related comment: #690 (comment)
This is a breaking change, and a nasty one. |
Hi @gravis, thanks for reporting this, it's very helpful for us. Just to note, this PR was not merged, but #692 was merged instead. Did you mean to post this there?
Note that // Base URL for API requests. Defaults to the public GitHub API, but can be
// set to a domain endpoint to use with GitHub Enterprise. BaseURL should
// always be specified with a trailing slash.
BaseURL *url.URL The relevant part is that "BaseURL should always be specified with a trailing slash." This was the API for a while, and PR #692 did not change that. If the BaseURL is specified without a trailing slash, there may be other issues as a result of that, because the code assumes it has a trailing slash. Can you share more details about your issue, what was the value |
I think the comment is wrong then, |
You're right, the comment should say "must". Saying "should" is not accurate.
Actually, the root path is the only situation where it's actually harmless to leave out the trailing slash, the I have another question for you. Did you know that Line 31 in fe4b603
Why did you try to set I ask because if it's not clear that |
Because we support GitHub Enterprise too ;) |
This PR provides logic to return an error if there is no slash at the end of BaseURL or UploadURL. Related comment: google#690 (comment)
Go creates servers without the trailing slash (https://golang.org/src/net/http/httptest/server.go, Line 27). @gravis was right in that this is a breaking change. |
Yes, but I believe this was addressed in #692. |
Yeah it gives you the error but I guess it's unfortunate that there is an inconsistency and you have to add random slashes |
If there is no trailing slash in BaseURL, I think that it is ideal to have the same result as when there is a trailing slash.