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>pull/22969/head
parent
52c4ab73a9
commit
140c7f430c
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue