Commit Graph

18 Commits

Author SHA1 Message Date
Matthias Rauter 76e55a052f Set missinghandler callback with a context object and remove rvalue
Use QtPrivate::makeCallableObject() and a context object instead
of std::function() when calling setMissingHandler(). Also added
clearMissingHandler() to set the handler back to the default behavior.

The rvalue was exchanged with a reference in the callback signature
because QMetaObject::invokeMethod is not prepared to handle rvalues.

Pick-to: 6.8
Task-Id: QTBUG-128113
Change-Id: If02c67a0ee200b458d9f8051a23a9307fce6e59a
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2024-08-30 17:57:37 +02:00
Øystein Heskestad bd5ac90224 QAbstractHttpServer: Remove QSslConfiguration and listen() methods
To keep the API lean, remove the SSL confguration and listen()
methods.

Instead using listen() on a QAbstractHttpServer, a user should
create an instance of a QTcpServer or QSslServer, then call
listen() on it before calling bind() on a QAbstractHttpServer
with it as an argument.

Task-number: QTBUG-125859
Pick-to: 6.8
Change-Id: I366c0a01d8b7ee3802e0bdd63b9d84813338f478
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2024-07-31 16:52:41 +02:00
Lena Biliaieva bcfed45d9b Use QHttpHeaders in QHttpServerResponder
Fixes: QTBUG-120135
Change-Id: Ic0c60884b7bc1a05edf55c20b944268445c56e87
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
2024-02-21 15:36:55 +01:00
Ievgenii Meshcheriakov 55d10201dc Add connection tracking
Introduce private QHttpServerStream class that handles connection
state. This is the only class that contains a connected QTcpSocket.
Make other classes use QHttpServerResponder to communicate
with clients. Stop processing of further requests as long as a
QHttpServerResponder object for the current request is active.

Add a regression test to tst_qhttpserver.

[ChangeLog][Potentially Source-Incompatible Changes] Most public
methods that accepted a QTcpSocket are now accepting
QHttpServerResponder instead.

Task-number: QTBUG-105202
Change-Id: Ib8db7fdc65b59077411b09277f2b1948fde4848b
Reviewed-by: André Klitzing <aklitzing@gmail.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-11-14 11:15:59 +01:00
Marc Mutz 5ccbb879fa Port from container::count() and length() to size()
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8:

  auto QtContainerClass = anyOf(
      expr(hasType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))))).bind(o),
      expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o));
  makeRule(cxxMemberCallExpr(on(QtContainerClass),
                             callee(cxxMethodDecl(hasAnyName({"count", "length"),
                                                  parameterCountIs(0))))),
           changeTo(cat(access(o, cat("size"), "()"))),
           cat("use 'size()' instead of 'count()/length()'"))

a.k.a qt-port-to-std-compatible-api with config Scope: 'Container',
with the extended set of container classes recognized.

Change-Id: Ibb3c96e7b98fc3c5586b947e91cdc19d26e56c80
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-10-06 10:19:37 +02:00
Ievgenii Meshcheriakov 9da514a0fa QAbstractHttpServer: Convert missingHandler() to a pure virtual method
This ensures that there is exactly one handler. This also should make
it easier to rework the response handling.

Pick-to: 6.4
Change-Id: I5771d94a0b2436b2ff2b745335184a80f4b2cf31
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-08-25 14:16:00 +02:00
Ievgenii Meshcheriakov 1e8551ca16 QHttpServerLiterals: Inline literals in tests and unexport them
Also make tst_qhttpserverresponder and tst_qhttpserverresponse
public.

Pick-to: 6.4
Change-Id: I1b95d20c86799a6f1088e54599128b07f8290f6f
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Mikhail Svetkin <mikhail.svetkin@gmail.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-08-09 11:04:58 +02:00
Ievgenii Meshcheriakov 2cd9c66a25 tests: Use _ba instead of QByteArrayLiteral
Pick-to: 6.4
Change-Id: I8d41e169cd3dd489d8de54aeed052ff6a9e3edc3
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-08-08 18:01:00 +02:00
Lucie Gérard 57b0db0896 Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
License files are organized under LICENSES directory.

Pick-to: 6.4
Task-number: QTBUG-67283
Change-Id: I657c36f679b9448ec68d411a492171bc39df1411
Reviewed-by: Jesus Fernandez <jsfdez@gmail.com>
2022-06-22 17:35:22 +02:00
Maurice Kalinowski 51734cd595 Fix build against 6.0
Fixes: QTBUG-89381
Change-Id: I79d0329f06005434c691416f92fbdac0d7252385
Reviewed-by: Jesus Fernandez <jsfdez@gmail.com>
2020-12-16 19:10:36 +01:00
Mikhail Svetkin 4b2790aa6d Add cmake support for Qt6/dev branch
Change-Id: Icca0edab01d6028d786b76f99fba388565bd6e76
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2020-05-05 19:43:56 +02:00
Mikhail Svetkin f46cb8832f Add QHttpServerLiterals
Currently we have a lot of duplication of most common HTTP headers and their
values.
This patch moves them to one place.

Change-Id: Idf9ddc5164e81649b4cc37ed92a516eb1eedab3a
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Tasuku Suzuki <tasuku.suzuki@qbc.io>
2019-08-21 22:07:26 +02:00
Mikhail Svetkin 055d36692b QHttpServerResponder: refactor and extend the API
Currently QHttpServerResponder is not flexible enough:
 - Does not allow to rewrite headers
 - Does not allow to write headers without storing them internaly first
 - Does not provide API to make your own HTTP response

This patch will help to implement QHttpServerResponse
setHeaders/addHeaders

Change-Id: If9e21f7f7a58629bfedad0f10cab67d67fce0a89
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2019-08-20 18:40:26 +02:00
Tasuku Suzuki f72ced1671 Fix tests failure introduced by the mime type detection
Commit 4f64330b39 changes some mime types
of responses to text/plain.
The commit also FIXED the "No newline at end of file" warning in a test
data for QHttpServerResponder.

Change-Id: I9b6b1878a2b61bf80db1e39b81ae75c4cedce615
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2019-05-09 13:57:18 +00:00
Jesus Fernandez 11fb154a84 Fix several build issues and fix the unit tests
It is required to have continuous integration enabled in the
repository.

Change-Id: I71728a6e89841640e77c50a05cf59f34d697f897
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2019-02-28 09:47:48 +00:00
Jesus Fernandez fe96330ca0 Fix license headers
Change-Id: Ie15244adb917e2938fe7897c30d4616218d26ac0
Reviewed-by: Mikhail Svetkin <mikhail.svetkin@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2019-01-31 11:31:21 +00:00
Mikhail Svetkin 2e7a824526 Refactor QHttpServerResponder::write(QIODevice, ...)
The current implementation has several problems.

1. The function takes an ownership the QIODevice and puts it into a smartpointer.
Also we conntected socket's destroyed signal to lambda which has captured the
smartpointer.
So if responder does not find the file, the smartpointer will
call deleteLater which then will call socket::destroyed and then lambda
will be called and try to access the smartpointer which does not exist
anymore.

2. The function takes an ownership the file(QIODevice)
and puts it into a smartpointer.
Also we conntected the QTemporaryFile's aboutToClose signal to lambda which has captured the
smartpointer.
So when the QTemporaryFile calls destructor it will emit aboutToClose
signal which will call the lambda and this lambda will try to access the smartpointer
which does not exist anymore.

3. If we send a file smaller than chunksize,
IOChunkedTransfer we will never be deleted.

4. Does not check a socket connection type (keep-alive).

5. Does not send anything if file is not found or opened in wrong
mode.

Change-Id: I699e7d5a462c4b8d195908747bf0386132b19973
Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
2018-10-04 08:12:29 +00:00
Jesus Fernandez f53818c8ef Introduce QHttpServerResponder
It encapsulates the socket and gives an API to answer the received
requests.

Change-Id: Ic95db2c50224a650a02b206faca9a0ff8d1cc62b
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Ryan Chu <ryan.chu@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2018-09-26 12:38:56 +00:00