Fix #1462 - add helper function for getting HTTP response status code.

This commit is contained in:
Sergey Lyubka committed 2022-02-12 16:51:37 +00:00
1 parent 1adf7f6b2b
commit da72dafbfb
5 files changed
+21

No files matched your search

+11
View File
@@ -766,6 +766,17 @@ struct mg_connection *c = mg_http_connect(&mgr, "http://google.com", fn, NULL);
if (c == NULL) fatal_error("Cannot create connection"); if (c == NULL) fatal_error("Cannot create connection");
``` ```
### mg\_http\_status()
```c
int mg_http_status(const struct mg_http_message *hm);
```
Get status code of the HTTP response.
Parameters:
- `hm` - Parsed HTTP response
Return value: status code, e.g. `200` for success.
### mg\_http\_get\_request\_len() ### mg\_http\_get\_request\_len()
+4
View File
@@ -1899,6 +1899,10 @@ int mg_http_upload(struct mg_connection *c, struct mg_http_message *hm,
} }
} }
int mg_http_status(const struct mg_http_message *hm) {
return atoi(hm->uri.ptr);
}
static void http_cb(struct mg_connection *c, int ev, void *evd, void *fnd) { static void http_cb(struct mg_connection *c, int ev, void *evd, void *fnd) {
if (ev == MG_EV_READ || ev == MG_EV_CLOSE) { if (ev == MG_EV_READ || ev == MG_EV_CLOSE) {
struct mg_http_message hm; struct mg_http_message hm;
+1
View File
@@ -939,6 +939,7 @@ int mg_http_upload(struct mg_connection *, struct mg_http_message *hm,
void mg_http_bauth(struct mg_connection *, const char *user, const char *pass); void mg_http_bauth(struct mg_connection *, const char *user, const char *pass);
struct mg_str mg_http_get_header_var(struct mg_str s, struct mg_str v); struct mg_str mg_http_get_header_var(struct mg_str s, struct mg_str v);
size_t mg_http_next_multipart(struct mg_str, size_t, struct mg_http_part *); size_t mg_http_next_multipart(struct mg_str, size_t, struct mg_http_part *);
int mg_http_status(const struct mg_http_message *hm);
void mg_http_serve_ssi(struct mg_connection *c, const char *root, void mg_http_serve_ssi(struct mg_connection *c, const char *root,
+4
View File
@@ -905,6 +905,10 @@ int mg_http_upload(struct mg_connection *c, struct mg_http_message *hm,
} }
} }
int mg_http_status(const struct mg_http_message *hm) {
return atoi(hm->uri.ptr);
}
static void http_cb(struct mg_connection *c, int ev, void *evd, void *fnd) { static void http_cb(struct mg_connection *c, int ev, void *evd, void *fnd) {
if (ev == MG_EV_READ || ev == MG_EV_CLOSE) { if (ev == MG_EV_READ || ev == MG_EV_CLOSE) {
struct mg_http_message hm; struct mg_http_message hm;
+1
View File
@@ -62,3 +62,4 @@ int mg_http_upload(struct mg_connection *, struct mg_http_message *hm,
void mg_http_bauth(struct mg_connection *, const char *user, const char *pass); void mg_http_bauth(struct mg_connection *, const char *user, const char *pass);
struct mg_str mg_http_get_header_var(struct mg_str s, struct mg_str v); struct mg_str mg_http_get_header_var(struct mg_str s, struct mg_str v);
size_t mg_http_next_multipart(struct mg_str, size_t, struct mg_http_part *); size_t mg_http_next_multipart(struct mg_str, size_t, struct mg_http_part *);
int mg_http_status(const struct mg_http_message *hm);