9
9
#include < fcntl.h>
10
10
#include < netdb.h>
11
11
#include < poll.h>
12
+
13
+ #include < cctype>
12
14
#include < iostream>
13
15
14
16
#define PC_EPOLL_FLAGS (EPOLLIN|EPOLLET|EPOLLRDHUP|EPOLLHUP|EPOLLERR)
@@ -985,7 +987,7 @@ ws_parser *http_server::get_ws_parser() const
985
987
return wp_;
986
988
}
987
989
988
- bool http_server::get_header_val ( const str & key, str& val) const
990
+ bool http_server::get_header_val ( const std::string & key, str& val ) const
989
991
{
990
992
for (unsigned i=0 ; i != hnms_.size (); ++i ) {
991
993
if ( key == hnms_[i] ) {
@@ -1015,7 +1017,7 @@ bool http_server::parse( const char *ptr, size_t len, size_t& res )
1015
1017
if ( !next ( LF, ++ptr, end ) ) return false ;
1016
1018
1017
1019
// parse other header lines
1018
- bool has_len = false , has_upgrade = false ;;
1020
+ bool has_len = false , has_upgrade = false ;
1019
1021
size_t clen = 0 ;
1020
1022
for (++ptr;;++ptr) {
1021
1023
if ( ptr <= &end[-2 ] && ptr[0 ] == CR && ptr[1 ] == LF ) {
@@ -1029,16 +1031,19 @@ bool http_server::parse( const char *ptr, size_t len, size_t& res )
1029
1031
if ( !find ( CR, ptr, end ) ) return false ;
1030
1032
assert ( hdr_end >= hdr );
1031
1033
const size_t hlen = static_cast < size_t >( hdr_end - hdr );
1034
+ std::string hdr_str{ hdr, hlen };
1035
+ for ( char & c : hdr_str ) {
1036
+ c = std::toupper ( static_cast < unsigned char >( c ) );
1037
+ }
1032
1038
assert ( ptr >= val );
1033
1039
const size_t vlen = static_cast < size_t >( ptr - val );
1034
- if ( has_len || (
1035
- 0 != __builtin_strncmp ( " Content-Length" , hdr, hlen ) &&
1036
- 0 != __builtin_strncmp ( " content-length" , hdr, hlen ) ) ) {
1037
- hnms_.push_back ( str ( hdr, hlen ) );
1040
+
1041
+ if ( has_len || hdr_str != " CONTENT-LENGTH" ) {
1042
+ hnms_.push_back ( hdr_str );
1038
1043
hval_.push_back ( str ( val, vlen ) );
1039
1044
if ( wp_ && !has_upgrade ) {
1040
1045
has_upgrade =
1041
- 0 == __builtin_strncmp ( " Upgrade " , hdr, hlen ) &&
1046
+ hdr_str == " UPGRADE " &&
1042
1047
0 == __builtin_strncmp ( " websocket" , val, vlen );
1043
1048
}
1044
1049
} else {
@@ -1070,7 +1075,7 @@ bool http_server::parse( const char *ptr, size_t len, size_t& res )
1070
1075
void http_server::upgrade_ws ()
1071
1076
{
1072
1077
str key;
1073
- if ( !get_header_val ( " Sec-WebSocket-Key " , key ) ) {
1078
+ if ( ! get_header_val ( " SEC-WEBSOCKET-KEY " , key ) ) {
1074
1079
return ;
1075
1080
}
1076
1081
const char *magic_id = " 258EAFA5-E914-47DA-95CA-C5AB0DC85B11" ;
0 commit comments