summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--include/libhttpc.h14
-rw-r--r--src/response.c15
2 files changed, 20 insertions, 9 deletions
diff --git a/include/libhttpc.h b/include/libhttpc.h
index bb0f35b..08d4b80 100644
--- a/include/libhttpc.h
+++ b/include/libhttpc.h
@@ -168,12 +168,14 @@ struct LibHTTPC_Request
  */
 struct LibHTTPC_Response
 {
-    char          *buf;                       /**< Pointer to char *response */
-    const char    *version, *status, *phrase; /**< Response line */
-    const char   **header_names;              /**< \ Header parallel array */
-    const char   **header_values;             /**< / Header parallel array */
-    const char    *body;                      /**< Pointer to body */
-    size_t         header_count;              /**< Length of header array */
+    char                   *buf;                        /**< Pointer to char *response */
+    const char             *version;                    /**< HTTP version */
+    enum LibHTTPC_Status    status;                     /**< Status code */
+    const char             *phrase;                     /**< Phrase describing status code */
+    const char            **header_names;               /**< \ Header parallel array */
+    const char            **header_values;              /**< / Header parallel array */
+    const char             *body;                       /**< Pointer to body */
+    size_t                  header_count;               /**< Length of header array */
 };
 
 /**
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");