diff options
| author | Nakidai <nakidai@disroot.org> | 2024-11-24 15:51:45 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2024-11-24 15:51:45 +0300 |
| commit | 0cd2e735fd54f96e4765b823cded724c61572031 (patch) | |
| tree | b74fd7d78daac4dd6933717a1c74a09bcbef198b /src/response.c | |
| download | libhttpc-0cd2e735fd54f96e4765b823cded724c61572031.tar.gz libhttpc-0cd2e735fd54f96e4765b823cded724c61572031.zip | |
Add code
Diffstat (limited to 'src/response.c')
| -rw-r--r-- | src/response.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/response.c b/src/response.c new file mode 100644 index 0000000..1000da6 --- /dev/null +++ b/src/response.c @@ -0,0 +1,32 @@ +#include "libhttpc.h" + +#include <stddef.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; + +#define append(X) strncat(buf, (X), buf_len - strlen(buf)) + append(response->version); + append(""); + append(response->status); + append(" "); + append(response->phrase); + append("\r\n"); + for (size_t i = 0; i < response->header_count; ++i) + { + append(response->header_names[i]); + append(": "); + append(response->header_values[i]); + append("\r\n"); + } + append("\r\n"); + if (response->body) + append(response->body); +#undef append + + return NULL; +} |