/*
- * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
#include "AccessLogEntry.h"
#include "HttpReply.h"
#include "HttpRequest.h"
+#include "MemBuf.h"
+#include "proxyp/Header.h"
#include "SquidConfig.h"
#include "ssl/support.h"
// - IPv4 clients masked with client_netmask
// - IPv6 clients use 'privacy addressing' instead.
- if (!log_ip.isLocalhost() && log_ip.isIPv4())
- log_ip.applyMask(Config.Addrs.client_netmask);
+ log_ip.applyClientMask(Config.Addrs.client_netmask);
log_ip.toStr(buf, bufsz);
}
SBuf
AccessLogEntry::getLogMethod() const
{
+ static const SBuf dash("-");
SBuf method;
if (icp.opcode)
method.append(icp_opcode_str[icp.opcode]);
else if (htcp.opcode)
method.append(htcp.opcode);
- else
+ else if (http.method)
method = http.method.image();
+ else
+ method = dash;
return method;
}
return nullptr;
}
+AccessLogEntry::AccessLogEntry() {}
+
AccessLogEntry::~AccessLogEntry()
{
safe_free(headers.request);
safe_free(adapt.last_meta);
#endif
- safe_free(headers.reply);
-
safe_free(headers.adapted_request);
HTTPMSGUNLOCK(adapted_request);
safe_free(lastAclName);
- HTTPMSGUNLOCK(reply);
HTTPMSGUNLOCK(request);
#if ICAP_CLIENT
HTTPMSGUNLOCK(icap.reply);
#endif
}
+ScopedId
+AccessLogEntry::codeContextGist() const
+{
+ if (request) {
+ if (const auto &mx = request->masterXaction)
+ return mx->id.detach();
+ }
+ // TODO: Carefully merge ALE and MasterXaction.
+ return ScopedId("ALE w/o master");
+}
+
+std::ostream &
+AccessLogEntry::detailCodeContext(std::ostream &os) const
+{
+ // TODO: Consider printing all instead of the first most important detail.
+
+ if (request) {
+ if (const auto &mx = request->masterXaction)
+ return os << Debug::Extra << "current master transaction: " << mx->id;
+ }
+
+ // provide helpful details since we cannot identify the transaction exactly
+
+ if (tcpClient)
+ return os << Debug::Extra << "current from-client connection: " << tcpClient;
+ else if (!cache.caddr.isNoAddr())
+ return os << Debug::Extra << "current client: " << cache.caddr;
+
+ const auto optionalMethod = [this,&os]() {
+ if (hasLogMethod())
+ os << getLogMethod() << ' ';
+ return "";
+ };
+ if (const auto uri = effectiveVirginUrl())
+ return os << Debug::Extra << "current client request: " << optionalMethod() << *uri;
+ else if (!url.isEmpty())
+ return os << Debug::Extra << "current request: " << optionalMethod() << url;
+ else if (hasLogMethod())
+ return os << Debug::Extra << "current request method: " << getLogMethod();
+
+ return os;
+}
+
const SBuf *
AccessLogEntry::effectiveVirginUrl() const
{
return nullptr;
}
+void
+AccessLogEntry::packReplyHeaders(MemBuf &mb) const
+{
+ if (reply)
+ reply->packHeadersUsingFastPacker(mb);
+}
+