KItinerary

httpresponseprocessor.cpp
1/*
2 SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#include "httpresponseprocessor.h"
7
8#include "http/httpresponse.h"
9
10#include <KItinerary/ExtractorDocumentNode>
11#include <KItinerary/ExtractorDocumentNodeFactory>
12#include <KItinerary/ExtractorEngine>
13
14using namespace KItinerary;
15
17{
18 const auto r = node.content<HttpResponse>();
19
20 auto contentNode = engine->documentNodeFactory()->createNode(r.content());
21 node.appendChild(contentNode);
22}
23
24bool HarDocumentProcessor::canHandleData([[maybe_unused]] const QByteArray &encodedData, QStringView fileName) const
25{
26 return fileName.endsWith(QLatin1StringView(".har"));
27}
28
30{
32 node.setContent(encodedData);
33 return node;
34}
35
37{
38 const auto httpResponses = HttpResponse::fromHarFile(node.content<QByteArray>());
39 for (const auto &httpResponse : httpResponses) {
40 auto child = engine->documentNodeFactory()->createNode(httpResponse, u"internal/http-response");
41 child.setContextDateTime(httpResponse.requestDateTime());
42 node.appendChild(child);
43 }
44}
ExtractorDocumentNode createNode(const QByteArray &data, QStringView fileName={}, QStringView mimeType={}) const
Create a new document node from data.
A node in the extracted document object tree.
void appendChild(ExtractorDocumentNode &child)
Add another child node.
QJSValue content
The decoded content of this node.
void setContent(const QVariant &content)
Set decoded content.
Semantic data extraction engine.
const ExtractorDocumentNodeFactory * documentNodeFactory() const
Factory for creating new document nodes.
bool canHandleData(const QByteArray &encodedData, QStringView fileName) const override
Fast check whether the given encoded data can possibly be processed by this instance.
void expandNode(ExtractorDocumentNode &node, const ExtractorEngine *engine) const override
Create child nodes for node, as far as that's necessary for this document type.
ExtractorDocumentNode createNodeFromData(const QByteArray &encodedData) const override
Create a document node from raw data.
void expandNode(ExtractorDocumentNode &node, const ExtractorEngine *engine) const override
Create child nodes for node, as far as that's necessary for this document type.
Container for an HTTP response to be passed into the extractor engine.
static QList< HttpResponse > fromHarFile(const QByteArray &harFile)
Read a set of HTTP responses from an HAR file.
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
bool endsWith(QChar ch) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:37 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.