File indexing completed on 2025-02-16 04:51:24
0001 /* 0002 SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #ifndef KITINERARY_HTTPRESPONSE_H 0007 #define KITINERARY_HTTPRESPONSE_H 0008 0009 #include "kitinerary_export.h" 0010 0011 #include <QDateTime> 0012 #include <QExplicitlySharedDataPointer> 0013 #include <QMetaType> 0014 #include <QUrl> 0015 0016 class QJsonObject; 0017 class QNetworkReply; 0018 0019 namespace KItinerary { 0020 0021 class HttpResponsePrivate; 0022 0023 /** 0024 * Container for an HTTP response to be passed into the extractor engine. 0025 * This is primarily needed for extracting data from arbitrary API responses 0026 * or for custom website extractors, as we cannot trigger extractor scripts 0027 * on HTTP request or response parameters (such as the URL) otherwise. 0028 * 0029 * For operational use this can be created from a QNetworkReply, the support for 0030 * HAR files is mainly intended for development use. 0031 */ 0032 class KITINERARY_EXPORT HttpResponse 0033 { 0034 Q_GADGET 0035 Q_PROPERTY(QUrl url READ url) 0036 Q_PROPERTY(QByteArray content READ content) 0037 Q_PROPERTY(QDateTime requestDateTime READ requestDateTime) 0038 0039 public: 0040 HttpResponse(); 0041 ~HttpResponse(); 0042 HttpResponse(const HttpResponse&); 0043 HttpResponse& operator=(const HttpResponse&); 0044 operator QVariant() const; 0045 0046 QUrl url() const; 0047 QByteArray content() const; 0048 QDateTime requestDateTime() const; 0049 0050 /** Create a HttpResponse object from an active QNetworkReply. */ 0051 static HttpResponse fromNetworkReply(QNetworkReply *reply); 0052 /** Read from an HAR entry. 0053 * @see https://w3c.github.io/web-performance/specs/HAR/Overview.html 0054 */ 0055 Q_DECL_HIDDEN static HttpResponse fromHarEntry(const QJsonObject &harEntry); 0056 /** Read a set of HTTP responses from an HAR file. */ 0057 Q_DECL_HIDDEN static QList<HttpResponse> fromHarFile(const QByteArray &harFile); 0058 0059 private: 0060 QExplicitlySharedDataPointer<HttpResponsePrivate> d; 0061 }; 0062 0063 } 0064 0065 Q_DECLARE_METATYPE(KItinerary::HttpResponse) 0066 0067 #endif // KITINERARY_HTTPRESPONSE_H