Skip to content

Commit

Permalink
Send User-Agent as the monitor info
Browse files Browse the repository at this point in the history
  • Loading branch information
bbockelm authored and abh3 committed Jan 12, 2024
1 parent dc49fc1 commit e78cf48
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/XrdHttp/XrdHttpProtocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,29 @@ int XrdHttpProtocol::Process(XrdLink *lp) // We ignore the argument here

} else
CurrentReq.reqstate++;
} else if (!DoneSetInfo && !CurrentReq.userAgent().empty()) { // DoingLogin is true, meaning the login finished.
std::string mon_info = "monitor info " + CurrentReq.userAgent();
DoneSetInfo = true;
if (mon_info.size() >= 1024) {
TRACEI(ALL, "User agent string too long");
} else if (!Bridge) {
TRACEI(ALL, "Internal logic error: Bridge is null after login");
} else {
TRACEI(DEBUG, "Setting " << mon_info);
memset(&CurrentReq.xrdreq, 0, sizeof (ClientRequest));
CurrentReq.xrdreq.set.requestid = htons(kXR_set);
CurrentReq.xrdreq.set.modifier = '\0';
memset(CurrentReq.xrdreq.set.reserved, '\0', sizeof(CurrentReq.xrdreq.set.reserved));
CurrentReq.xrdreq.set.dlen = htonl(mon_info.size());
if (!Bridge->Run((char *) &CurrentReq.xrdreq, (char *) mon_info.c_str(), mon_info.size())) {
SendSimpleResp(500, nullptr, nullptr, "Could not set user agent.", 0, false);
return -1;
}
return 0;
}
} else {
DoingLogin = false;
}
DoingLogin = false;


// Read the next request header, that is, read until a double CRLF is found

Expand Down Expand Up @@ -1856,6 +1876,7 @@ void XrdHttpProtocol::Reset() {
myBuffStart = myBuffEnd = 0;

DoingLogin = false;
DoneSetInfo = false;

ResumeBytes = 0;
Resume = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/XrdHttp/XrdHttpProtocol.hh
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ private:

/// Tells that we are just logging in
bool DoingLogin;

/// Indicates whether we've attempted to send app info.
bool DoneSetInfo;

/// Tells that we are just waiting to have N bytes in the buffer
long ResumeBytes;
Expand Down
4 changes: 4 additions & 0 deletions src/XrdHttp/XrdHttpReq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ int XrdHttpReq::parseLine(char *line, int len) {
if(prot->pmarkHandle != nullptr) {
parseScitag(val);
}
} else if (!strcasecmp(key, "User-Agent")) {
m_user_agent = val;
trim(m_user_agent);
} else {
// Some headers need to be translated into "local" cgi info.
auto it = std::find_if(prot->hdr2cgimap.begin(), prot->hdr2cgimap.end(),[key](const auto & item) {
Expand Down Expand Up @@ -2755,6 +2758,7 @@ void XrdHttpReq::reset() {
m_req_cksum = nullptr;

m_resource_with_digest = "";
m_user_agent = "";

headerok = false;
keepalive = true;
Expand Down
6 changes: 6 additions & 0 deletions src/XrdHttp/XrdHttpReq.hh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ private:
int httpStatusCode;
std::string httpStatusText;

// The value of the user agent, if specified
std::string m_user_agent;

// Whether transfer encoding was requested.
bool m_transfer_encoding_chunked;
long long m_current_chunk_offset;
Expand Down Expand Up @@ -191,6 +194,9 @@ public:

void addCgi(const std::string & key, const std::string & value);

// Return the current user agent; if none has been specified, returns an empty string
const std::string &userAgent() const {return m_user_agent;}

// ----------------
// Description of the request. The header/body parsing
// is supposed to populate these fields, for fast access while
Expand Down

0 comments on commit e78cf48

Please sign in to comment.