summaryrefslogtreecommitdiffstats
path: root/src/httpserver/qhttpserverstream.cpp
blob: 873061deb255845eb345f9af73ec7a8bbb71e772 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include "qhttpserverstream_p.h"

#include <QtNetwork/qtcpsocket.h>

#if QT_CONFIG(ssl)
#include <QtNetwork/qsslsocket.h>
#endif

QT_BEGIN_NAMESPACE

static QHttpServerParser initParserFromSocket(QIODevice *socket)
{
    QTcpSocket *tcpSocket = qobject_cast<QTcpSocket *>(socket);
    if (tcpSocket) {
        return QHttpServerParser(tcpSocket->peerAddress(), tcpSocket->peerPort(),
                                 tcpSocket->localAddress(), tcpSocket->localPort());
    }
    return QHttpServerParser(QHostAddress::LocalHost, 0, QHostAddress::LocalHost, 0);
}

#if QT_CONFIG(ssl)
static QSslConfiguration initSslConfigurationFromSocket(QIODevice *socket)
{
    if (auto *ssl = qobject_cast<const QSslSocket *>(socket))
        return ssl->sslConfiguration();

    return QSslConfiguration();
}
#endif

QHttpServerStream::QHttpServerStream(QIODevice *socket, QObject *parent)
    : QObject(parent)
    , parser(initParserFromSocket(socket))
#if QT_CONFIG(ssl)
    , sslConfiguration(initSslConfigurationFromSocket(socket))
#endif
{
}

QT_END_NAMESPACE