-
Notifications
You must be signed in to change notification settings - Fork 89
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
Gitlab support fixes #17
Conversation
api/gitlab.go
Outdated
finalLinkEntries := []string{} | ||
for _, linkEntry := range linkEntries { | ||
linkAndRel := strings.Split(strings.TrimSpace(linkEntry), ";") | ||
link := proxyAPIURL + strings.TrimPrefix(gitlabLinkRegex.FindStringSubmatch(linkAndRel[0])[1], endpointAPIURL) |
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.
you're indexing into matches, are we 100% sure that these regexes will not fail (odd inputs)?
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 added length-checking before match access to ensure that it's working as expected - the link entry is simply returned unchanged if something goes wrong (this is per-link, so the other links in the Link
header can still be rewritten if one doesn't match what we expect).
also if you want to update the Go version, it might be worth it right now. |
api/gitlab.go
Outdated
|
||
func rewriteGitlabLinks(linkHeader, endpointAPIURL, proxyAPIURL string) string { | ||
linkEntries := strings.Split(linkHeader, ",") | ||
finalLinkEntries := []string{} |
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.
you can save some allocations by creating the slice with fixed capacity:
finalLinkEntries := make([]string, len(linkEntries), len(linkEntries))
It looks like this requires a docs update. At this point, I think that means some minor changes to the README and an update to |
api/gitlab.go
Outdated
linkEntries := strings.Split(linkHeader, ",") | ||
finalLinkEntries := make([]string, len(linkEntries), len(linkEntries)) | ||
for _, linkEntry := range linkEntries { | ||
finalLinkEntries = append(finalLinkEntries, rewriteGitlabLinkEntry(linkEntry, endpointAPIURL, proxyAPIURL)) |
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 think that with the pre-allocation this will cause it to have a bunch of blanks. You'll want to use the index.
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.
Addressed, thanks for the catch.
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.
lgtm. I'd love to see more tests in this project in general, but not going to force it.
Fixes several bugs with GitLab support in git-gateway:
HEAD
requests to the allowed CORS methods."Private-Token"
to the allowed CORS headers.r.URL.Opaque
instead of by settingr.URL.Path
to prevent literal%2F
s in URLs, which are required by the GitLab API, from being turned into literal/
characters by the Go stdlib. (see this github issue and this commit, noting thatgit-gateway
is running ongo1.8
if I understand correctly from the.travis.yml
).Authorization
header from GitLab requests, which causes 401s when used with private access tokens (example), and replaces it with thePrivate-Token
header. (The current WIP Netlify UI has a box for a token to be pasted, so I assume this is supposed to be a private access token, not an OAuth token - which would use theAuthorization
header).Link
header to be relative, so they're requested from git-gateway instead of the proxied API.