if you look at this your mother will die in her sleep

This commit is contained in:
malloc 2018-04-02 17:04:21 -05:00
parent 47134fece3
commit f238152970
3 changed files with 39 additions and 3 deletions

View file

@ -30,12 +30,35 @@ int sosc::ScapeConnection::Handshake() {
return SOSC_SHAKE_ERR; return SOSC_SHAKE_ERR;
} }
auto lines = str::split(this->buffer, "\r\n");
if(!str::contains(this->buffer, "\r\n\r\n")) if(!str::contains(this->buffer, "\r\n\r\n"))
return SOSC_SHAKE_CONT; return SOSC_SHAKE_CONT;
std::string websocket_key = "";
auto lines = str::split(this->buffer, "\r\n");
for(auto line_r = lines.begin() + 1; line_r != lines.end(); ++line_r) {
std::string line = str::trim(*line_r);
if(str::starts(line, "Sec-WebSocket-Key")) {
auto parts = str::split(line, ':');
if(parts.size() < 2)
break;
websocket_key = str::trim(parts[1]);
break;
}
}
if(websocket_key == "") {
this->Close();
return SOSC_SHAKE_ERR;
}
std::stringstream stream;
stream << "HTTP/1.1 101 Switching Protocols\r\n"
<< "Upgrade: websocket\r\n"
<< "Connection: Upgrade\r\n"
<< "Sec-WebSock";
this->handshaked = true; this->handshaked = true;
return SOSC_SHAKE_DONE; return SOSC_SHAKE_DONE;
} }

View file

@ -120,3 +120,13 @@ bool sosc::str::contains
{ {
return haystack.find(needle) != std::string::npos; return haystack.find(needle) != std::string::npos;
} }
std::string sosc::str::tolower(std::string str) {
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
return str;
}
std::string* sosc::str::tolower(std::string* str) {
std::transform(str->begin(), str->end(), str->begin(), ::tolower);
return str;
}

View file

@ -35,6 +35,9 @@ bool starts(const std::string& str, const std::string& start);
bool ends(const std::string& str, const std::string& end); bool ends(const std::string& str, const std::string& end);
bool contains(const std::string& haystack, const std::string& needle); bool contains(const std::string& haystack, const std::string& needle);
std::string tolower(std::string str);
std::string* tolower(std::string* str);
}} }}
#endif #endif