Add easy ability to set status codes and format response body #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I did this PR independent of my other PR, #4 since I didn't know which one would be merged first (if any) to avoid complicating things. This is a rebase of the master branch (at the time).
I modified the
HTTP_Server
struct a bit to hold the status code and the response body. This comes with two new functions:Set the the status code using any of the pre-defined enums (listed below)
Prepare the response body before sending to the client (see
main.c
for the full example usage). This will automatically prepend the status code for us so we don't have to manuallystrncat
it ourselves.As of now the following status codes are supported:
I didn't add all of them, just what I feel like are probably the most common ones (it's easy enough to change in the future).
See the attached video sample where I tested the
OK
andNOT_FOUND
status codes after slight modifications to themain.c
example.cerveur.status.codes.1.mp4