Commit 36f16fdf authored by Nick Thomas's avatar Nick Thomas 💃

Merge branch 'pages-gz-symlink-0.4.4' into '0-4-stable'

Don't serve statically-compiled `.gz` files that are symlinks (v0.4.4)

See merge request gitlab/gitlab-pages!2
parents 34a68fc5 5f15bedf
Pipeline #11563132 passed with stage
in 1 minute and 48 seconds
v 0.4.4
- Don't serve statically-compiled `.gz` files that are symlinks
v 0.4.3
- Fix domain lookups when Pages is exposed on non-default ports
......
......@@ -35,8 +35,7 @@ func acceptsGZip(r *http.Request) bool {
func (d *domain) serveFile(w http.ResponseWriter, r *http.Request, fullPath string) error {
// Open and serve content of file
if acceptsGZip(r) {
_, err := os.Stat(fullPath + ".gz")
if err == nil {
if fi, err := os.Lstat(fullPath + ".gz"); err == nil && fi.Mode().IsRegular() {
// Set the content type based on the non-gzipped extension
_, haveType := w.Header()["Content-Type"]
if !haveType {
......@@ -70,8 +69,7 @@ func (d *domain) serveCustomFile(w http.ResponseWriter, r *http.Request, code in
// Open and serve content of file
ext := filepath.Ext(fullPath)
if acceptsGZip(r) {
_, err := os.Stat(fullPath + ".gz")
if err == nil {
if fi, err := os.Lstat(fullPath + ".gz"); err == nil && fi.Mode().IsRegular() {
// Serve up the gzipped version
fullPath += ".gz"
w.Header().Set("Content-Encoding", "gzip")
......
......@@ -121,6 +121,8 @@ func TestGroupServeHTTPGzip(t *testing.T) {
{"GET", "http://group.test.io/", nil, ";; gzip", "main-dir", false},
{"GET", "http://group.test.io/", nil, "middle-out", "main-dir", false},
{"GET", "http://group.test.io/", nil, "gzip; quality=1", "main-dir", false},
// Symlinked .gz files are not supported
{"GET", "http://group.test.io/gz-symlink", nil, "*", "data", false},
}
for _, tt := range testSet {
......
../config.json
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment