mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-26 06:37:07 +00:00
The proxy returned HTML pages only. uv with --exclude-newer drops files that carry no upload time, so every file was filtered out. The handler now negotiates the representation from the Accept header, as PyPI does. It passes the upstream JSON through, including PEP 700 upload-time, and rewrites only the file URLs. HTML clients keep HTML. The handler also fetches the PEP 658 metadata sidecar and trusts the configured upstream host for file URLs.
33 lines
1.4 KiB
Go
33 lines
1.4 KiB
Go
package pypi
|
|
|
|
import "testing"
|
|
|
|
func TestNegotiateFormat(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
accept string
|
|
want format
|
|
wantOK bool
|
|
}{
|
|
{"no header serves html", "", formatHTML, true},
|
|
{"wildcard serves html", "*/*", formatHTML, true},
|
|
{"browser", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", formatHTML, true},
|
|
{"uv", "application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html;q=0.2, text/html;q=0.01", formatJSON, true},
|
|
{"pip", "application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html; q=0.1, text/html; q=0.01", formatJSON, true},
|
|
{"explicit html", "application/vnd.pypi.simple.v1+html", formatHTML, true},
|
|
{"latest json alias", "application/vnd.pypi.simple.latest+json", formatJSON, true},
|
|
{"html preferred by q", "application/vnd.pypi.simple.v1+json;q=0.1, text/html", formatHTML, true},
|
|
{"json q zero refused", "application/vnd.pypi.simple.v1+json;q=0, text/html;q=0.5", formatHTML, true},
|
|
{"unsupported only", "application/xml", formatHTML, false},
|
|
{"tie prefers json", "text/html, application/vnd.pypi.simple.v1+json", formatJSON, true},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, ok := negotiateFormat(tt.accept)
|
|
if ok != tt.wantOK || (ok && got != tt.want) {
|
|
t.Errorf("negotiateFormat(%q) = (%v, %v), want (%v, %v)", tt.accept, got, ok, tt.want, tt.wantOK)
|
|
}
|
|
})
|
|
}
|
|
}
|