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

Use .serveStatic and .on for same URI #195

Open
MicDG opened this issue Oct 23, 2024 · 6 comments
Open

Use .serveStatic and .on for same URI #195

MicDG opened this issue Oct 23, 2024 · 6 comments

Comments

@MicDG
Copy link

MicDG commented Oct 23, 2024

Hello, doing something like this:

httpServer.on("/index.html", HTTP_POST, [](PsychicRequest *request) {
    // Do sth
});
httpServer.serveStatic("/index.html", LittleFS, "/index.html");

causes the server to return an error like "httpd_uri: Method '1' not allowed for URI" when a GET request is made. However doing this works:

httpServer.on("/index.html", HTTP_POST, [](PsychicRequest *request) {
    // Do sth
});
httpServer.on("/index.html", HTTP_GET, [](PsychicRequest *request) {
    // Return file
});

I guess this is due to the fact that .serveStatic is an handler and doesn't register any endpoint. Is there a way around this, beyond using two endpoints (it's just for brevity I guess, not having to reimplement a function to serve the file).

@MicDG
Copy link
Author

MicDG commented Oct 23, 2024

Sorry, just saw this can be used:


String filename = "/path/to/file";
PsychicFileResponse response(request, LittleFS, filename);

return response.send();

However, maybe this could be added in the ReadMe notes just for clarity.

@hitecSmartHome
Copy link

After IDF 5.3 there will be HTTP_ANY support

@hoeken
Copy link
Owner

hoeken commented Oct 30, 2024 via email

@hitecSmartHome
Copy link

Actually in psychic 2.0 we add HTTP_ANY support, and with 5.3 it's much cleaner internally. :)

On Wed, Oct 30, 2024, 04:32 HITEC @.> wrote: After IDF 5.3 there will be HTTP_ANY support — Reply to this email directly, view it on GitHub <#195 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABEHSQIWHHFLCX3VYBKC6TZ6CRTBAVCNFSM6AAAAABQOPO2VGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINBWGMZDKNZVGM . You are receiving this because you are subscribed to this thread.Message ID: @.>

Does that mean that the v2 is already using your planned approach with HTTP_ANY and the library's own list of handlers?

@mathieucarbou
Copy link
Collaborator

@hitecSmartHome yes!

@hitecSmartHome
Copy link

Wow. I must try it

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

No branches or pull requests

4 participants