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

http_response: fix move assign operator not moving file_info. #157

Merged
merged 1 commit into from
Jun 28, 2021

Conversation

luca-schlecker
Copy link
Collaborator

This PR fixes an issue I've been experiencing, leading to an error with static file serving as the client will receive net::ERR_CONTENT_LENGTH_MISMATCH.

My example project's main file:

#define CROW_MAIN
#include <crow.h>

int main() {
  crow::SimpleApp app;

  CROW_ROUTE(app, "/")
  ([](const crow::request& req) {
    crow::response r;
    r.set_static_file_info("index.html");
    return r;
  });

  app.port(80).multithreaded().run();

  return 0;
}

The error happens because of this check failing to recognize that the given response is of static type:
https://github.com/CrowCpp/crow/blob/189e0709b14e2c782f9dd94609bfd3af1212e1df/include/crow/http_connection.h#L398-L403

The function is_static_type checks for a path inside file_info which is set by set_static_file_info:
https://github.com/CrowCpp/crow/blob/189e0709b14e2c782f9dd94609bfd3af1212e1df/include/crow/http_response.h#L182-L185

The check returns false because after moving the response, file_info isn't being moved along with it, leading to an empty path:
https://github.com/CrowCpp/crow/blob/189e0709b14e2c782f9dd94609bfd3af1212e1df/include/crow/http_response.h#L84-L91

This is leading to a response with an empty body but a specific Content-Length being set, leading to the given error on the client's side.

Signed-off-by: Luca Schlecker [email protected]

@The-EDev
Copy link
Member

The-EDev commented Jun 28, 2021

Great work! Thanks a lot for pointing out this issue and taking the initiative to fix it! Thanks for the detailed description of the issue as well.

Let me know if you need any help taking this PR out of the draft phase, I'll merge it into 0.3 and master as soon as possible.

@luca-schlecker luca-schlecker marked this pull request as ready for review June 28, 2021 16:30
@luca-schlecker
Copy link
Collaborator Author

The CI passed and this PR should be ready to merge. 🚀
I'll look into updating the vcpkg port as soon as a patch is released. 👍

@The-EDev The-EDev merged commit 3c6f242 into CrowCpp:master Jun 28, 2021
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.

2 participants