Selaa lähdekoodia

Rewrite request parsing (Step 27/?)

bel2125 8 vuotta sitten
vanhempi
commit
b81e8cd1ae

+ 5 - 0
docs/api/mg_get_request_info.md

@@ -18,6 +18,11 @@
 
 The function `mg_get_request_info()` returns information about the request on a given connection. This information is returned as a pointer to a [`mg_request_info`](mg_request_info.md) structure. If an error occurs, a NULL pointer is returned instead.
 
+Use this function when implementing a server.
+
 ### See Also
 
 * [`struct mg_request_info;`](mg_request_info.md)
+* [`mg_get_response_info();`](mg_get_response_info.md)
+* [`struct mg_response_info;`](mg_response_info.md)
+

+ 29 - 0
docs/api/mg_get_response_info.md

@@ -0,0 +1,29 @@
+# Civetweb API Reference
+
+### `mg_get_response_info( conn );`
+
+### Parameters
+
+| Parameter | Type | Description |
+| :--- | :--- | :--- |
+|**`conn`**|`const struct mg_connection *`|The connection for which the response info is needed|
+
+### Return Value
+
+| Type | Description |
+| :--- | :--- |
+|`const struct mg_request_info *`|Pointer to the requested info, or NULL if an error occured|
+
+### Description
+
+The function `mg_response_info()` returns information about a response on a client connection opened by `mg_connect_client()`. If an error occurs, a NULL pointer is returned instead.
+
+Use this function when implementing a client.
+
+### See Also
+
+* [`struct mg_response_info;`](mg_response_info.md)
+* [`mg_connect_client();`](mg_connect_client.md)
+* [`mg_get_request_info();`](mg_get_request_info.md)
+* [`struct mg_request_info;`](mg_request_info.md)
+

+ 38 - 0
docs/api/mg_response_info.md

@@ -0,0 +1,38 @@
+# Civetweb API Reference
+
+### `struct mg_response_info;`
+
+### Fields
+
+struct mg_response_info {
+        int status_code;          /* E.g. 200 */
+        const char *status_text;  /* E.g. "OK" */
+        const char *http_version; /* E.g. "1.0", "1.1" */
+
+        long long content_length; /* Length (in bytes) of the request body,
+                                     can be -1 if no length was given. */
+
+        int num_headers; /* Number of HTTP headers */
+        struct mg_header
+            http_headers[MG_MAX_HEADERS]; /* Allocate maximum headers */
+};
+
+| Field | Type | Description |
+| :--- | :--- | :--- |
+|**`status code`**|`int`| The HTTP response code received by the client. |
+|**`status_text`**|`const char *`| The textual representation of the HTTP status code. |
+|**`http_version`**|`const char *`| The HTTP version as mentioned in the client request. This can be "1.0", "1.1", etc. |
+|**`content_length`**|`long long`| The content length of the request body. This value can be -1 if no content length was provided. The request may still have body data, but the server cannot determine the length until all data has arrived (e.g. when the client closes the connection, or the final chunk of a chunked request has been received). |
+|**`num_headers`**|`int`| The number of HTTP request headers sent by the client (see http_headers) |
+|**`http_headers`**|`struct mg_header[64]`| Array of structures with the HTTP request headers sent by the client. For the number of filled header fields, ee num_headers. |
+
+Note: This structure is not yet feature complete and will be extended in future versions.
+
+### Description
+
+The `mg_response_info` structure contains information on a completed request from a client.
+
+### See Also
+
+* [`struct mg_header;`](mg_header.md)
+* [`mg_get_response_info();`](mg_get_response_info.md)

+ 9 - 2
include/civetweb.h

@@ -604,12 +604,19 @@ CIVETWEB_API int mg_modify_passwords_file(const char *passwords_file_name,
 
 /* Return information associated with the request.
  * Use this function to implement a server and get data about a request
- * from a HTTP/HTTPS client. */
+ * from a HTTP/HTTPS client.
+ * Note: Before CivetWeb 1.10, this function could be used to read
+ * a response from a server, when implementing a client, although the
+ * values were never returned in appropriate mg_request_info elements.
+ * It is strongly advised to use mg_get_response_info for clients.
+ */
 CIVETWEB_API const struct mg_request_info *
 mg_get_request_info(const struct mg_connection *);
 
 
-/* Return information associated with the request. */
+/* Return information associated with a HTTP/HTTPS response.
+ * Use this function in a client, to check the response from
+ * the server. */
 CIVETWEB_API const struct mg_response_info *
 mg_get_response_info(const struct mg_connection *);
 

+ 1 - 1
src/civetweb.c

@@ -14900,7 +14900,7 @@ mg_connect_websocket_client(const char *host,
 	                   origin);
 
 	/* Connection object will be null if something goes wrong */
-    if (conn == NULL) {
+	if (conn == NULL) {
 		if (!*error_buffer) {
 			/* There should be already an error message */
 			mg_snprintf(conn,