Skip to content

Fix handling of / to load index.htm #1085

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

Closed
wants to merge 1 commit into from
Closed

Fix handling of / to load index.htm #1085

wants to merge 1 commit into from

Conversation

sticilface
Copy link
Contributor

Recent changes broke the handling of / leading to index.htm.

Im not sure if changing the requestUri is the best / or valid way to do this. but it works. It will just change it on first call to the handle.
If you prefer, I can make a local copy of the requestUri, append the index.htm if required, then use that throughout the rest of the function?

Recent changes broke the handling of / leading to index.htm.

Im not sure if changing the requestUri is the best / or valid way to do this.  but it works.  It will just change it on first call to the handle.  
If you prefer, I can make a local copy of the requestUri, append the index.htm if required, then use that throughout the rest of the function?
@pgollor
Copy link
Contributor

pgollor commented Nov 27, 2015

Thanks. I will check it at the weekend okay?

@sticilface
Copy link
Contributor Author

No problem.

I think it comes from the fact that the path does not have a leading / when it is a directory. when it is the request that should really interpreted. My concern is that it might be better to cache the uri within the handler rather than modify the uri. or if the uri is to be modified by appending index.htm then it could be done earlier before the handles are called. (if that makes sense)

@Links2004 Links2004 changed the title Fix handling of / to load index.hm Fix handling of / to load index.htm Nov 27, 2015
@pgollor
Copy link
Contributor

pgollor commented Nov 29, 2015

Sorry for the late replay. I did some tests and i think your usage of the serveStaic function is wrong.
In my opinion it have to be server.serveStatic("/index.htm", SPIFFS, "/test/index.htm", "max-age=86400");

This works without changing the source code.

@sticilface
Copy link
Contributor Author

I was under the impression that servestatic allows you to serve directories? What is the purpose of this part?

        if (!_isFile) { 
            // Base URI doesn't point to a file. Append whatever follows this
            // URI in request to get the file path.
            path += requestUri.substring(_baseUriLength); 
        }

This is a good feature as if you have 10 files in a directory you do not need a request handler for each separate file. Each handler uses a not insignificant amount of memory. It is standard web server behaviour to look for an index.htm file in a directory. Plus this used to work, before the refactoring a few commits back. That is just my two cents.

@sticilface
Copy link
Contributor Author

I think the important thing to emphasise is that this used to work, just fine.

@igrr
Copy link
Member

igrr commented Nov 30, 2015

Looks almost good to me.

Serving whole directories was actually what I had in mind when I added serveStatic. However due to a bug it could also be used to serve individual files. So both cases should work fine.

I moved the if(requestUri.endsWith("/")) clause inside if (!_isFile), because another valid use would be:

server.serveStatic("/info/", SPIFFS, "/info.html");

I.e. we should not try adding index.htm to the URI if target path is a file already.

I will close this pull, but thanks for pointing out the fix.

@igrr igrr closed this Nov 30, 2015
igrr added a commit that referenced this pull request Nov 30, 2015
@sticilface sticilface deleted the patch-1 branch January 1, 2016 12:52
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.

3 participants