|
8 | 8 | #include <cstdio> |
9 | 9 | #include <httplib.h> |
10 | 10 | #include <iostream> |
| 11 | +#include <sstream> |
| 12 | +#include <iomanip> |
| 13 | +#include <openssl/md5.h> |
11 | 14 |
|
12 | 15 | #define SERVER_CERT_FILE "./cert.pem" |
13 | 16 | #define SERVER_PRIVATE_KEY_FILE "./key.pem" |
@@ -110,19 +113,32 @@ int main(int argc, const char **argv) { |
110 | 113 | }); |
111 | 114 |
|
112 | 115 | svr.Post("/multi2", [](Stream& strm, const Request &req, Response &res) { |
113 | | - std::string rsp="req body stream is :\n"; |
| 116 | + std::ostringstream rsp; |
| 117 | + rsp << "req body stream:\n"; |
| 118 | + MD5_CTX ctx; |
| 119 | + MD5_Init(&ctx); |
| 120 | + int nCall=0; |
114 | 121 |
|
115 | 122 | detail::read_content( |
116 | 123 | strm, req, std::numeric_limits<size_t>::max(), res.status |
117 | | - , req.progress, [&rsp] (const char *buf, size_t n){ |
118 | | - rsp+="cut("; |
119 | | - rsp.append(buf,n); |
120 | | - rsp+=")\n"; |
| 124 | + , req.progress, [&] (const char *buf, size_t n){ |
| 125 | + MD5_Update(&ctx, buf, n); |
| 126 | + nCall++; |
121 | 127 | return true; |
122 | 128 | } |
123 | 129 | ); |
| 130 | + unsigned char result[MD5_DIGEST_LENGTH+1]; |
124 | 131 |
|
125 | | - res.set_content(rsp, "text/plain"); |
| 132 | + rsp << "nCall:" << nCall <<std::endl; |
| 133 | + |
| 134 | + MD5_Final(result, &ctx); |
| 135 | + rsp << "md5:" ; |
| 136 | + for(int i =0; i<MD5_DIGEST_LENGTH; i++) { |
| 137 | + rsp << std::hex << std::setw(2) << std::setfill('0') << (int) result[i]; |
| 138 | + } |
| 139 | + rsp << std::endl; |
| 140 | + |
| 141 | + res.set_content(rsp.str(), "text/plain"); |
126 | 142 | }); |
127 | 143 |
|
128 | 144 | svr.set_error_handler([](const Request & /*req*/, Response &res) { |
|
0 commit comments