浏览代码

Document new API function

bel2125 7 年之前
父节点
当前提交
293412ae17
共有 2 个文件被更改,包括 33 次插入0 次删除
  1. 1 0
      docs/api/mg_send_http_error.md
  2. 32 0
      docs/api/mg_send_http_ok.md

+ 1 - 0
docs/api/mg_send_http_error.md

@@ -27,6 +27,7 @@ A body of the error message, to explain the error in more detail, can be specifi
 
 ### See Also
 
+* [`mg_send_http_ok();`](mg_send_http_ok.md)
 * [`mg_printf();`](mg_printf.md)
 * [`mg_write();`](mg_write.md)
 

+ 32 - 0
docs/api/mg_send_http_ok.md

@@ -0,0 +1,32 @@
+# Civetweb API Reference
+
+### `mg_send_http_ok( conn, mime_type, content_len, ... );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`struct mg_connection *`|The connection over which the data must be sent|
+|**`mime_type`**|`const char *`|The content type to be sent|
+|**`content_len`**|`long long`|Length of the following body data|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+
+
+### Description
+
+The function `mg_send_http_ok()` can be used to send a "HTTP 200 OK" response header, including typical response headers like date, length, content type, "no caching" and additional headers from the server configuration.
+A proper content type (`mime_type`) has to be supplied (e.g., "text/plain", "text/html", "application/json", ...)
+The. `status_code` must be one of the predefined HTTP standard error codes (e.g., "404" for "Not Found").
+The `content_len` specifies the size of the response body in bytes. If the size is not yet known, a value of -1 could be supplied to select chunked transfer encoding. After `mg_send_http_ok()`, the server callback must send body, either using [`mg_write`](mg_write.md) (typical for known `content_len`), or using [`mg_send_chunk`](mg_send_chunk.md) (chunked encoding for unknown content length).
+
+
+### See Also
+
+* [`mg_send_http_error();`](mg_send_http_ok.md)
+* [`mg_write();`](mg_write.md)
+* [`mg_send_chunk();`](mg_send_chunk.md)
+