Add support for basic Netlify redirects
Add support for basic Netlify redirects
- Fix #24 (closed)
- Supports basic 301, 302 Netlify style redirects using plain text style
_redirects
- https://docs.netlify.com/routing/redirects/
- The other more advanced options are not supported: https://docs.netlify.com/routing/redirects/redirect-options/
- The
_redirects
file is not publicly accessible but when you visit/_redirects
, it will show validation messages per line of_redirects
file - Documentation MR: gitlab!42011 (merged)
Benchmarks
Need to look into the numbers to see if actually acceptable:
Previous
$ go test ./internal/redirects -bench=.
goos: darwin
goarch: amd64
pkg: gitlab.com/gitlab-org/gitlab-pages/internal/redirects
BenchmarkRedirectsRewrite/10_redirects-8 158222 7207 ns/op
BenchmarkRedirectsRewrite/100_redirects-8 98227 12031 ns/op
BenchmarkRedirectsRewrite/1000_redirects-8 19407 61143 ns/op
BenchmarkRedirectsParseRedirects/10_redirects-8 6319 173126 ns/op
BenchmarkRedirectsParseRedirects/100_redirects-8 5889 198681 ns/op
BenchmarkRedirectsParseRedirects/1000_redirects-8 2431 499812 ns/op
PASS
ok gitlab.com/gitlab-org/gitlab-pages/internal/redirects 8.119s
Latest:
- Parse 1000 redirects takes 0.296 ms (296043 ns)
- Rewrite URL matching the last rule in 1000 takes 0.058475 ms (58475 ns)
$ go test ./internal/redirects -bench=.
goos: darwin
goarch: amd64
pkg: gitlab.com/gitlab-org/gitlab-pages/internal/redirects
BenchmarkRedirectsRewrite/10_redirects-8 294306 3864 ns/op
BenchmarkRedirectsRewrite/100_redirects-8 128731 8844 ns/op
BenchmarkRedirectsRewrite/1000_redirects-8 20427 58361 ns/op
BenchmarkRedirectsParseRedirects/10_redirects-8 29253 41024 ns/op
BenchmarkRedirectsParseRedirects/100_redirects-8 18249 65300 ns/op
BenchmarkRedirectsParseRedirects/1000_redirects-8 3867 297138 ns/op
PASS
ok gitlab.com/gitlab-org/gitlab-pages/internal/redirects 9.209s
Dev notes
- http://group.redirects.pages.gdk.test:8090/project-redirects/redirect-portal.html
- http://group.redirects.pages.gdk.test:8090/project-redirects/magic-land.html
$ make
$ ./gitlab-pages -listen-http ":8090" -pages-root shared/pages -pages-domain pages.gdk.test -log-verbose
make test
go test ./internal/serving/disk/
go test ./internal/serving/disk/ -run TestDisk_ServeFileHTTP
make setup
make lint
Running benchmarks:
go test ./internal/redirects -bench=.
Running acceptance tests:
go test ./ -run TestStatusPage
go test ./ -run TestRedirectStatusPage -test.v
go test ./ -run TestRedirect -test.v
go test ./ -list=Test
Todo
-
Blocked by !325 (merged) -
Acceptance tests -
Benchmarks -
Feature flag -
Docs -> gitlab!42011 (merged) -
Add feature flag to https://ops.gitlab.net/gitlab-cookbooks/chef-repo -
Try out Netlify behavior of file overriding redirect, !336 (comment 403520570)
Fix #24 (closed)
Edited by Eric Eastwood