diff options
| author | Nakidai <nakidai@disroot.org> | 2024-11-24 18:26:42 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2024-11-24 18:26:42 +0300 |
| commit | c7d38eb85062c86c2ca6c411a8c805501a748e59 (patch) | |
| tree | af841f2c4d8b0c6db7bdf6e7b062d3dfdb5408c5 /src/response.c | |
| parent | db7553eda4ed2feefac4859f59f79ee8e3d20e3f (diff) | |
| download | libhttpc-c7d38eb85062c86c2ca6c411a8c805501a748e59.tar.gz libhttpc-c7d38eb85062c86c2ca6c411a8c805501a748e59.zip | |
QoL things
- Make response.status be LibHTTPC_Status - Add defaults in LibHTTPC_dumpResponse
Diffstat (limited to 'src/response.c')
| -rw-r--r-- | src/response.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/response.c b/src/response.c index 1000da6..d3411ae 100644 --- a/src/response.c +++ b/src/response.c @@ -1,18 +1,27 @@ #include "libhttpc.h" #include <stddef.h> +#include <stdio.h> #include <string.h> char *LibHTTPC_dumpResponse(struct LibHTTPC_Response *response, char *buf, size_t buf_len) { - if (!response->version || !response->status || !response->phrase) - return NULL; + char status[10]; + + if (!response->version) + response->version = "HTTP/1.1"; + if (!response->status) + response->status = 200; + if (!response->phrase) + response->phrase = LibHTTPC_dumpStatus(LibHTTPC_Status_OK); + + snprintf(status, sizeof(status), "%d", response->status); #define append(X) strncat(buf, (X), buf_len - strlen(buf)) append(response->version); append(""); - append(response->status); + append(status); append(" "); append(response->phrase); append("\r\n"); |