Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The directory path does not end with '/', it needs to be redirected #1572

Merged
merged 3 commits into from Aug 28, 2020
Merged

The directory path does not end with '/', it needs to be redirected #1572

merged 3 commits into from Aug 28, 2020

Conversation

sotex
Copy link
Contributor

@sotex sotex commented May 13, 2020

#1533 (comment)

Reference golang source code

https://github.com/golang/go/blob/cf9b4f63a57b4360be700831781885fc6cf5a0b1/src/net/http/fs.go#L575-L612

	if redirect {
		// redirect to canonical path: / at end of directory url
		// r.URL.Path always begins with /
		url := r.URL.Path
		if d.IsDir() {
			if url[len(url)-1] != '/' {
				localRedirect(w, r, path.Base(url)+"/")
				return
			}
		} else {
			if url[len(url)-1] == '/' {
				localRedirect(w, r, "../"+path.Base(url))
				return
			}
		}
	}


	if d.IsDir() {
		url := r.URL.Path
		// redirect if the directory name doesn't end in a slash
		if url == "" || url[len(url)-1] != '/' {
			localRedirect(w, r, path.Base(url)+"/")
			return
		}


		// use contents of index.html for directory, if present
		index := strings.TrimSuffix(name, "/") + indexPage
		ff, err := fs.Open(index)
		if err == nil {
			defer ff.Close()
			dd, err := ff.Stat()
			if err == nil {
				name = index
				d = dd
				f = ff
			}
		}
	}

@codecov
Copy link

@codecov codecov bot commented May 15, 2020

Codecov Report

Merging #1572 into master will increase coverage by 0.12%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1572      +/-   ##
==========================================
+ Coverage   84.96%   85.08%   +0.12%     
==========================================
  Files          28       28              
  Lines        2168     2186      +18     
==========================================
+ Hits         1842     1860      +18     
  Misses        211      211              
  Partials      115      115              
Impacted Files Coverage Δ
echo.go 86.10% <100.00%> (+0.25%) ⬆️
middleware/recover.go 82.35% <100.00%> (+9.62%) ⬆️
context.go 89.72% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 43e32ba...d506533. Read the comment docs.

@stale
Copy link

@stale stale bot commented Jul 18, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added wontfix and removed wontfix labels Jul 18, 2020
solym and others added 3 commits Jul 19, 2020
* Fix recover print stack trace log level

* Add recover log level test

* Add default LogLevel to DefaultRecoverConfig
@vishr vishr merged commit 28020c2 into labstack:master Aug 28, 2020
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants