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

Adds IgnoreBase parameter to static middleware #1701

Merged
merged 2 commits into from
Dec 2, 2020
Merged

Conversation

lnenad
Copy link
Contributor

@lnenad lnenad commented Nov 30, 2020

Adds IgnoreBase parameter to static middleware to support the use case of nested route groups.

I've run into a use case of having a route group that is used with static middleware, but when you access the group's base url the filesystem path is doubled. For example

group := root.Group("somepath")
group .Use(middleware.Static(filepath.Join("filesystempath")))

When an incoming request comes for /somepath the actual filesystem request goes to filesystempath/somepath instead of only filesystempath. This is what is being solved with this PR.

It includes tests for both branches, with bool value set to true, or default -> false.

Adds IgnoreBase parameter to static middleware to support the use case of nested route groups
e.ServeHTTP(rec, req)

assert.Equal(http.StatusOK, rec.Code)
assert.Contains(rec.Body.String(), "..\\_fixture\\_fixture")
Copy link
Contributor

@iambenkay iambenkay Nov 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be ../_fixture/_fixture?

Copy link
Contributor Author

@lnenad lnenad Nov 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was doing it on a windows machine, and was trying to write tests quickly so I made a rookie mistake, I'll add system path separators instead.

@codecov
Copy link

codecov bot commented Dec 1, 2020

Codecov Report

Merging #1701 (5716616) into master (502cce2) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1701      +/-   ##
==========================================
+ Coverage   84.88%   84.93%   +0.04%     
==========================================
  Files          29       29              
  Lines        1945     1951       +6     
==========================================
+ Hits         1651     1657       +6     
  Misses        187      187              
  Partials      107      107              
Impacted Files Coverage Δ
middleware/static.go 68.65% <100.00%> (+3.08%) ⬆️

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 502cce2...5716616. Read the comment docs.

@lnenad
Copy link
Contributor Author

lnenad commented Dec 1, 2020

I am now thinking if maybe this behavior (of trimming duplicate path) should be default, as it seems like a bug that the path is duplicated.

@iambenkay
Copy link
Contributor

@lnenad it would have been great as a default in my opinion but that would be a breaking change. it's best left optional.
let's just call it a design flaw 😂🥂

@lnenad
Copy link
Contributor Author

lnenad commented Dec 1, 2020

@iambenkay Cool, any idea when is this going to be merged, I need this functionality and I don't like using forks if I don't have to :)?

@iambenkay
Copy link
Contributor

@lammel

@lammel
Copy link
Contributor

lammel commented Dec 2, 2020

Looks good and is a common pitfall for some users. Thanks @lnenad .
Could you also do a PR for the documentation in labstack/echox?
That would make it also more prominent.

@lnenad
Copy link
Contributor Author

lnenad commented Dec 2, 2020

Yes, I would be glad to. Thanks

@lammel lammel merged commit a908413 into labstack:master Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants