1 | // Copyright (C) 2022 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "qhttpserverstream_p.h" |
5 | |
6 | #include <QtNetwork/qtcpsocket.h> |
7 | |
8 | #if QT_CONFIG(ssl) |
9 | #include <QtNetwork/qsslsocket.h> |
10 | #endif |
11 | |
12 | QT_BEGIN_NAMESPACE |
13 | |
14 | QHttpServerStream::QHttpServerStream(QObject *parent) |
15 | : QObject(parent) |
16 | { |
17 | } |
18 | |
19 | QHttpServerRequest QHttpServerStream::initRequestFromSocket(QTcpSocket *tcpSocket) |
20 | { |
21 | if (tcpSocket) { |
22 | #if QT_CONFIG(ssl) |
23 | if (auto *ssl = qobject_cast<const QSslSocket *>(object: tcpSocket)) { |
24 | return QHttpServerRequest(ssl->peerAddress(), ssl->peerPort(), |
25 | ssl->localAddress(), ssl->localPort(), |
26 | ssl->sslConfiguration()); |
27 | } |
28 | #endif |
29 | return QHttpServerRequest(tcpSocket->peerAddress(), tcpSocket->peerPort(), |
30 | tcpSocket->localAddress(), tcpSocket->localPort()); |
31 | } |
32 | |
33 | return QHttpServerRequest(QHostAddress::LocalHost, 0, QHostAddress::LocalHost, 0); |
34 | } |
35 | |
36 | QT_END_NAMESPACE |
37 |