diff --git a/docs/README.md b/docs/README.md index bf523060..058048db 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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"); ``` +### 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() diff --git a/mongoose.c b/mongoose.c index 733ef61e..50ffee10 100644 --- a/mongoose.c +++ b/mongoose.c @@ -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) { if (ev == MG_EV_READ || ev == MG_EV_CLOSE) { struct mg_http_message hm; diff --git a/mongoose.h b/mongoose.h index a6d288ae..b376f3ff 100644 --- a/mongoose.h +++ b/mongoose.h @@ -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); 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 *); +int mg_http_status(const struct mg_http_message *hm); void mg_http_serve_ssi(struct mg_connection *c, const char *root, diff --git a/src/http.c b/src/http.c index a11e7d6e..23cd103e 100644 --- a/src/http.c +++ b/src/http.c @@ -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) { if (ev == MG_EV_READ || ev == MG_EV_CLOSE) { struct mg_http_message hm; diff --git a/src/http.h b/src/http.h index 05952cdd..5bcf64b8 100644 --- a/src/http.h +++ b/src/http.h @@ -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); 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 *); +int mg_http_status(const struct mg_http_message *hm);