Pārlūkot izejas kodu

Add functions from response.inl to API

bel2125 4 gadi atpakaļ
vecāks
revīzija
92e0e2ed22
2 mainītis faili ar 74 papildinājumiem un 6 dzēšanām
  1. 72 4
      include/civetweb.h
  2. 2 2
      src/response.inl

+ 72 - 4
include/civetweb.h

@@ -1473,6 +1473,7 @@ enum { TIMEOUT_INFINITE = -1 };
 #endif
 enum { MG_TIMEOUT_INFINITE = -1 };
 
+
 /* Wait for a response from the server
    Parameters:
      conn: connection
@@ -1484,10 +1485,77 @@ enum { MG_TIMEOUT_INFINITE = -1 };
      On success, >= 0
      On error/timeout, < 0
 */
-CIVETWEB_API int mg_get_response(struct mg_connection *conn,
-                                 char *ebuf,
-                                 size_t ebuf_len,
-                                 int timeout);
+CIVETWEB_API int 
+mg_get_response(struct mg_connection *conn,
+                char *ebuf,
+                size_t ebuf_len,
+                int timeout);
+
+
+/* Initialize a new HTTP response
+ * Parameters:
+ *   conn: Current connection handle.
+ *   status: HTTP status code (e.g., 200 for "OK").
+ * Return:
+ *   0:    ok
+ *  -1:    parameter error
+ *  -2:    invalid connection type
+ *  -3:    invalid connection status
+ */
+CIVETWEB_API int
+mg_response_start(struct mg_connection *conn, int status);
+
+
+/* Add a new HTTP response header line
+ * Parameters:
+ *   conn: Current connection handle.
+ *   header: Header name.
+ *   value: Header value.
+ *   value_len: Length of header value, excluding the terminating zero. 
+ *              Use -1 for "strlen(value)". 
+ * Return:  
+ *   0:    ok 
+ *  -1:    parameter error 
+ *  -2:    invalid connection type
+ *  -3:    invalid connection status
+ *  -4:    too many headers
+ *  -5:    out of memory
+ */
+CIVETWEB_API int
+mg_response_add_header(struct mg_connection *conn,
+	const char *header,
+	const char *value,
+	int value_len);
+
+
+/* Add a complete header string (key + value).
+ * Parameters:
+ *   conn: Current connection handle.
+ *   http1_headers: Header line(s) in the form "name: value".
+ * Return:
+ *  >=0:   no error, number of header lines added
+ *  -1:    parameter error
+ *  -2:    invalid connection type
+ *  -3:    invalid connection status
+ *  -4:    too many headers
+ *  -5:    out of memory
+ */
+CIVETWEB_API int
+mg_response_add_headerlines(struct mg_connection *conn,
+	const char *http1_headers);
+
+
+/* Send http response
+ * Parameters:
+ *   conn: Current connection handle.
+ * Return:
+ *   0:    ok
+ *  -1:    parameter error
+ *  -2:    invalid connection type
+ *  -3:    invalid connection status
+ */
+CIVETWEB_API int
+mg_response_send_headers(struct mg_connection *conn);
 
 
 /* Check which features where set when the civetweb library has been compiled.

+ 2 - 2
src/response.inl

@@ -104,9 +104,9 @@ mg_response_add_header(struct mg_connection *conn,
 	conn->response_info.http_headers[hidx].name =
 	    mg_strdup_ctx(header, conn->phys_ctx);
 	if (value_len >= 0) {
-		char *hbuf = mg_malloc_ctx(value_len + 1, conn->phys_ctx);
+		char *hbuf = mg_malloc_ctx((unsigned)value_len + 1, conn->phys_ctx);
 		if (hbuf) {
-			memcpy(hbuf, value, value_len);
+			memcpy(hbuf, value, (unsigned)value_len);
 			hbuf[value_len] = 0;
 		}
 		conn->response_info.http_headers[hidx].value = hbuf;