Skip to content

Commit

Permalink
translation/Protocol: add packet ANALYTICS_ID
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Mar 11, 2024
1 parent be1ce1d commit 365ae29
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ cm4all-beng-proxy (18.0.58) unstable; urgency=low
* lb: run lua_handler as coroutine
* certdb/puki: client for the 1&1 Public Key Infrastructure (PUKI)
* log: drop support for protocol v1
* translation: add packet ANALYTICS_ID

--

Expand Down
1 change: 1 addition & 0 deletions python/beng_proxy/translation/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
TRANSLATE_NO_HOME_AUTHORIZED_KEYS = 255
TRANSLATE_TIMEOUT = 256
TRANSLATE_MOUNT_LISTEN_STREAM = 257
TRANSLATE_ANALYTICS_ID = 258

TRANSLATE_PROXY = TRANSLATE_HTTP # deprecated
TRANSLATE_LHTTP_EXPAND_URI = TRANSLATE_EXPAND_LHTTP_URI # deprecated
Expand Down
6 changes: 5 additions & 1 deletion src/access_log/Glue.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ AccessLogGlue::Log(const Net::Log::Datagram &d) noexcept
void
AccessLogGlue::Log(std::chrono::system_clock::time_point now,
const IncomingHttpRequest &request, const char *site,
const char *analytics_id,
const char *forwarded_to,
const char *host, const char *x_forwarded_for,
const char *referer, const char *user_agent,
Expand Down Expand Up @@ -98,6 +99,7 @@ AccessLogGlue::Log(std::chrono::system_clock::time_point now,
.remote_host = remote_host,
.host = host,
.site = site,
.analytics_id = analytics_id,
.forwarded_to = forwarded_to,
.http_uri = request.uri,
.http_referer = referer,
Expand All @@ -114,13 +116,15 @@ AccessLogGlue::Log(std::chrono::system_clock::time_point now,
void
AccessLogGlue::Log(std::chrono::system_clock::time_point now,
const IncomingHttpRequest &request, const char *site,
const char *analytics_id,
const char *forwarded_to,
const char *referer, const char *user_agent,
HttpStatus status, int64_t content_length,
uint64_t bytes_received, uint64_t bytes_sent,
std::chrono::steady_clock::duration duration) noexcept
{
Log(now, request, site, forwarded_to,
Log(now, request, site, analytics_id,
forwarded_to,
request.headers.Get("host"),
request.headers.Get("x-forwarded-for"),
referer, user_agent,
Expand Down
2 changes: 2 additions & 0 deletions src/access_log/Glue.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public:
*/
void Log(std::chrono::system_clock::time_point now,
const IncomingHttpRequest &request, const char *site,
const char *analytics_id,
const char *forwarded_to,
const char *host, const char *x_forwarded_for,
const char *referer, const char *user_agent,
Expand All @@ -60,6 +61,7 @@ public:

void Log(std::chrono::system_clock::time_point now,
const IncomingHttpRequest &request, const char *site,
const char *analytics_id,
const char *forwarded_to,
const char *referer, const char *user_agent,
HttpStatus status, int64_t length,
Expand Down
5 changes: 5 additions & 0 deletions src/bp/Handler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ Request::HandleTranslatedRequest2(const TranslateResponse &response) noexcept
rl.site_name = response.site;
}

if (response.analytics_id != nullptr) {
auto &rl = *(BpRequestLogger *)request.logger;
rl.analytics_id = response.analytics_id;
}

if (response.stats_tag != nullptr) {
auto &rl = *(BpRequestLogger *)request.logger;
rl.stats_tag = response.stats_tag;
Expand Down
1 change: 1 addition & 0 deletions src/bp/RLogger.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ BpRequestLogger::LogHttpRequest(IncomingHttpRequest &request,
if (instance.access_log != nullptr)
instance.access_log->Log(instance.event_loop.SystemNow(),
request, site_name,
analytics_id,
nullptr,
request.headers.Get("referer"),
request.headers.Get("user-agent"),
Expand Down
5 changes: 5 additions & 0 deletions src/bp/RLogger.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ struct BpRequestLogger final : IncomingHttpRequestLogger {
*/
const char *site_name = nullptr;

/**
* @see TranslationCommand::ANALYTICS_ID
*/
const char *analytics_id = nullptr;

/**
* From TranslationCommand::STATS_TAG
*/
Expand Down
1 change: 1 addition & 0 deletions src/lb/RLogger.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ LbRequestLogger::LogHttpRequest(IncomingHttpRequest &request,
if (instance.access_log != nullptr)
instance.access_log->Log(instance.event_loop.SystemNow(),
request, site_name,
analytics_id,
forwarded_to,
host,
x_forwarded_for,
Expand Down
5 changes: 5 additions & 0 deletions src/lb/RLogger.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ struct LbRequestLogger final : IncomingHttpRequestLogger {
*/
const char *site_name = nullptr;

/**
* @see TranslationCommand::ANALYTICS_ID
*/
const char *analytics_id = nullptr;

/**
* @see LOG_FORWARDED_TO
*/
Expand Down
3 changes: 3 additions & 0 deletions src/lb/TranslationHttpRequestHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ LbHttpRequest::OnTranslateResponse(UniquePoolPtr<TranslateResponse> _response) n
if (response.site != nullptr)
rl.site_name = p_strdup(request.pool, response.site);

if (response.analytics_id != nullptr)
rl.analytics_id = p_strdup(request.pool, response.analytics_id);

if (response.https_only != 0 && !c.IsEncrypted()) {
Destroy();

Expand Down

0 comments on commit 365ae29

Please sign in to comment.