| 269 | } |
| 270 | |
| 271 | void ProtocolHttp::parseHeader(const char *ptr, const char *end, Socket *sock) const |
| 272 | { |
| 273 | auto protoRequest = static_cast<ProtoRequestHttp *>(sock->protoData); |
| 274 | const char *word_boundary = ptr; |
| 275 | while (*word_boundary != ':' && word_boundary < end) { |
| 276 | ++word_boundary; |
| 277 | } |
| 278 | const auto key = QByteArray(ptr, int(word_boundary - ptr)); |
| 279 | |
| 280 | while ((*word_boundary == ':' || *word_boundary == ' ') && word_boundary < end) { |
| 281 | ++word_boundary; |
| 282 | } |
| 283 | const auto value = QByteArray(word_boundary, int(end - word_boundary)); |
| 284 | |
| 285 | if (protoRequest->headerConnection == ProtoRequestHttp::HeaderConnection::NotSet && |
| 286 | key.compare("Connection", Qt::CaseInsensitive) == 0) { |
| 287 | if (value.compare("close", Qt::CaseInsensitive) == 0) { |
| 288 | protoRequest->headerConnection = ProtoRequestHttp::HeaderConnection::Close; |
| 289 | } else { |
| 290 | protoRequest->headerConnection = ProtoRequestHttp::HeaderConnection::Keep; |
| 291 | } |
| 292 | } else if (protoRequest->contentLength < 0 && |
| 293 | key.compare("Content-Length", Qt::CaseInsensitive) == 0) { |
| 294 | bool ok; |
| 295 | qint64 cl = value.toLongLong(&ok); |
| 296 | if (ok && cl >= 0) { |
| 297 | protoRequest->contentLength = cl; |
| 298 | } |
| 299 | } else if (!protoRequest->headerHost && key.compare("Host", Qt::CaseInsensitive) == 0) { |
| 300 | protoRequest->serverAddress = value; |
| 301 | protoRequest->headerHost = true; |
| 302 | } else if (usingFrontendProxy) { |
| 303 | if (!protoRequest->X_Forwarded_For && |
| 304 | (key.compare("X-Forwarded-For", Qt::CaseInsensitive) == 0 || |
| 305 | key.compare("X-Real-Ip", Qt::CaseInsensitive) == 0)) { |
| 306 | // configure your reverse-proxy to list only one IP address |
| 307 | protoRequest->remoteAddress.setAddress(QString::fromLatin1(value)); |
| 308 | protoRequest->remotePort = 0; // unknown |
| 309 | protoRequest->X_Forwarded_For = true; |
| 310 | } else if (!protoRequest->X_Forwarded_Host && |
| 311 | key.compare("X-Forwarded-Host", Qt::CaseInsensitive) == 0) { |
| 312 | protoRequest->serverAddress = value; |
| 313 | protoRequest->X_Forwarded_Host = true; |
| 314 | protoRequest->headerHost = true; // ignore a following Host: header (if any) |
| 315 | } else if (!protoRequest->X_Forwarded_Proto && |
| 316 | key.compare("X-Forwarded-Proto", Qt::CaseInsensitive) == 0) { |
| 317 | protoRequest->isSecure = (value.compare("https") == 0); |
| 318 | protoRequest->X_Forwarded_Proto = true; |
| 319 | } |
| 320 | } |
| 321 | protoRequest->headers.pushHeader(key, value); |
| 322 | } |
| 323 | |
| 324 | ProtoRequestHttp::ProtoRequestHttp(Socket *sock, int bufferSize) |
| 325 | : ProtocolData(sock, bufferSize) |
nothing calls this directly
no test coverage detected