| 336 | } |
| 337 | |
| 338 | bool CLiveSession::ParseHeader() { |
| 339 | size_t pos1 = dataCatch.find("\r\n"); //��һ�еĽ�β |
| 340 | size_t pos2 = dataCatch.find("\r\n\r\n"); //ͷ�Ľ�βλ�� |
| 341 | string reqline = dataCatch.substr(0, pos1); //��һ�е����� |
| 342 | vector<string> reqlines = StringHandle::StringSplit(reqline, ' '); |
| 343 | if(reqlines.size() != 3) |
| 344 | return false; |
| 345 | |
| 346 | |
| 347 | method = reqlines[0].c_str(); |
| 348 | path = reqlines[1]; |
| 349 | version = reqlines[2].c_str(); |
| 350 | string rawHeaders = dataCatch.substr(pos1+2, pos2-pos1); |
| 351 | dataCatch = dataCatch.substr(pos2+4, dataCatch.size()-pos2-4); |
| 352 | |
| 353 | vector<string> headers = StringHandle::StringSplit(rawHeaders, "\r\n"); |
| 354 | for(auto &hh : headers) { |
| 355 | string name, value; |
| 356 | bool b = false; |
| 357 | for(auto &c:hh){ |
| 358 | if(!b) { |
| 359 | if(c == ':'){ |
| 360 | b = true; |
| 361 | } else { |
| 362 | name.push_back(c); |
| 363 | } |
| 364 | } else { |
| 365 | if(!value.empty() || c != ' ') |
| 366 | value.push_back(c); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | if(!strcasecmp(name.c_str(), "Connection")) { |
| 371 | Connection = value; |
| 372 | } else if(!strcasecmp(name.c_str(), "Upgrade")) { |
| 373 | Upgrade = value; |
| 374 | } else if(!strcasecmp(name.c_str(), "Sec-WebSocket-Key")) { |
| 375 | SecWebSocketKey = value; |
| 376 | } else if(!strcasecmp(name.c_str(), "x-forwarded-for")) { |
| 377 | xForwardedFor = value; |
| 378 | } |
| 379 | } |
| 380 | return true; |
| 381 | } |
| 382 | |
| 383 | bool CLiveSession::ParsePath() { |
| 384 | vector<string> uri = StringHandle::StringSplit(path, '?'); |