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
Cameron Clough 2021-11-18 14:53:21 +00:00 committed by GitHub
parent 52c4ab73a9
commit 140c7f430c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View File

@ -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());

View File

@ -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() {

View File

@ -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);