How to recognise GitLab remote by HTTP header?
Problem to solve
I'm working on GitLab support for git-credential-manager [since implemented, see GitLab docs]. This makes it easy to conveniently authenticate to HTTPS remotes in web browser (OAuth) without having to create a personal access token.
Select an authentication method for 'https://gitlab.com/':
1. Web browser (default)
2. Personal access token
3. Username/password
option (enter for default):
A problem is identifying GitLab remotes. A heuristic is "domain starts with gitlab.", but this isn't the case for many GitLab instances, such as https://salsa.debian.org/
and https://code.videolan.org/
(more examples). It would be neat to recognise a GitLab remote by some HTTP header. Then git-credential-manager can offer help with OAuth.
This is how git-credential-manager recognises enterprise GitHub instances, by looking for HTTP header X-GitHub-Request-Id.
Proposal
Include some kind of X-Gitlab header on GitLab HTTP remotes:
Current headers from http -h head https://code.videolan.org/videolan/vlc.git
HTTP/1.1 302 Found Cache-Control: no-cache Connection: keep-alive Content-Type: text/html; charset=utf-8 Date: Sat, 01 Jan 2022 17:23:16 GMT Location: https://code.videolan.org/videolan/vlc Pragma: no-cache Referrer-Policy: strict-origin-when-cross-origin Server: nginx/1.21.5 X-Content-Type-Options: nosniff X-Download-Options: noopen X-Frame-Options: DENY X-I-Am-Here: foo X-Permitted-Cross-Domain-Policies: none X-Request-Id: 01FRBANG0QMQX9XGTWN9HWDF2X X-Runtime: 0.034397 X-Ua-Compatible: IE=edge X-Xss-Protection: 1; mode=block