Commit Graph

11 Commits

Author SHA1 Message Date
Marc Mutz 845eedf66d QHttpServerRouter: use unqiue_ptr to accept rules
They're already stored in unique_ptr internally, so use the more
expressive pass-unique_ptr-by-value idiom to express ownership
transfer, so the docs don't need to mention it anymore.

Also fixes a theoretical memleak on failed vector::emplace_back().

Pick-to: 6.4
Task-number: QTBUG-100868
Change-Id: I32e386378fe177e4890deea44f0e937c8054c1c6
Reviewed-by: Jesus Fernandez <jsfdez@gmail.com>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
2022-06-22 16:17:36 +02:00
Marc Mutz cb25d34789 Fix std::forward uses
- in route() implementations, the viewHandler was passed by universal
  reference, however, it was then captured either by value (copying,
  which some viewHandlers may not support) or - yuck - by reference,
  creating a dangling pointer in case a temporary was passed. This
  error was also present in the example implementations in the docs
  and the test. To fix, std::forward the viewHandler into the mutable
  lambda and std::move() it inside the lambda into
  route.bindCaptured().

- One more case of RouterHandler being passed by rvalue ref and then
  std::forward()ed, fixed by taking by value and std::move()ing
  instead.

Pick-to: 6.4
Task-number: QTBUG-100868
Change-Id: I729f7e0c8fd0838679bcefc141fd5cea333d276b
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Jesus Fernandez <jsfdez@gmail.com>
2022-06-22 10:15:42 +02:00
Mikhail Svetkin e0fa374411 Add QHttpServer::afterRequest
This function allows to register a function to be run after each request.

Task-number: QTBUG-77090
Change-Id: I40dd4c1e9a447fbe034149ffc1923c7c814cf0e9
Reviewed-by: Mikhail Svetkin <mikhail.svetkin@gmail.com>
2020-05-14 20:36:31 +02:00
Mikhail Svetkin 9719bf64bb Add dependencies file for Coin
Coin by default uses dev branch of qtbase.
Add 5.12 qtbase into the dependencies file

Change-Id: I849ea65e36c74f153dbd5531c01e3a3b00ab4fef
Reviewed-by: Mikhail Svetkin <mikhail.svetkin@gmail.com>
2020-04-19 00:01:36 +02:00
Mikhail Svetkin 43a04e17a1 Allow using QHttpServerRequest/Responder at the same time
Fixes: QTBUG-77088
Change-Id: I2208cee290d086339aba705f959c57e0f6a73a87
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2019-10-25 08:55:01 +02:00
Mikhail Svetkin 3eebefcd27 QHttpServerRouterViewTraits: Make it simpler and testable
Currently QHttpServerRouterViewTraits contains all helpers and tools
inside itself. It is hard to read and extend.

This patch:
- Moves all helper and tools to QtPrivate namespace
- Tries to "simplify" template magic
- Adds support for unit test

Change-Id: I6aa443b286c4c896b8dbfee85fffb638328868ad
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2019-10-24 11:56:21 +02:00
Mikhail Svetkin be06bd66b8 Accept a string as request method in QHttpServer::route()
Allow writing simpler source code.

For example:

httpserver.route("/", "GET|POST", [] () { return ""; })

Instead of:

httpserver.route("/", QHttpServerRequest::Method::Post | QHttpServerRequest::Method::Get, [] () { return ""; })

Change-Id: Id0a754eccaba6b5f9f3be6a3b975383eb94840a0
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2019-04-04 20:50:09 +00:00
Maurice Kalinowski 572e0b1f6c Fix build on Windows
Change-Id: I7bb287dedfc146ba717a69170cec529d7ef7fadb
Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2019-02-28 10:08:19 +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 a856556784 Introduce QHttpServerRouter
Provide simple API for routing, parsing, capture and call callback

Change-Id: Ibd7c37282d00bd56f96d841db92b473a65a2bf5c
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
2019-01-23 10:46:43 +00:00