Add easy ability to set status codes and format response body#5
Open
Kiyoshika wants to merge 3 commits intoinfraredCoding:masterfrom
Open
Add easy ability to set status codes and format response body#5Kiyoshika wants to merge 3 commits intoinfraredCoding:masterfrom
Kiyoshika wants to merge 3 commits intoinfraredCoding:masterfrom
Conversation
After using the address sanitizer (-fsanitize=address) I noticed that the lack of null terminator on the response body was causing problems.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_Serverstruct 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.cfor the full example usage). This will automatically prepend the status code for us so we don't have to manuallystrncatit 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
OKandNOT_FOUNDstatus codes after slight modifications to themain.cexample.cerveur.status.codes.1.mp4