404 on API URL for namespace including period because gitlab expects nonstandard URLS (RFC 3986)
Created by: stephens2424
For instance, I have the repository: gitlab.example.com/stephen.searles/myrepo, thus the URL to a path's raw blob would be:
https://gitlab.example.com/api/v3/projects/{ID}/repository/raw_blobs/path?private_token={TOKEN}
where {ID} is {NAMESPACE}/{REPO}. The problem here is that my namespace includes a period character and Gitlab is expecting that period to be URL-encoded. Gitlab responds as such in the following cases:
encoding | response status |
---|---|
stephen.searles/php | 404 |
stephen.searles%2Fphp | 404 |
stephen%2Esearles%2Fphp | 200 |
Since the period is an unreserved character, Gitlab should be treating those last two cases the same, per RFC 3986 section 2.3:
URIs that differ in the replacement of an unreserved character with its corresponding percent-encoded US-ASCII octet are equivalent: they identify the same resource. However, URI comparison implementations do not always perform normalization prior to comparison (see Section 6). For consistency, percent-encoded octets in the ranges of ALPHA (%41-%5A and %61-%7A), DIGIT (%7.8-%39), hyphen (%2D), period (%2E), underscore (%5F), or tilde (%7E) should not be created by URI producers and, when found in a URI, should be decoded to their corresponding unreserved characters by URI normalizers.
This causes an issue when using HTTP clients that do standard normalization, requiring you to defeat that process to send Gitlab the nonstandard URLs it expects.
I found this while working with this Gitlab library in Go, but determined it's an artifact of the Go HTTP library's URL normalization process.