fixed some warning

This commit is contained in:
2019-06-04 00:03:37 +08:00
parent e1423e9fa8
commit c7a6b9b05f
6 changed files with 12 additions and 10 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ int main() {
chttp::Server s { };
chttp::Router router { };
router.Get("/about", [](chttp::Request req, chttp::Response res) {
cout << req.URL().GetParam("key") << endl;
cout << req.URL().GetURLParam("key") << endl;
res.ServeHtml("index.html");
});
s.SetRouter(router);
+7 -5
View File
@@ -102,13 +102,15 @@ void Response::NotFound() {
void Response::WriteSocket(Sock_type sock, const char* buffer, size_t size,
int flags) {
int length = size;
int length = static_cast<int>(size);
if (size == 0)
length = strlen(buffer);
length = static_cast<int>(strlen(buffer));
send(sock, buffer, length, flags);
//std::cout << "write to socket:";
//for (size_t i = 0; i < length; ++i)
// cout << buffer[i];
#ifdef DEBUG
std::cout << "write to socket:";
for (size_t i = 0; i < length; ++i)
cout << buffer[i];
#endif // DEBUG
}
inline void Response::CloseSocket(Sock_type sock)
+1 -1
View File
@@ -66,7 +66,7 @@ public:
}
inline void SetContentType(std::string&& content_type) {
header.Content()["Content-Type"] = content_type;
header.Content()["content-type"] = content_type;
}
private:
+1 -1
View File
@@ -64,7 +64,7 @@ int Server::GetLine(Sock_type sock, char* buf, int size) {
vector<string> Server::ReadRequest(const Sock_type& clnt_sock) {
int char_count { 1 };
char buffer[buffer_size];
char buffer[buffer_size] = "";
vector<string> content { };
while (char_count > 0 && strcmp("\n", buffer)) {
char_count = GetLine(clnt_sock, buffer, sizeof(buffer));
+1 -1
View File
@@ -7,7 +7,7 @@
#include "url.h"
using namespace std;
std::string chttp::URL::GetParam(const std::string& key)const
std::string chttp::URL::GetURLParam(const std::string& key)const
{
smatch result;
if (regex_search(_url.cbegin(), _url.cend(), result, regex{ key + "=(.*?)&" })
+1 -1
View File
@@ -22,7 +22,7 @@ public:
inline std::string GetURL() const { return _url; }
inline std::string& GetURL() { return _url; }
std::string GetParam(const std::string& key)const;
std::string GetURLParam(const std::string& key)const;
inline bool operator == (const URL& other)const { return this->_url == other._url; }
inline bool operator != (const URL& other)const { return this->_url != other._url; }