* handle the WebSocket header reading * @param client WSclient_t * ptr to the client struct */
| 549 | * @param client WSclient_t * ptr to the client struct |
| 550 | */ |
| 551 | void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) { |
| 552 | |
| 553 | headerLine->trim(); // remove \r |
| 554 | |
| 555 | if(headerLine->length() > 0) { |
| 556 | DEBUG_WEBSOCKETS("[WS-Client][handleHeader] RX: %s\n", headerLine->c_str()); |
| 557 | |
| 558 | if(headerLine->startsWith(WEBSOCKETS_STRING("HTTP/1."))) { |
| 559 | // "HTTP/1.1 101 Switching Protocols" |
| 560 | client->cCode = headerLine->substring(9, headerLine->indexOf(' ', 9)).toInt(); |
| 561 | } else if(headerLine->indexOf(':')) { |
| 562 | String headerName = headerLine->substring(0, headerLine->indexOf(':')); |
| 563 | String headerValue = headerLine->substring(headerLine->indexOf(':') + 1); |
| 564 | |
| 565 | // remove space in the beginning (RFC2616) |
| 566 | if(headerValue[0] == ' ') { |
| 567 | headerValue.remove(0, 1); |
| 568 | } |
| 569 | |
| 570 | if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Connection"))) { |
| 571 | if(headerValue.equalsIgnoreCase(WEBSOCKETS_STRING("upgrade"))) { |
| 572 | client->cIsUpgrade = true; |
| 573 | } |
| 574 | } else if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Upgrade"))) { |
| 575 | if(headerValue.equalsIgnoreCase(WEBSOCKETS_STRING("websocket"))) { |
| 576 | client->cIsWebsocket = true; |
| 577 | } |
| 578 | } else if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Sec-WebSocket-Accept"))) { |
| 579 | client->cAccept = headerValue; |
| 580 | client->cAccept.trim(); // see rfc6455 |
| 581 | } else if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Sec-WebSocket-Protocol"))) { |
| 582 | client->cProtocol = headerValue; |
| 583 | } else if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Sec-WebSocket-Extensions"))) { |
| 584 | client->cExtensions = headerValue; |
| 585 | } else if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Sec-WebSocket-Version"))) { |
| 586 | client->cVersion = headerValue.toInt(); |
| 587 | } else if(headerName.equalsIgnoreCase(WEBSOCKETS_STRING("Set-Cookie"))) { |
| 588 | if(headerValue.indexOf(WEBSOCKETS_STRING("HttpOnly")) > -1) { |
| 589 | client->cSessionId = headerValue.substring(headerValue.indexOf('=') + 1, headerValue.indexOf(";")); |
| 590 | } else { |
| 591 | client->cSessionId = headerValue.substring(headerValue.indexOf('=') + 1); |
| 592 | } |
| 593 | } |
| 594 | } else { |
| 595 | DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Header error (%s)\n", headerLine->c_str()); |
| 596 | } |
| 597 | |
| 598 | (*headerLine) = ""; |
| 599 | #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) |
| 600 | client->tcp->readStringUntil('\n', &(client->cHttpLine), std::bind(&WebSocketsClient::handleHeader, this, client, &(client->cHttpLine))); |
| 601 | #endif |
| 602 | |
| 603 | } else { |
| 604 | DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Header read fin.\n"); |
| 605 | DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Client settings:\n"); |
| 606 | |
| 607 | DEBUG_WEBSOCKETS("[WS-Client][handleHeader] - cURL: %s\n", client->cUrl.c_str()); |
| 608 | DEBUG_WEBSOCKETS("[WS-Client][handleHeader] - cKey: %s\n", client->cKey.c_str()); |
nothing calls this directly
no outgoing calls
no test coverage detected