| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #include "services/abstract/gui/httpheadersdetails.h" |
| 4 | |
| 5 | #include "definitions/definitions.h" |
| 6 | |
| 7 | #include "ui_httpheadersdetails.h" |
| 8 | |
| 9 | #include <QRegularExpression> |
| 10 | |
| 11 | HttpHeadersDetails::HttpHeadersDetails(QWidget* parent) : QWidget(parent), m_ui(new Ui::HttpHeadersDetails()) { |
| 12 | m_ui->setupUi(this); |
| 13 | m_ui->m_helpHttpHeaders |
| 14 | ->setHelpText(tr("Enter each key/value HTTP header pair on separate line. Note that all spaces are significant " |
| 15 | "and that header names are case-sensitive. " |
| 16 | "Also, make sure to separate key from value with '=', like the example below:") + |
| 17 | QSL("<br/><br/><b>HeaderKey=HeaderValue</b>"), |
| 18 | false); |
| 19 | } |
| 20 | |
| 21 | void HttpHeadersDetails::loadHttpHeaders(const QVariantHash& headers) { |
| 22 | m_ui->m_txtHttpHeaders->clear(); |
| 23 | |
| 24 | for (auto i = headers.cbegin(), end = headers.cend(); i != end; i++) { |
| 25 | m_ui->m_txtHttpHeaders->appendPlainText(QSL("%1=%2").arg(i.key(), i.value().toString())); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | QVariantHash HttpHeadersDetails::httpHeaders() const { |
| 30 | QVariantHash h; |
| 31 | |
| 32 | QRegularExpression exp(QSL("^([^=]+)=(.+)$"), QRegularExpression::PatternOption::MultilineOption); |
| 33 | auto exp_match = exp.globalMatch(m_ui->m_txtHttpHeaders->toPlainText()); |
| 34 | |
| 35 | while (exp_match.hasNext()) { |
| 36 | auto match = exp_match.next(); |
| 37 | |
| 38 | h.insert(match.captured(1), match.captured(2)); |
| 39 | } |
| 40 | |
| 41 | return h; |
| 42 | } |
| 43 | |
| 44 | HttpHeadersDetails::~HttpHeadersDetails() = default; |