mirror of
https://github.com/MoreTore/openpilot.git
synced 2026-08-02 13:29:30 +08:00
api: send User-Agent on network requests (#22965)
* api: set User-Agent on network requests
The format of the User-Agent header matches the format in `common/api/__init__.py`.
Closes #22954.
* Update selfdrive/ui/qt/util.cc
* fix parentheses
* refactor into function
Co-authored-by: Willem Melching <willem.melching@gmail.com>
old-commit-hash: 140c7f430c
This commit is contained in:
@@ -90,6 +90,7 @@ void HttpRequest::sendRequest(const QString &requestURL, const HttpRequest::Meth
|
||||
|
||||
QNetworkRequest request;
|
||||
request.setUrl(QUrl(requestURL));
|
||||
request.setRawHeader("User-Agent", getUserAgent().toUtf8());
|
||||
|
||||
if (!token.isEmpty()) {
|
||||
request.setRawHeader(QByteArray("Authorization"), ("JWT " + token).toUtf8());
|
||||
|
||||
+10
-1
@@ -8,12 +8,21 @@
|
||||
#include "selfdrive/common/swaglog.h"
|
||||
#include "selfdrive/hardware/hw.h"
|
||||
|
||||
QString getVersion() {
|
||||
static QString version = QString::fromStdString(Params().get("Version"));
|
||||
return version;
|
||||
}
|
||||
|
||||
QString getBrand() {
|
||||
return Params().getBool("Passive") ? "dashcam" : "openpilot";
|
||||
}
|
||||
|
||||
QString getBrandVersion() {
|
||||
return getBrand() + " v" + QString::fromStdString(Params().get("Version")).left(14).trimmed();
|
||||
return getBrand() + " v" + getVersion().left(14).trimmed();
|
||||
}
|
||||
|
||||
QString getUserAgent() {
|
||||
return "openpilot-" + getVersion();
|
||||
}
|
||||
|
||||
std::optional<QString> getDongleId() {
|
||||
|
||||
@@ -9,8 +9,10 @@
|
||||
#include <QSurfaceFormat>
|
||||
#include <QWidget>
|
||||
|
||||
QString getVersion();
|
||||
QString getBrand();
|
||||
QString getBrandVersion();
|
||||
QString getUserAgent();
|
||||
std::optional<QString> getDongleId();
|
||||
void configFont(QPainter &p, const QString &family, int size, const QString &style);
|
||||
void clearLayout(QLayout* layout);
|
||||
|
||||
Reference in New Issue
Block a user