mirror of
https://github.com/lammertb/libhttp.git
synced 2025-08-10 14:23:00 +03:00
Renamed mg_ to httplib_
This commit is contained in:
@@ -23,30 +23,30 @@ class ExampleHandler : public CivetHandler
|
||||
{
|
||||
public:
|
||||
bool
|
||||
handleGet(CivetServer *server, struct mg_connection *conn)
|
||||
handleGet(CivetServer *server, struct httplib_connection *conn)
|
||||
{
|
||||
mg_printf(conn,
|
||||
httplib_printf(conn,
|
||||
"HTTP/1.1 200 OK\r\nContent-Type: "
|
||||
"text/html\r\nConnection: close\r\n\r\n");
|
||||
mg_printf(conn, "<html><body>\r\n");
|
||||
mg_printf(conn,
|
||||
httplib_printf(conn, "<html><body>\r\n");
|
||||
httplib_printf(conn,
|
||||
"<h2>This is an example text from a C++ handler</h2>\r\n");
|
||||
mg_printf(conn,
|
||||
httplib_printf(conn,
|
||||
"<p>To see a page from the A handler <a "
|
||||
"href=\"a\">click here</a></p>\r\n");
|
||||
mg_printf(conn,
|
||||
httplib_printf(conn,
|
||||
"<p>To see a page from the A handler with a parameter "
|
||||
"<a href=\"a?param=1\">click here</a></p>\r\n");
|
||||
mg_printf(conn,
|
||||
httplib_printf(conn,
|
||||
"<p>To see a page from the A/B handler <a "
|
||||
"href=\"a/b\">click here</a></p>\r\n");
|
||||
mg_printf(conn,
|
||||
httplib_printf(conn,
|
||||
"<p>To see a page from the *.foo handler <a "
|
||||
"href=\"xy.foo\">click here</a></p>\r\n");
|
||||
mg_printf(conn,
|
||||
httplib_printf(conn,
|
||||
"<p>To exit <a href=\"%s\">click here</a></p>\r\n",
|
||||
EXIT_URI);
|
||||
mg_printf(conn, "</body></html>\r\n");
|
||||
httplib_printf(conn, "</body></html>\r\n");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -55,12 +55,12 @@ class ExitHandler : public CivetHandler
|
||||
{
|
||||
public:
|
||||
bool
|
||||
handleGet(CivetServer *server, struct mg_connection *conn)
|
||||
handleGet(CivetServer *server, struct httplib_connection *conn)
|
||||
{
|
||||
mg_printf(conn,
|
||||
httplib_printf(conn,
|
||||
"HTTP/1.1 200 OK\r\nContent-Type: "
|
||||
"text/plain\r\nConnection: close\r\n\r\n");
|
||||
mg_printf(conn, "Bye!\n");
|
||||
httplib_printf(conn, "Bye!\n");
|
||||
exitNow = true;
|
||||
return true;
|
||||
}
|
||||
@@ -72,31 +72,31 @@ class AHandler : public CivetHandler
|
||||
bool
|
||||
handleAll(const char *method,
|
||||
CivetServer *server,
|
||||
struct mg_connection *conn)
|
||||
struct httplib_connection *conn)
|
||||
{
|
||||
std::string s = "";
|
||||
mg_printf(conn,
|
||||
httplib_printf(conn,
|
||||
"HTTP/1.1 200 OK\r\nContent-Type: "
|
||||
"text/html\r\nConnection: close\r\n\r\n");
|
||||
mg_printf(conn, "<html><body>");
|
||||
mg_printf(conn, "<h2>This is the A handler for \"%s\" !</h2>", method);
|
||||
httplib_printf(conn, "<html><body>");
|
||||
httplib_printf(conn, "<h2>This is the A handler for \"%s\" !</h2>", method);
|
||||
if (CivetServer::getParam(conn, "param", s)) {
|
||||
mg_printf(conn, "<p>param set to %s</p>", s.c_str());
|
||||
httplib_printf(conn, "<p>param set to %s</p>", s.c_str());
|
||||
} else {
|
||||
mg_printf(conn, "<p>param not set</p>");
|
||||
httplib_printf(conn, "<p>param not set</p>");
|
||||
}
|
||||
mg_printf(conn, "</body></html>\n");
|
||||
httplib_printf(conn, "</body></html>\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
bool
|
||||
handleGet(CivetServer *server, struct mg_connection *conn)
|
||||
handleGet(CivetServer *server, struct httplib_connection *conn)
|
||||
{
|
||||
return handleAll("GET", server, conn);
|
||||
}
|
||||
bool
|
||||
handlePost(CivetServer *server, struct mg_connection *conn)
|
||||
handlePost(CivetServer *server, struct httplib_connection *conn)
|
||||
{
|
||||
return handleAll("POST", server, conn);
|
||||
}
|
||||
@@ -106,14 +106,14 @@ class ABHandler : public CivetHandler
|
||||
{
|
||||
public:
|
||||
bool
|
||||
handleGet(CivetServer *server, struct mg_connection *conn)
|
||||
handleGet(CivetServer *server, struct httplib_connection *conn)
|
||||
{
|
||||
mg_printf(conn,
|
||||
httplib_printf(conn,
|
||||
"HTTP/1.1 200 OK\r\nContent-Type: "
|
||||
"text/html\r\nConnection: close\r\n\r\n");
|
||||
mg_printf(conn, "<html><body>");
|
||||
mg_printf(conn, "<h2>This is the AB handler!!!</h2>");
|
||||
mg_printf(conn, "</body></html>\n");
|
||||
httplib_printf(conn, "<html><body>");
|
||||
httplib_printf(conn, "<h2>This is the AB handler!!!</h2>");
|
||||
httplib_printf(conn, "</body></html>\n");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -122,68 +122,64 @@ class FooHandler : public CivetHandler
|
||||
{
|
||||
public:
|
||||
bool
|
||||
handleGet(CivetServer *server, struct mg_connection *conn)
|
||||
handleGet(CivetServer *server, struct httplib_connection *conn)
|
||||
{
|
||||
/* Handler may access the request info using mg_get_request_info */
|
||||
const struct mg_request_info *req_info = mg_get_request_info(conn);
|
||||
/* Handler may access the request info using httplib_get_request_info */
|
||||
const struct httplib_request_info *req_info = httplib_get_request_info(conn);
|
||||
|
||||
mg_printf(conn,
|
||||
httplib_printf(conn,
|
||||
"HTTP/1.1 200 OK\r\nContent-Type: "
|
||||
"text/html\r\nConnection: close\r\n\r\n");
|
||||
|
||||
mg_printf(conn, "<html><body>\n");
|
||||
mg_printf(conn, "<h2>This is the Foo GET handler!!!</h2>\n");
|
||||
mg_printf(conn,
|
||||
httplib_printf(conn, "<html><body>\n");
|
||||
httplib_printf(conn, "<h2>This is the Foo GET handler!!!</h2>\n");
|
||||
httplib_printf(conn,
|
||||
"<p>The request was:<br><pre>%s %s HTTP/%s</pre></p>\n",
|
||||
req_info->request_method,
|
||||
req_info->uri,
|
||||
req_info->http_version);
|
||||
mg_printf(conn, "</body></html>\n");
|
||||
httplib_printf(conn, "</body></html>\n");
|
||||
|
||||
return true;
|
||||
}
|
||||
bool
|
||||
handlePost(CivetServer *server, struct mg_connection *conn)
|
||||
handlePost(CivetServer *server, struct httplib_connection *conn)
|
||||
{
|
||||
/* Handler may access the request info using mg_get_request_info */
|
||||
const struct mg_request_info *req_info = mg_get_request_info(conn);
|
||||
/* Handler may access the request info using httplib_get_request_info */
|
||||
const struct httplib_request_info *req_info = httplib_get_request_info(conn);
|
||||
long long rlen, wlen;
|
||||
long long nlen = 0;
|
||||
long long tlen = req_info->content_length;
|
||||
char buf[1024];
|
||||
|
||||
mg_printf(conn,
|
||||
httplib_printf(conn,
|
||||
"HTTP/1.1 200 OK\r\nContent-Type: "
|
||||
"text/html\r\nConnection: close\r\n\r\n");
|
||||
|
||||
mg_printf(conn, "<html><body>\n");
|
||||
mg_printf(conn, "<h2>This is the Foo POST handler!!!</h2>\n");
|
||||
mg_printf(conn,
|
||||
httplib_printf(conn, "<html><body>\n");
|
||||
httplib_printf(conn, "<h2>This is the Foo POST handler!!!</h2>\n");
|
||||
httplib_printf(conn,
|
||||
"<p>The request was:<br><pre>%s %s HTTP/%s</pre></p>\n",
|
||||
req_info->request_method,
|
||||
req_info->uri,
|
||||
req_info->http_version);
|
||||
mg_printf(conn, "<p>Content Length: %li</p>\n", (long)tlen);
|
||||
mg_printf(conn, "<pre>\n");
|
||||
httplib_printf(conn, "<p>Content Length: %li</p>\n", (long)tlen);
|
||||
httplib_printf(conn, "<pre>\n");
|
||||
|
||||
while (nlen < tlen) {
|
||||
rlen = tlen - nlen;
|
||||
if (rlen > sizeof(buf)) {
|
||||
rlen = sizeof(buf);
|
||||
}
|
||||
rlen = mg_read(conn, buf, (size_t)rlen);
|
||||
if (rlen <= 0) {
|
||||
break;
|
||||
}
|
||||
wlen = mg_write(conn, buf, (size_t)rlen);
|
||||
if (rlen != rlen) {
|
||||
break;
|
||||
}
|
||||
rlen = httplib_read(conn, buf, (size_t)rlen);
|
||||
if (rlen <= 0) break;
|
||||
wlen = httplib_write(conn, buf, (size_t)rlen);
|
||||
if (rlen != rlen) break;
|
||||
nlen += wlen;
|
||||
}
|
||||
|
||||
mg_printf(conn, "\n</pre>\n");
|
||||
mg_printf(conn, "</body></html>\n");
|
||||
httplib_printf(conn, "\n</pre>\n");
|
||||
httplib_printf(conn, "</body></html>\n");
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -191,10 +187,10 @@ class FooHandler : public CivetHandler
|
||||
#define fopen_recursive fopen
|
||||
|
||||
bool
|
||||
handlePut(CivetServer *server, struct mg_connection *conn)
|
||||
handlePut(CivetServer *server, struct httplib_connection *conn)
|
||||
{
|
||||
/* Handler may access the request info using mg_get_request_info */
|
||||
const struct mg_request_info *req_info = mg_get_request_info(conn);
|
||||
/* Handler may access the request info using httplib_get_request_info */
|
||||
const struct httplib_request_info *req_info = httplib_get_request_info(conn);
|
||||
long long rlen, wlen;
|
||||
long long nlen = 0;
|
||||
long long tlen = req_info->content_length;
|
||||
@@ -220,7 +216,7 @@ class FooHandler : public CivetHandler
|
||||
if (rlen > sizeof(buf)) {
|
||||
rlen = sizeof(buf);
|
||||
}
|
||||
rlen = mg_read(conn, buf, (size_t)rlen);
|
||||
rlen = httplib_read(conn, buf, (size_t)rlen);
|
||||
if (rlen <= 0) {
|
||||
fail = 1;
|
||||
break;
|
||||
@@ -236,12 +232,12 @@ class FooHandler : public CivetHandler
|
||||
}
|
||||
|
||||
if (fail) {
|
||||
mg_printf(conn,
|
||||
httplib_printf(conn,
|
||||
"HTTP/1.1 409 Conflict\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Connection: close\r\n\r\n");
|
||||
} else {
|
||||
mg_printf(conn,
|
||||
httplib_printf(conn,
|
||||
"HTTP/1.1 201 Created\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Connection: close\r\n\r\n");
|
||||
|
Reference in New Issue
Block a user