XRootD
XrdHttpReq Class Reference

#include <XrdHttpReq.hh>

+ Inheritance diagram for XrdHttpReq:
+ Collaboration diagram for XrdHttpReq:

Public Types

enum  ReqType {
  rtUnset = -1 ,
  rtUnknown = 0 ,
  rtMalformed ,
  rtGET ,
  rtHEAD ,
  rtPUT ,
  rtOPTIONS ,
  rtPATCH ,
  rtDELETE ,
  rtPROPFIND ,
  rtMKCOL ,
  rtMOVE ,
  rtPOST
}
 These are the HTTP/DAV requests that we support. More...
 

Public Member Functions

 XrdHttpReq (XrdHttpProtocol *protinstance, const XrdHttpReadRangeHandler::Configuration &rcfg)
 
virtual ~XrdHttpReq ()
 
void addCgi (const std::string &key, const std::string &value)
 
void appendOpaque (XrdOucString &s, XrdSecEntity *secent, char *hash, time_t tnow)
 
std::string buildPartialHdr (long long bytestart, long long byteend, long long filesize, char *token)
 Build a partial header for a multipart response. More...
 
std::string buildPartialHdrEnd (char *token)
 Build the closing part for a multipart response. More...
 
virtual bool Data (XrdXrootd::Bridge::Context &info, const struct iovec *iovP, int iovN, int iovL, bool final)
 
virtual bool Done (XrdXrootd::Bridge::Context &info)
 the result context More...
 
virtual bool Error (XrdXrootd::Bridge::Context &info, int ecode, const char *etext)
 
virtual int File (XrdXrootd::Bridge::Context &info, int dlen)
 
int parseBody (char *body, long long len)
 Parse the body of a request, assuming that it's XML and that it's entirely in memory. More...
 
int parseFirstLine (char *line, int len)
 Parse the first line of the header. More...
 
int parseLine (char *line, int len)
 Parse the header. More...
 
int ProcessHTTPReq ()
 
virtual bool Redir (XrdXrootd::Bridge::Context &info, int port, const char *hname)
 
int ReqReadV (const XrdHttpIOList &cl)
 Prepare the buffers for sending a readv request. More...
 
virtual void reset ()
 
void setTransferStatusHeader (std::string &header)
 
const std::string & userAgent () const
 
- Public Member Functions inherited from XrdXrootd::Bridge::Result
 Result ()
 Constructor & Destructor. More...
 
virtual ~Result ()
 
virtual void Free (Bridge::Context &info, char *buffP, int buffL)
 
virtual bool Wait (Bridge::Context &info, int wtime, const char *wtext)
 
virtual Bridge::ResultWaitResp (Bridge::Context &info, int wtime, const char *wtext)
 

Public Attributes

std::map< std::string, std::string > allheaders
 
bool closeAfterError
 
int depth
 
std::string destination
 The destination field specified in the req. More...
 
std::string etext
 
char fhandle [4]
 
long filectime
 
long fileflags
 
long filemodtime
 
long long filesize
 
bool final
 true -> final result More...
 
bool fopened
 
std::string hdr2cgistr
 Additional opaque info that may come from the hdr2cgi directive. More...
 
bool headerok
 Tells if we have finished reading the header. More...
 
std::string host
 The host field specified in the req. More...
 
int iovL
 byte count More...
 
int iovN
 array count More...
 
const struct iovec * iovP
 The latest data chunks got from the xrd layer. These are valid only inside the callbacks! More...
 
bool keepalive
 
long long length
 
bool m_appended_asize {false}
 Track whether we already appended the oss.asize argument for PUTs. More...
 
bool m_appended_hdr2cgistr
 
std::string m_digest_header
 The computed digest for the HTTP response header. More...
 
XrdHttpChecksumHandler::XrdHttpChecksumRawPtr m_req_cksum = nullptr
 The checksum that was ran for this request. More...
 
std::string m_req_digest
 The requested digest type. More...
 
XrdOucString m_resource_with_digest
 
int mScitag
 
XrdOucEnvopaque
 The opaque data, after parsing. More...
 
std::vector< readahead_listralist
 
bool readClosing
 
XrdHttpReadRangeHandler readRangeHandler
 Tracking the next ranges of data to read during GET. More...
 
XrdOucString redirdest
 
int reqstate
 State machine to talk to the bridge. More...
 
ReqType request
 The request we got. More...
 
std::string requestverb
 
XrdOucString resource
 The resource specified by the request, stripped of opaque data. More...
 
XrdOucString resourceplusopaque
 The resource specified by the request, including all the opaque data. More...
 
unsigned int rwOpDone
 To coordinate multipart responses across multiple calls. More...
 
unsigned int rwOpPartialDone
 
bool sendcontinue
 
std::string stringresp
 If we want to give a string as a response, we compose it here. More...
 
long long writtenbytes
 In a long write, we track where we have arrived. More...
 
XErrorCode xrderrcode
 
ClientRequest xrdreq
 The last issued xrd request, often pending. More...
 
XResponseType xrdresp
 The last response data we got. More...
 

Detailed Description

Definition at line 71 of file XrdHttpReq.hh.

Member Enumeration Documentation

◆ ReqType

These are the HTTP/DAV requests that we support.

Enumerator
rtUnset 
rtUnknown 
rtMalformed 
rtGET 
rtHEAD 
rtPUT 
rtOPTIONS 
rtPATCH 
rtDELETE 
rtPROPFIND 
rtMKCOL 
rtMOVE 
rtPOST 

Definition at line 224 of file XrdHttpReq.hh.

224  {
225  rtUnset = -1,
226  rtUnknown = 0,
227  rtMalformed,
228  rtGET,
229  rtHEAD,
230  rtPUT,
231  rtOPTIONS,
232  rtPATCH,
233  rtDELETE,
234  rtPROPFIND,
235  rtMKCOL,
236  rtMOVE,
237  rtPOST
238  };

Constructor & Destructor Documentation

◆ XrdHttpReq()

XrdHttpReq::XrdHttpReq ( XrdHttpProtocol protinstance,
const XrdHttpReadRangeHandler::Configuration rcfg 
)
inline

Definition at line 168 of file XrdHttpReq.hh.

168  :
169  readRangeHandler(rcfg), closeAfterError(false), keepalive(true) {
170 
171  prot = protinstance;
172  length = 0;
173  //xmlbody = 0;
174  depth = 0;
175  opaque = 0;
176  writtenbytes = 0;
177  fopened = false;
178  headerok = false;
179  mScitag = -1;
180  };
bool keepalive
Definition: XrdHttpReq.hh:267
long long length
Definition: XrdHttpReq.hh:268
bool headerok
Tells if we have finished reading the header.
Definition: XrdHttpReq.hh:257
bool closeAfterError
Definition: XrdHttpReq.hh:265
long long writtenbytes
In a long write, we track where we have arrived.
Definition: XrdHttpReq.hh:334
XrdOucEnv * opaque
The opaque data, after parsing.
Definition: XrdHttpReq.hh:251
bool fopened
Definition: XrdHttpReq.hh:325
XrdHttpReadRangeHandler readRangeHandler
Tracking the next ranges of data to read during GET.
Definition: XrdHttpReq.hh:260

References depth, fopened, headerok, length, mScitag, opaque, and writtenbytes.

◆ ~XrdHttpReq()

XrdHttpReq::~XrdHttpReq ( )
virtual

Definition at line 110 of file XrdHttpReq.cc.

110  {
111  //if (xmlbody) xmlFreeDoc(xmlbody);
112 
113  reset();
114 }
virtual void reset()
Definition: XrdHttpReq.cc:2815

References reset().

+ Here is the call graph for this function:

Member Function Documentation

◆ addCgi()

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

Definition at line 794 of file XrdHttpReq.cc.

794  {
795  if (hdr2cgistr.length() > 0) {
796  hdr2cgistr.append("&");
797  }
798  hdr2cgistr.append(key);
799  hdr2cgistr.append("=");
800  hdr2cgistr.append(value);
801 }
std::string hdr2cgistr
Additional opaque info that may come from the hdr2cgi directive.
Definition: XrdHttpReq.hh:291

References hdr2cgistr.

Referenced by parseLine().

+ Here is the caller graph for this function:

◆ appendOpaque()

void XrdHttpReq::appendOpaque ( XrdOucString s,
XrdSecEntity secent,
char *  hash,
time_t  tnow 
)

Definition at line 637 of file XrdHttpReq.cc.

637  {
638 
639  int l = 0;
640  char * p = 0;
641  if (opaque)
642  p = opaque->Env(l);
643 
644  if (hdr2cgistr.empty() && (l < 2) && !hash) return;
645 
646  // this works in most cases, except if the url already contains the xrdhttp tokens
647  s = s + "?";
648  if (!hdr2cgistr.empty()) {
649  char *s1 = quote(hdr2cgistr.c_str());
650  if (s1) {
651  s += s1;
652  free(s1);
653  }
654  }
655  if (p && (l > 1)) {
656  char *s1 = quote(p+1);
657  if (s1) {
658  if (!hdr2cgistr.empty()) {
659  s = s + "&";
660  }
661  s = s + s1;
662  free(s1);
663  }
664  }
665 
666 
667 
668  if (hash) {
669  if (l > 1) s += "&";
670  s += "xrdhttptk=";
671  s += hash;
672 
673  s += "&xrdhttptime=";
674  char buf[256];
675  sprintf(buf, "%lld", (long long) tnow);
676  s += buf;
677 
678  if (secent) {
679  if (secent->name) {
680  s += "&xrdhttpname=";
681  char *s1 = quote(secent->name);
682  if (s1) {
683  s += s1;
684  free(s1);
685  }
686  }
687 
688  if (secent->vorg) {
689  s += "&xrdhttpvorg=";
690  char *s1 = quote(secent->vorg);
691  if (s1) {
692  s += s1;
693  free(s1);
694  }
695  }
696 
697  if (secent->host) {
698  s += "&xrdhttphost=";
699  char *s1 = quote(secent->host);
700  if (s1) {
701  s += s1;
702  free(s1);
703  }
704  }
705 
706  if (secent->moninfo) {
707  s += "&xrdhttpdn=";
708  char *s1 = quote(secent->moninfo);
709  if (s1) {
710  s += s1;
711  free(s1);
712  }
713  }
714 
715  if (secent->role) {
716  s += "&xrdhttprole=";
717  char *s1 = quote(secent->role);
718  if (s1) {
719  s += s1;
720  free(s1);
721  }
722  }
723 
724  if (secent->grps) {
725  s += "&xrdhttpgrps=";
726  char *s1 = quote(secent->grps);
727  if (s1) {
728  s += s1;
729  free(s1);
730  }
731  }
732 
733  if (secent->endorsements) {
734  s += "&xrdhttpendorsements=";
735  char *s1 = quote(secent->endorsements);
736  if (s1) {
737  s += s1;
738  free(s1);
739  }
740  }
741 
742  if (secent->credslen) {
743  s += "&xrdhttpcredslen=";
744  char buf[16];
745  sprintf(buf, "%d", secent->credslen);
746  char *s1 = quote(buf);
747  if (s1) {
748  s += s1;
749  free(s1);
750  }
751  }
752 
753  if (secent->credslen) {
754  if (secent->creds) {
755  s += "&xrdhttpcreds=";
756  // Apparently this string might be not 0-terminated (!)
757  char *zerocreds = strndup(secent->creds, secent->credslen);
758  if (zerocreds) {
759  char *s1 = quote(zerocreds);
760  if (s1) {
761  s += s1;
762  free(s1);
763  }
764  free(zerocreds);
765  }
766  }
767  }
768 
769  }
770  }
771 
772 }
char * quote(const char *str)
char * Env(int &envlen)
Definition: XrdOucEnv.hh:48
char * vorg
Entity's virtual organization(s)
Definition: XrdSecEntity.hh:71
int credslen
Length of the 'creds' data.
Definition: XrdSecEntity.hh:78
char * creds
Raw entity credentials or cert.
Definition: XrdSecEntity.hh:77
char * grps
Entity's group name(s)
Definition: XrdSecEntity.hh:73
char * name
Entity's name.
Definition: XrdSecEntity.hh:69
char * role
Entity's role(s)
Definition: XrdSecEntity.hh:72
char * endorsements
Protocol specific endorsements.
Definition: XrdSecEntity.hh:75
char * moninfo
Information for monitoring.
Definition: XrdSecEntity.hh:76
char * host
Entity's host name dnr dependent.
Definition: XrdSecEntity.hh:70

References XrdSecEntity::creds, XrdSecEntity::credslen, XrdSecEntity::endorsements, XrdOucEnv::Env(), XrdSecEntity::grps, hdr2cgistr, XrdSecEntity::host, XrdSecEntity::moninfo, XrdSecEntity::name, opaque, quote(), XrdSecEntity::role, and XrdSecEntity::vorg.

Referenced by XrdHttpProtocol::Process(), ProcessHTTPReq(), and Redir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildPartialHdr()

std::string XrdHttpReq::buildPartialHdr ( long long  bytestart,
long long  byteend,
long long  filesize,
char *  token 
)

Build a partial header for a multipart response.

Definition at line 430 of file XrdHttpReq.cc.

430  {
431  std::ostringstream s;
432 
433  s << "\r\n--" << token << "\r\n";
434  s << "Content-type: text/plain; charset=UTF-8\r\n";
435  s << "Content-range: bytes " << bytestart << "-" << byteend << "/" << fsz << "\r\n\r\n";
436 
437  return s.str();
438 }

◆ buildPartialHdrEnd()

std::string XrdHttpReq::buildPartialHdrEnd ( char *  token)

Build the closing part for a multipart response.

Definition at line 440 of file XrdHttpReq.cc.

440  {
441  std::ostringstream s;
442 
443  s << "\r\n--" << token << "--\r\n";
444 
445  return s.str();
446 }

◆ Data()

bool XrdHttpReq::Data ( XrdXrootd::Bridge::Context info,
const struct iovec *  iovP,
int  iovN,
int  iovL,
bool  final 
)
virtual

Effect a client data response.

The Data() method is called when Run() resulted in a successful data response. The method should rewrite the data and send it to the client using the associated XrdLink object. As an example, 1) Result::Data(info, iovP, iovN, iovL) is called. 2) Inspect iovP, rewrite the data. 3) Send the response: info->linkP->Send(new_iovP, new_iovN, new_iovL); 4) Handle send errors and cleanup(e.g. deallocate storage). 5) Return, the exchange is now complete.

Parameters
infothe context associated with the result.
iovPa pointer to the iovec structure containing the xrootd data response about to be sent to the client. The request header is not included in the iovec structure. The elements of this structure must not be modified by the method.
iovNthe number of elements in the iovec structure array.
iovLtotal number of data bytes that would be sent to the client. This is simply the sum of all the lengths in the iovec.
finalTrue is this is the final result. Otherwise, this is a partial result (i.e. kXR_oksofar) and more data will result causing additional callbacks.
Returns
true continue normal processing. false terminate the bridge and close the link.
Parameters
infothe result context
iovPpointer to data array
iovNarray count
iovLbyte count
finaltrue -> final result

Implements XrdXrootd::Bridge::Result.

Definition at line 448 of file XrdHttpReq.cc.

454  {
455 
456  TRACE(REQ, " XrdHttpReq::Data! final=" << final);
457 
458  this->xrdresp = kXR_ok;
459  this->iovP = iovP_;
460  this->iovN = iovN_;
461  this->iovL = iovL_;
462  this->final = final_;
463 
464  if (PostProcessHTTPReq(final_)) reset();
465 
466  return true;
467 
468 };
@ kXR_ok
Definition: XProtocol.hh:899
#define TRACE(act, x)
Definition: XrdTrace.hh:63
XResponseType xrdresp
The last response data we got.
Definition: XrdHttpReq.hh:308
int iovL
byte count
Definition: XrdHttpReq.hh:316
const struct iovec * iovP
The latest data chunks got from the xrd layer. These are valid only inside the callbacks!
Definition: XrdHttpReq.hh:314
int iovN
array count
Definition: XrdHttpReq.hh:315

References iovL, iovN, iovP, kXR_ok, reset(), TRACE, and xrdresp.

+ Here is the call graph for this function:

◆ Done()

bool XrdHttpReq::Done ( XrdXrootd::Bridge::Context info)
virtual

the result context

Effect a client acknowledgement.

The Done() method is called when Run() resulted in success and there is no associated data for the client (equivalent to a simple kXR_ok response).

Parameters
infothe context associated with the result.
Returns
true continue normal processing. false terminate the bridge and close the link.

Implements XrdXrootd::Bridge::Result.

Definition at line 494 of file XrdHttpReq.cc.

494  {
495 
496  TRACE(REQ, " XrdHttpReq::Done");
497 
498  xrdresp = kXR_ok;
499 
500  this->iovN = 0;
501 
502  int r = PostProcessHTTPReq(true);
503  // Beware, we don't have to reset() if the result is 0
504  if (r) reset();
505  if (r < 0) return false;
506 
507 
508  return true;
509 };

References iovN, kXR_ok, reset(), TRACE, and xrdresp.

+ Here is the call graph for this function:

◆ Error()

bool XrdHttpReq::Error ( XrdXrootd::Bridge::Context info,
int  ecode,
const char *  etext 
)
virtual

Effect a client error response.

The Error() method is called when an error was encountered while processing the Run() request. The error should be reflected to the client.

Parameters
infothe context associated with the result.
ecodethe "kXR" error code describing the nature of the error. The code is in host byte format.
etexta null terminated string describing the error in human terms
Returns
true continue normal processing. false terminate the bridge and close the link.
Parameters
infothe result context
ecodethe "kXR" error code
etextassociated error message

Implements XrdXrootd::Bridge::Result.

Definition at line 511 of file XrdHttpReq.cc.

514  {
515 
516  TRACE(REQ, " XrdHttpReq::Error");
517 
518  xrdresp = kXR_error;
519  xrderrcode = (XErrorCode) ecode;
520 
521  if (etext_) {
522  char *s = escapeXML(etext_);
523  this->etext = s;
524  free(s);
525  }
526 
527  auto rc = PostProcessHTTPReq();
528  if (rc) {
529  reset();
530  }
531 
532  // If we are servicing a GET on a directory, it'll generate an error for the default
533  // OSS (we don't assume this is always true). Catch and suppress the error so we can instead
534  // generate a directory listing (if configured).
535  if ((request == rtGET) && (xrdreq.header.requestid == ntohs(kXR_open)) && (xrderrcode == kXR_isDirectory))
536  return true;
537 
538  return rc == 0 ? true : false;
539 };
XErrorCode
Definition: XProtocol.hh:989
@ kXR_isDirectory
Definition: XProtocol.hh:1006
@ kXR_error
Definition: XProtocol.hh:903
struct ClientRequestHdr header
Definition: XProtocol.hh:846
kXR_unt16 requestid
Definition: XProtocol.hh:157
@ kXR_open
Definition: XProtocol.hh:122
char * escapeXML(const char *str)
std::string etext
Definition: XrdHttpReq.hh:310
ReqType request
The request we got.
Definition: XrdHttpReq.hh:241
XErrorCode xrderrcode
Definition: XrdHttpReq.hh:309
ClientRequest xrdreq
The last issued xrd request, often pending.
Definition: XrdHttpReq.hh:305

References escapeXML(), etext, ClientRequest::header, kXR_error, kXR_isDirectory, kXR_open, request, ClientRequestHdr::requestid, reset(), rtGET, TRACE, xrderrcode, xrdreq, and xrdresp.

+ Here is the call graph for this function:

◆ File()

int XrdHttpReq::File ( XrdXrootd::Bridge::Context info,
int  dlen 
)
virtual

Notify callback that a sendfile() request is pending.

The File() method is called when Run() resulted in a sendfile response (i.e. sendfile() would have been used to send data to the client). This allows the callback to reframe the sendfile() data using the Send() method in the passed context object (see class Context above).

Parameters
infothe context associated with the result.
dlentotal number of data bytes that would be sent to the client.
Returns
true continue normal processing. false terminate the bridge and close the link.
Parameters
infothe result context
dlenbyte count

Implements XrdXrootd::Bridge::Result.

Definition at line 470 of file XrdHttpReq.cc.

472  {
473 
474  // sendfile about to be sent by bridge for fetching data for GET:
475  // no https, no chunked+trailer, no multirange
476 
477  //prot->SendSimpleResp(200, NULL, NULL, NULL, dlen);
478  int rc = info.Send(0, 0, 0, 0);
479  TRACE(REQ, " XrdHttpReq::File dlen:" << dlen << " send rc:" << rc);
480  bool start, finish;
481  // short read will be classed as error
482  if (rc) {
484  return false;
485  }
486 
487  if (readRangeHandler.NotifyReadResult(dlen, nullptr, start, finish) < 0)
488  return false;
489 
490 
491  return true;
492 };
void NotifyError()
Force handler to enter error state.
int NotifyReadResult(const ssize_t ret, const UserRange **const urp, bool &start, bool &allend)
Advance internal counters concerning received bytes.
virtual int Send(const struct iovec *headP, int headN, const struct iovec *tailP, int tailN)

References XrdHttpReadRangeHandler::NotifyError(), XrdHttpReadRangeHandler::NotifyReadResult(), readRangeHandler, XrdXrootd::Bridge::Context::Send(), and TRACE.

+ Here is the call graph for this function:

◆ parseBody()

int XrdHttpReq::parseBody ( char *  body,
long long  len 
)

Parse the body of a request, assuming that it's XML and that it's entirely in memory.

Definition at line 94 of file XrdHttpReq.cc.

94  {
95  /*
96  * The document being in memory, it has no base per RFC 2396,
97  * and the "noname.xml" argument will serve as its base.
98  */
99  //xmlbody = xmlReadMemory(body, len, "noname.xml", NULL, 0);
100  //if (xmlbody == NULL) {
101  // fprintf(stderr, "Failed to parse document\n");
102  // return 1;
103  //}
104 
105 
106 
107  return 1;
108 }

Referenced by ProcessHTTPReq().

+ Here is the caller graph for this function:

◆ parseFirstLine()

int XrdHttpReq::parseFirstLine ( char *  line,
int  len 
)

Parse the first line of the header.

Definition at line 261 of file XrdHttpReq.cc.

261  {
262 
263  char *key = line;
264 
265  int pos;
266 
267  // Do the naive parsing
268  if (!line) return -1;
269 
270  // Look for the first space-delimited token
271  char *p = strchr((char *) line, (int) ' ');
272  if (!p) {
274  return -1;
275  }
276 
277 
278  pos = p - line;
279  // The first token cannot be too long
280  if (pos > MAX_TK_LEN - 1) {
282  return -2;
283  }
284 
285  // The first space-delimited char cannot be the first one
286  // this allows to deal with the case when a client sends a first line that starts with a space " GET / HTTP/1.1"
287  if(pos == 0) {
289  return -4;
290  }
291 
292  // the first token must be non empty
293  if (pos > 0) {
294  line[pos] = 0;
295  char *val = line + pos + 1;
296 
297  // Here we are supposed to initialize whatever flag or variable that is needed
298  // by looking at the first token of the line
299 
300  // The token is key
301  // The remainder is val, look for the resource
302  p = strchr((char *) val, (int) ' ');
303 
304  if (!p) {
306  line[pos] = ' ';
307  return -3;
308  }
309 
310  *p = '\0';
311  parseResource(val);
312 
313  *p = ' ';
314 
315  // Xlate the known header lines
316  if (!strcmp(key, "GET")) {
317  request = rtGET;
318  } else if (!strcmp(key, "HEAD")) {
319  request = rtHEAD;
320  } else if (!strcmp(key, "PUT")) {
321  request = rtPUT;
322  } else if (!strcmp(key, "POST")) {
323  request = rtPOST;
324  } else if (!strcmp(key, "PATCH")) {
325  request = rtPATCH;
326  } else if (!strcmp(key, "OPTIONS")) {
327  request = rtOPTIONS;
328  } else if (!strcmp(key, "DELETE")) {
329  request = rtDELETE;
330  } else if (!strcmp(key, "PROPFIND")) {
332 
333  } else if (!strcmp(key, "MKCOL")) {
334  request = rtMKCOL;
335 
336  } else if (!strcmp(key, "MOVE")) {
337  request = rtMOVE;
338  } else {
339  request = rtUnknown;
340  }
341 
342  requestverb = key;
343 
344  // The last token should be the protocol. If it is HTTP/1.0, then
345  // keepalive is disabled by default.
346  if (!strcmp(p+1, "HTTP/1.0\r\n")) {
347  keepalive = false;
348  }
349  line[pos] = ' ';
350  }
351 
352  return 0;
353 }
#define MAX_TK_LEN
Definition: XrdHttpReq.cc:65
std::string requestverb
Definition: XrdHttpReq.hh:242

References keepalive, MAX_TK_LEN, request, requestverb, rtDELETE, rtGET, rtHEAD, rtMalformed, rtMKCOL, rtMOVE, rtOPTIONS, rtPATCH, rtPOST, rtPROPFIND, rtPUT, and rtUnknown.

Referenced by XrdHttpProtocol::Process().

+ Here is the caller graph for this function:

◆ parseLine()

int XrdHttpReq::parseLine ( char *  line,
int  len 
)

Parse the header.

Definition at line 116 of file XrdHttpReq.cc.

116  {
117 
118  char *key = line;
119  int pos;
120 
121  // Do the parsing
122  if (!line) return -1;
123 
124 
125  char *p = strchr((char *) line, (int) ':');
126  if (!p) {
127 
129  return -1;
130  }
131 
132  pos = (p - line);
133  if (pos > (MAX_TK_LEN - 1)) {
134 
136  return -2;
137  }
138 
139  if (pos > 0) {
140  line[pos] = 0;
141  char *val = line + pos + 1;
142 
143  // Trim left
144  while ( (!isgraph(*val) || (!*val)) && (val < line+len)) val++;
145 
146  // We memorize the headers also as a string
147  // because external plugins may need to process it differently
148  std::string ss = val;
149  if(ss.length() >= 2 && ss.substr(ss.length() - 2, 2) != "\r\n") {
151  return -3;
152  }
153  trim(ss);
154  allheaders[key] = ss;
155 
156  // Here we are supposed to initialize whatever flag or variable that is needed
157  // by looking at the first token of the line
158  // The token is key
159  // The value is val
160 
161  // Screen out the needed header lines
162  if (!strcasecmp(key, "connection")) {
163 
164  if (!strcasecmp(val, "Keep-Alive\r\n")) {
165  keepalive = true;
166  } else if (!strcasecmp(val, "close\r\n")) {
167  keepalive = false;
168  }
169 
170  } else if (!strcasecmp(key, "host")) {
171  parseHost(val);
172  } else if (!strcasecmp(key, "range")) {
173  // (rfc2616 14.35.1) says if Range header contains any range
174  // which is syntactically invalid the Range header should be ignored.
175  // Therefore no need for the range handler to report an error.
177  } else if (!strcasecmp(key, "content-length")) {
178  length = atoll(val);
179 
180  } else if (!strcasecmp(key, "destination")) {
181  destination.assign(val, line+len-val);
182  trim(destination);
183  } else if (!strcasecmp(key, "want-digest")) {
184  m_req_digest.assign(val, line + len - val);
186  //Transform the user requests' want-digest to lowercase
187  std::transform(m_req_digest.begin(),m_req_digest.end(),m_req_digest.begin(),::tolower);
188  } else if (!strcasecmp(key, "depth")) {
189  depth = -1;
190  if (strcmp(val, "infinity"))
191  depth = atoll(val);
192 
193  } else if (!strcasecmp(key, "expect") && strstr(val, "100-continue")) {
194  sendcontinue = true;
195  } else if (!strcasecmp(key, "te") && strstr(val, "trailers")) {
196  m_trailer_headers = true;
197  } else if (!strcasecmp(key, "transfer-encoding") && strstr(val, "chunked")) {
198  m_transfer_encoding_chunked = true;
199  } else if (!strcasecmp(key, "x-transfer-status") && strstr(val, "true")) {
200  m_transfer_encoding_chunked = true;
201  m_status_trailer = true;
202  } else if (!strcasecmp(key, "scitag")) {
203  if(prot->pmarkHandle != nullptr) {
204  parseScitag(val);
205  }
206  } else if (!strcasecmp(key, "user-agent")) {
207  m_user_agent = val;
208  trim(m_user_agent);
209  } else {
210  // Some headers need to be translated into "local" cgi info.
211  auto it = std::find_if(prot->hdr2cgimap.begin(), prot->hdr2cgimap.end(),[key](const auto & item) {
212  return !strcasecmp(key,item.first.c_str());
213  });
214  if (it != prot->hdr2cgimap.end() && (opaque ? (0 == opaque->Get(it->second.c_str())) : true)) {
215  std::string s;
216  s.assign(val, line+len-val);
217  trim(s);
218  addCgi(it->second,s);
219  }
220  }
221 
222 
223  line[pos] = ':';
224  }
225 
226  return 0;
227 }
void trim(std::string &str)
Definition: XrdHttpReq.cc:76
static XrdNetPMark * pmarkHandle
Packet marking handler pointer (assigned from the environment during the Config() call)
static std::map< std::string, std::string > hdr2cgimap
Rules that turn HTTP headers to cgi tokens in the URL, for internal comsumption.
void ParseContentRange(const char *const line)
parse the line after a "Range: " http request header
std::string destination
The destination field specified in the req.
Definition: XrdHttpReq.hh:275
std::string m_req_digest
The requested digest type.
Definition: XrdHttpReq.hh:278
std::map< std::string, std::string > allheaders
Definition: XrdHttpReq.hh:246
void addCgi(const std::string &key, const std::string &value)
Definition: XrdHttpReq.cc:794
bool sendcontinue
Definition: XrdHttpReq.hh:270
char * Get(const char *varname)
Definition: XrdOucEnv.hh:69

References addCgi(), allheaders, depth, destination, XrdOucEnv::Get(), XrdHttpProtocol::hdr2cgimap, keepalive, length, m_req_digest, MAX_TK_LEN, opaque, XrdHttpReadRangeHandler::ParseContentRange(), XrdHttpProtocol::pmarkHandle, readRangeHandler, request, rtMalformed, sendcontinue, and trim().

Referenced by XrdHttpProtocol::Process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ProcessHTTPReq()

int XrdHttpReq::ProcessHTTPReq ( )

Crunch an http request. Return values: 0->call Process again 1->request processed -1->error

If we have to add extra header information, add it here.

Definition at line 939 of file XrdHttpReq.cc.

939  {
940 
941  kXR_int32 l;
942 
943  // State variable for tracking the query parameter search
944  // - 0: Indicates we've not yet searched the URL for '?'
945  // - 1: Indicates we have a '?' and hence query parameters
946  // - 2: Indicates we do *not* have '?' present -- no query parameters
947  int query_param_status = 0;
948  if (!m_appended_asize) {
949  m_appended_asize = true;
950  if (request == rtPUT && length) {
951  if (query_param_status == 0) {
952  query_param_status = strchr(resourceplusopaque.c_str(), '?') ? 1 : 2;
953  }
954  resourceplusopaque.append((query_param_status == 1) ? '&' : '?');
955  query_param_status = 1;
956  auto length_str = std::to_string(length);
957  resourceplusopaque.append("oss.asize=");
958  resourceplusopaque.append(length_str.c_str());
959  if (!opaque) {
960  opaque = new XrdOucEnv();
961  }
962  opaque->Put("oss.asize", length_str.c_str());
963  }
964  }
965 
967  if (!m_appended_hdr2cgistr && !hdr2cgistr.empty()) {
968  if (query_param_status == 0) {
969  query_param_status = strchr(resourceplusopaque.c_str(), '?') ? 1 : 2;
970  }
971  resourceplusopaque.append((query_param_status == 1) ? '&' : '?');
972 
973  char *q = quote(hdr2cgistr.c_str());
975  if (TRACING(TRACE_DEBUG)) {
976  // The obfuscation of "authz" will only be done if the server http.header2cgi config contains something that maps a header to this "authz" cgi.
977  // Unfortunately the obfuscation code will be called no matter what is configured in http.header2cgi.
978  std::string header2cgistrObf = obfuscateAuth(hdr2cgistr);
979 
980  TRACEI(DEBUG, "Appended header fields to opaque info: '"
981  << header2cgistrObf.c_str() << "'");
982 
983  }
984  // We assume that anything appended to the CGI str should also
985  // apply to the destination in case of a MOVE.
986  if (strchr(destination.c_str(), '?')) destination.append("&");
987  else destination.append("?");
988  destination.append(q);
989 
990  free(q);
991  m_appended_hdr2cgistr = true;
992  }
993 
994  // Verify if we have an external handler for this request
995  if (reqstate == 0) {
996  XrdHttpExtHandler *exthandler = prot->FindMatchingExtHandler(*this);
997  if (exthandler) {
998  XrdHttpExtReq xreq(this, prot);
999  int r = exthandler->ProcessReq(xreq);
1000  reset();
1001  if (!r) return 1; // All went fine, response sent
1002  if (r < 0) return -1; // There was a hard error... close the connection
1003 
1004  return 1; // There was an error and a response was sent
1005  }
1006  }
1007 
1008  //
1009  // Here we process the request locally
1010  //
1011 
1012  switch (request) {
1013  case XrdHttpReq::rtUnset:
1014  case XrdHttpReq::rtUnknown:
1015  {
1016  prot->SendSimpleResp(400, NULL, NULL, (char *) "Request unknown", 0, false);
1017  reset();
1018  return -1;
1019  }
1021  {
1022  prot->SendSimpleResp(400, NULL, NULL, (char *) "Request malformed", 0, false);
1023  reset();
1024  return -1;
1025  }
1026  case XrdHttpReq::rtHEAD:
1027  {
1028  if (reqstate == 0) {
1029  // Always start with Stat; in the case of a checksum request, we'll have a follow-up query
1030  if (prot->doStat((char *) resourceplusopaque.c_str())) {
1031  prot->SendSimpleResp(404, NULL, NULL, (char *) "Could not run request.", 0, false);
1032  return -1;
1033  }
1034  return 0;
1035  } else {
1036  const char *opaque = strchr(resourceplusopaque.c_str(), '?');
1037  // Note that doChksum requires that the memory stays alive until the callback is invoked.
1039 
1041  if(!m_req_cksum) {
1042  // No HTTP IANA checksums have been configured by the server admin, return a "METHOD_NOT_ALLOWED" error
1043  prot->SendSimpleResp(403, NULL, NULL, (char *) "No HTTP-IANA compatible checksums have been configured.", 0, false);
1044  return -1;
1045  }
1046  if (!opaque) {
1047  m_resource_with_digest += "?cks.type=";
1049  } else {
1050  m_resource_with_digest += "&cks.type=";
1052  }
1053  if (prot->doChksum(m_resource_with_digest) < 0) {
1054  // In this case, the Want-Digest header was set and PostProcess gave the go-ahead to do a checksum.
1055  prot->SendSimpleResp(500, NULL, NULL, (char *) "Failed to create initial checksum request.", 0, false);
1056  return -1;
1057  }
1058  return 1;
1059  }
1060  }
1061  case XrdHttpReq::rtGET:
1062  {
1063  int retval = keepalive ? 1 : -1; // reset() clears keepalive
1064 
1065  if (resource.beginswith("/static/")) {
1066 
1067  // This is a request for a /static resource
1068  // If we have to use the embedded ones then we return the ones in memory as constants
1069 
1070  // The sysadmin can always redirect the request to another host that
1071  // contains his static resources
1072 
1073  // We also allow xrootd to preread from the local disk all the files
1074  // that have to be served as static resources.
1075 
1076  if (prot->embeddedstatic) {
1077 
1078  // Default case: the icon and the css of the HTML rendering of XrdHttp
1079  if (resource == "/static/css/xrdhttp.css") {
1080  prot->SendSimpleResp(200, NULL, NULL, (char *) static_css_xrdhttp_css, static_css_xrdhttp_css_len, keepalive);
1081  reset();
1082  return retval;
1083  }
1084  if (resource == "/static/icons/xrdhttp.ico") {
1085  prot->SendSimpleResp(200, NULL, NULL, (char *) favicon_ico, favicon_ico_len, keepalive);
1086  reset();
1087  return retval;
1088  }
1089 
1090  }
1091 
1092  // If we are here then none of the embedded resources match (or they are disabled)
1093  // We may have to redirect to a host that is supposed to serve the static resources
1094  if (prot->staticredir) {
1095 
1096  XrdOucString s = "Location: ";
1097  s.append(prot->staticredir);
1098 
1099  if (s.endswith('/'))
1100  s.erasefromend(1);
1101 
1102  s.append(resource);
1103  appendOpaque(s, 0, 0, 0);
1104 
1105  prot->SendSimpleResp(302, NULL, (char *) s.c_str(), 0, 0, false);
1106  return -1;
1107 
1108 
1109  } else {
1110 
1111  // We lookup the requested path in a hash containing the preread files
1112  if (prot->staticpreload) {
1114  if (mydata) {
1115  prot->SendSimpleResp(200, NULL, NULL, (char *) mydata->data, mydata->len, keepalive);
1116  reset();
1117  return retval;
1118  }
1119  }
1120 
1121  }
1122 
1123 
1124  }
1125 
1126  // The reqstate parameter basically moves us through a simple state machine.
1127  // To optimize things, we start off by opening the file; if it turns out to be a directory, then
1128  // we close the file handle and switch to doing a HTML-based rendering of the directory. This
1129  // avoids needing to always to do "stat" first to determine the next step (since the file-open also
1130  // does a "stat").
1131  // - 0: Perform an open on the resource
1132  // - 1: Perform a checksum request on the resource (only if requested in header; otherwise skipped)
1133  // - 2: Perform a close (for dirlist only)
1134  // - 3: Perform a dirlist.
1135  // - 4+: Reads from file; if at end, perform a close.
1136  switch (reqstate) {
1137  case 0: // Open the path for reading.
1138  {
1139  memset(&xrdreq, 0, sizeof (ClientRequest));
1140  xrdreq.open.requestid = htons(kXR_open);
1141  l = resourceplusopaque.length() + 1;
1142  xrdreq.open.dlen = htonl(l);
1143  xrdreq.open.mode = 0;
1145 
1146  if (!prot->Bridge->Run((char *) &xrdreq, (char *) resourceplusopaque.c_str(), l)) {
1147  prot->SendSimpleResp(404, NULL, NULL, (char *) "Could not run request.", 0, false);
1148  return -1;
1149  }
1150 
1151  // Prepare to chunk up the request
1152  writtenbytes = 0;
1153 
1154  // We want to be invoked again after this request is finished
1155  return 0;
1156  }
1157  case 1: // Checksum request
1158  if (!(fileflags & kXR_isDir) && !m_req_digest.empty()) {
1159  // In this case, the Want-Digest header was set.
1160  bool has_opaque = strchr(resourceplusopaque.c_str(), '?');
1161  // Note that doChksum requires that the memory stays alive until the callback is invoked.
1163  if(!m_req_cksum) {
1164  // No HTTP IANA checksums have been configured by the server admin, return a "METHOD_NOT_ALLOWED" error
1165  prot->SendSimpleResp(403, NULL, NULL, (char *) "No HTTP-IANA compatible checksums have been configured.", 0, false);
1166  return -1;
1167  }
1169  if (has_opaque) {
1170  m_resource_with_digest += "&cks.type=";
1172  } else {
1173  m_resource_with_digest += "?cks.type=";
1175  }
1176  if (prot->doChksum(m_resource_with_digest) < 0) {
1177  prot->SendSimpleResp(500, NULL, NULL, (char *) "Failed to start internal checksum request to satisfy Want-Digest header.", 0, false);
1178  return -1;
1179  }
1180  return 0;
1181  } else {
1182  TRACEI(DEBUG, "No checksum requested; skipping to request state 2");
1183  reqstate += 1;
1184  }
1185  // fallthrough
1186  case 2: // Close file handle for directory
1187  if ((fileflags & kXR_isDir) && fopened) {
1188  memset(&xrdreq, 0, sizeof (ClientRequest));
1189  xrdreq.close.requestid = htons(kXR_close);
1190  memcpy(xrdreq.close.fhandle, fhandle, 4);
1191 
1192  if (!prot->Bridge->Run((char *) &xrdreq, 0, 0)) {
1193  mapXrdErrorToHttpStatus();
1194  return sendFooterError("Could not run close request on the bridge");
1195  }
1196  return 0;
1197  } else {
1198  reqstate += 1;
1199  }
1200  // fallthrough
1201  case 3: // List directory
1202  if (fileflags & kXR_isDir) {
1203  if (prot->listdeny) {
1204  prot->SendSimpleResp(503, NULL, NULL, (char *) "Listings are disabled.", 0, false);
1205  return -1;
1206  }
1207 
1208  if (prot->listredir) {
1209  XrdOucString s = "Location: ";
1210  s.append(prot->listredir);
1211 
1212  if (s.endswith('/'))
1213  s.erasefromend(1);
1214 
1215  s.append(resource);
1216  appendOpaque(s, 0, 0, 0);
1217 
1218  prot->SendSimpleResp(302, NULL, (char *) s.c_str(), 0, 0, false);
1219  return -1;
1220  }
1221 
1222  std::string res;
1223  res = resourceplusopaque.c_str();
1224 
1225  // --------- DIRLIST
1226  memset(&xrdreq, 0, sizeof (ClientRequest));
1229  l = res.length() + 1;
1230  xrdreq.dirlist.dlen = htonl(l);
1231 
1232  if (!prot->Bridge->Run((char *) &xrdreq, (char *) res.c_str(), l)) {
1233  mapXrdErrorToHttpStatus();
1234  prot->SendSimpleResp(httpStatusCode, NULL, NULL, httpStatusText.c_str(), httpStatusText.length(), false);
1235  return sendFooterError("Could not run listing request on the bridge");
1236  }
1237 
1238  // We don't want to be invoked again after this request is finished
1239  return 1;
1240  }
1241  else {
1242  reqstate += 1;
1243  }
1244  // fallthrough
1245  case 4:
1246  {
1247  auto retval = ReturnGetHeaders();
1248  if (retval) {
1249  return retval;
1250  }
1251  }
1252  // fallthrough
1253  default: // Read() or Close(); reqstate is 4+
1254  {
1255  const XrdHttpIOList &readChunkList = readRangeHandler.NextReadList();
1256 
1257  // Close() if we have finished, otherwise read the next chunk
1258 
1259  // --------- CLOSE
1260  if ( closeAfterError || readChunkList.empty() )
1261  {
1262 
1263  memset(&xrdreq, 0, sizeof (ClientRequest));
1264  xrdreq.close.requestid = htons(kXR_close);
1265  memcpy(xrdreq.close.fhandle, fhandle, 4);
1266 
1267  if (!prot->Bridge->Run((char *) &xrdreq, 0, 0)) {
1268  TRACEI(REQ, " Failed to run close request on the bridge.");
1269  // Note: we have already completed the request and sent the data to the client.
1270  // Hence, there's no need to send an error. However, since the bridge is potentially
1271  // in a bad state, we close the TCP socket to force the client to reconnect.
1272  return -1;
1273  }
1274 
1275  // We have finished
1276  readClosing = true;
1277  return 1;
1278 
1279  }
1280  // --------- READ or READV
1281 
1282  if ( readChunkList.size() == 1 ) {
1283  // Use a read request for single range
1284 
1285  long l;
1286  long long offs;
1287 
1288  // --------- READ
1289  memset(&xrdreq, 0, sizeof (xrdreq));
1290  xrdreq.read.requestid = htons(kXR_read);
1291  memcpy(xrdreq.read.fhandle, fhandle, 4);
1292  xrdreq.read.dlen = 0;
1293 
1294  offs = readChunkList[0].offset;
1295  l = readChunkList[0].size;
1296 
1297  xrdreq.read.offset = htonll(offs);
1298  xrdreq.read.rlen = htonl(l);
1299 
1300  // If we are using HTTPS or if the client requested trailers, or if the
1301  // read concerns a multirange reponse, disable sendfile
1302  // (in the latter two cases, the extra framing is only done in PostProcessHTTPReq)
1303  if (prot->ishttps || (m_transfer_encoding_chunked && m_trailer_headers) ||
1305  if (!prot->Bridge->setSF((kXR_char *) fhandle, false)) {
1306  TRACE(REQ, " XrdBridge::SetSF(false) failed.");
1307 
1308  }
1309  }
1310 
1311 
1312 
1313  if (l <= 0) {
1314  if (l < 0) {
1315  TRACE(ALL, " Data sizes mismatch.");
1316  return -1;
1317  }
1318  else {
1319  TRACE(ALL, " No more bytes to send.");
1320  reset();
1321  return 1;
1322  }
1323  }
1324 
1325  if ((offs >= filesize) || (offs+l > filesize)) {
1326  httpStatusCode = 416;
1327  httpStatusText = "Range Not Satisfiable";
1328  std::stringstream ss;
1329  ss << "Requested range " << l << "@" << offs << " is past the end of file (" << filesize << ")";
1330  return sendFooterError(ss.str());
1331  }
1332 
1333  if (!prot->Bridge->Run((char *) &xrdreq, 0, 0)) {
1334  mapXrdErrorToHttpStatus();
1335  return sendFooterError("Could not run read request on the bridge");
1336  }
1337  } else {
1338  // --------- READV
1339 
1340  length = ReqReadV(readChunkList);
1341 
1342  if (!prot->Bridge->Run((char *) &xrdreq, (char *) &ralist[0], length)) {
1343  mapXrdErrorToHttpStatus();
1344  return sendFooterError("Could not run ReadV request on the bridge");
1345  }
1346 
1347  }
1348 
1349  // We want to be invoked again after this request is finished
1350  return 0;
1351  } // case 3+
1352 
1353  } // switch (reqstate)
1354 
1355 
1356  } // case XrdHttpReq::rtGET
1357 
1358  case XrdHttpReq::rtPUT:
1359  {
1360  //if (prot->ishttps) {
1361  //prot->SendSimpleResp(501, NULL, NULL, (char *) "HTTPS not supported yet for direct writing. Sorry.", 0);
1362  //return -1;
1363  //}
1364 
1365  if (!fopened) {
1366 
1367  // --------- OPEN for write!
1368  memset(&xrdreq, 0, sizeof (ClientRequest));
1369  xrdreq.open.requestid = htons(kXR_open);
1370  l = resourceplusopaque.length() + 1;
1371  xrdreq.open.dlen = htonl(l);
1372  xrdreq.open.mode = htons(kXR_ur | kXR_uw | kXR_gw | kXR_gr | kXR_or);
1373  if (! XrdHttpProtocol::usingEC)
1375  else
1377 
1378  if (!prot->Bridge->Run((char *) &xrdreq, (char *) resourceplusopaque.c_str(), l)) {
1379  prot->SendSimpleResp(404, NULL, NULL, (char *) "Could not run request.", 0, keepalive);
1380  return -1;
1381  }
1382 
1383 
1384  // We want to be invoked again after this request is finished
1385  // Only if there is data to fetch from the socket or there will
1386  // never be more data
1387  if (prot->BuffUsed() > 0 || (length == 0 && !sendcontinue))
1388  return 0;
1389 
1390  return 1;
1391 
1392  } else {
1393 
1394  if (m_transfer_encoding_chunked) {
1395  if (m_current_chunk_size == m_current_chunk_offset) {
1396  // Chunk has been consumed; we now must process the CRLF.
1397  // Note that we don't support trailer headers.
1398  if (prot->BuffUsed() < 2) return 1;
1399  if (prot->myBuffStart[0] != '\r' || prot->myBuffStart[1] != '\n') {
1400  prot->SendSimpleResp(400, NULL, NULL, (char *) "Invalid trailing chunk encoding.", 0, keepalive);
1401  return -1;
1402  }
1403  prot->BuffConsume(2);
1404  if (m_current_chunk_size == 0) {
1405  // All data has been sent. Turn off chunk processing and
1406  // set the bytes written and length appropriately; on next callback,
1407  // we will hit the close() block below.
1408  m_transfer_encoding_chunked = false;
1409  length = writtenbytes;
1410  return ProcessHTTPReq();
1411  }
1412  m_current_chunk_size = -1;
1413  m_current_chunk_offset = 0;
1414  // If there is more data, we try to process the next chunk; otherwise, return
1415  if (!prot->BuffUsed()) return 1;
1416  }
1417  if (-1 == m_current_chunk_size) {
1418 
1419  // Parse out the next chunk size.
1420  long long idx = 0;
1421  bool found_newline = false;
1422  // Set a maximum size of chunk we will allow
1423  // Nginx sets this to "NGX_MAX_OFF_T_VALUE", which is 9223372036854775807 (a some crazy number)
1424  // We set it to 1TB, which is 1099511627776
1425  // This is to prevent a malicious client from sending a very large chunk size
1426  // or a malformed chunk request.
1427  // 1TB in base-16 is 0x40000000000, so only allow 11 characters, plus the CRLF
1428  long long max_chunk_size_chars = std::min(static_cast<long long>(prot->BuffUsed()), static_cast<long long>(13));
1429  for (; idx < max_chunk_size_chars; idx++) {
1430  if (prot->myBuffStart[idx] == '\n') {
1431  found_newline = true;
1432  break;
1433  }
1434  }
1435  // If we found a new line, but it is the first character in the buffer (no chunk length)
1436  // or if the previous character is not a CR.
1437  if (found_newline && ((idx == 0) || prot->myBuffStart[idx-1] != '\r')) {
1438  prot->SendSimpleResp(400, NULL, NULL, (char *)"Invalid chunked encoding", 0, false);
1439  TRACE(REQ, "XrdHTTP PUT: Sending invalid chunk encoding. Start of chunk should have had a length, followed by a CRLF.");
1440  return -1;
1441  }
1442  if (found_newline) {
1443  char *endptr = NULL;
1444  std::string line_contents(prot->myBuffStart, idx);
1445  long long chunk_contents = strtol(line_contents.c_str(), &endptr, 16);
1446  // Chunk sizes can be followed by trailer information or CRLF
1447  if (*endptr != ';' && *endptr != '\r') {
1448  prot->SendSimpleResp(400, NULL, NULL, (char *)"Invalid chunked encoding", 0, false);
1449  TRACE(REQ, "XrdHTTP PUT: Sending invalid chunk encoding. Chunk size was not followed by a ';' or CR." << __LINE__);
1450  return -1;
1451  }
1452  m_current_chunk_size = chunk_contents;
1453  m_current_chunk_offset = 0;
1454  prot->BuffConsume(idx + 1);
1455  TRACE(REQ, "XrdHTTP PUT: next chunk from client will be " << m_current_chunk_size << " bytes");
1456  } else {
1457  // Need more data!
1458  return 1;
1459  }
1460  }
1461 
1462  if (m_current_chunk_size == 0) {
1463  // All data has been sent. Invoke this routine again immediately to process CRLF
1464  return ProcessHTTPReq();
1465  } else {
1466  // At this point, we have a chunk size defined and should consume payload data
1467  memset(&xrdreq, 0, sizeof (xrdreq));
1468  xrdreq.write.requestid = htons(kXR_write);
1469  memcpy(xrdreq.write.fhandle, fhandle, 4);
1470 
1471  long long chunk_bytes_remaining = m_current_chunk_size - m_current_chunk_offset;
1472  long long bytes_to_write = std::min(static_cast<long long>(prot->BuffUsed()),
1473  chunk_bytes_remaining);
1474 
1475  xrdreq.write.offset = htonll(writtenbytes);
1476  xrdreq.write.dlen = htonl(bytes_to_write);
1477 
1478  TRACEI(REQ, "XrdHTTP PUT: Writing chunk of size " << bytes_to_write << " starting with '" << *(prot->myBuffStart) << "'" << " with " << chunk_bytes_remaining << " bytes remaining in the chunk");
1479  if (!prot->Bridge->Run((char *) &xrdreq, prot->myBuffStart, bytes_to_write)) {
1480  mapXrdErrorToHttpStatus();
1481  return sendFooterError("Could not run write request on the bridge");
1482  }
1483  // If there are more bytes in the buffer, then immediately call us after the
1484  // write is finished; otherwise, wait for data.
1485  return (prot->BuffUsed() > chunk_bytes_remaining) ? 0 : 1;
1486  }
1487  } else if (writtenbytes < length) {
1488 
1489 
1490  // --------- WRITE
1491  memset(&xrdreq, 0, sizeof (xrdreq));
1492  xrdreq.write.requestid = htons(kXR_write);
1493  memcpy(xrdreq.write.fhandle, fhandle, 4);
1494 
1495  long long bytes_to_read = std::min(static_cast<long long>(prot->BuffUsed()),
1496  length - writtenbytes);
1497 
1498  xrdreq.write.offset = htonll(writtenbytes);
1499  xrdreq.write.dlen = htonl(bytes_to_read);
1500 
1501  TRACEI(REQ, "Writing " << bytes_to_read);
1502  if (!prot->Bridge->Run((char *) &xrdreq, prot->myBuffStart, bytes_to_read)) {
1503  mapXrdErrorToHttpStatus();
1504  return sendFooterError("Could not run write request on the bridge");
1505  }
1506 
1507  if (writtenbytes + prot->BuffUsed() >= length)
1508  // Trigger an immediate recall after this request has finished
1509  return 0;
1510  else
1511  // We want to be invoked again after this request is finished
1512  // only if there is pending data
1513  return 1;
1514 
1515 
1516 
1517  } else {
1518 
1519  // --------- CLOSE
1520  memset(&xrdreq, 0, sizeof (ClientRequest));
1521  xrdreq.close.requestid = htons(kXR_close);
1522  memcpy(xrdreq.close.fhandle, fhandle, 4);
1523 
1524 
1525  if (!prot->Bridge->Run((char *) &xrdreq, 0, 0)) {
1526  mapXrdErrorToHttpStatus();
1527  return sendFooterError("Could not run close request on the bridge");
1528  }
1529 
1530  // We have finished
1531  return 1;
1532 
1533  }
1534 
1535  }
1536 
1537  break;
1538 
1539  }
1540  case XrdHttpReq::rtOPTIONS:
1541  {
1542  prot->SendSimpleResp(200, NULL, (char *) "DAV: 1\r\nDAV: <http://apache.org/dav/propset/fs/1>\r\nAllow: HEAD,GET,PUT,PROPFIND,DELETE,OPTIONS", NULL, 0, keepalive);
1543  bool ret_keepalive = keepalive; // reset() clears keepalive
1544  reset();
1545  return ret_keepalive ? 1 : -1;
1546  }
1547  case XrdHttpReq::rtDELETE:
1548  {
1549 
1550 
1551  switch (reqstate) {
1552 
1553  case 0: // Stat()
1554  {
1555 
1556 
1557  // --------- STAT is always the first step
1558  memset(&xrdreq, 0, sizeof (ClientRequest));
1559  xrdreq.stat.requestid = htons(kXR_stat);
1560  std::string s = resourceplusopaque.c_str();
1561 
1562 
1563  l = resourceplusopaque.length() + 1;
1564  xrdreq.stat.dlen = htonl(l);
1565 
1566  if (!prot->Bridge->Run((char *) &xrdreq, (char *) resourceplusopaque.c_str(), l)) {
1567  prot->SendSimpleResp(501, NULL, NULL, (char *) "Could not run request.", 0, false);
1568  return -1;
1569  }
1570 
1571  // We need to be invoked again to complete the request
1572  return 0;
1573  }
1574  default:
1575 
1576  if (fileflags & kXR_isDir) {
1577  // --------- RMDIR
1578  memset(&xrdreq, 0, sizeof (ClientRequest));
1579  xrdreq.rmdir.requestid = htons(kXR_rmdir);
1580 
1581  std::string s = resourceplusopaque.c_str();
1582 
1583  l = s.length() + 1;
1584  xrdreq.rmdir.dlen = htonl(l);
1585 
1586  if (!prot->Bridge->Run((char *) &xrdreq, (char *) s.c_str(), l)) {
1587  prot->SendSimpleResp(501, NULL, NULL, (char *) "Could not run rmdir request.", 0, false);
1588  return -1;
1589  }
1590  } else {
1591  // --------- DELETE
1592  memset(&xrdreq, 0, sizeof (ClientRequest));
1593  xrdreq.rm.requestid = htons(kXR_rm);
1594 
1595  std::string s = resourceplusopaque.c_str();
1596 
1597  l = s.length() + 1;
1598  xrdreq.rm.dlen = htonl(l);
1599 
1600  if (!prot->Bridge->Run((char *) &xrdreq, (char *) s.c_str(), l)) {
1601  prot->SendSimpleResp(501, NULL, NULL, (char *) "Could not run rm request.", 0, false);
1602  return -1;
1603  }
1604  }
1605 
1606 
1607  // We don't want to be invoked again after this request is finished
1608  return 1;
1609 
1610  }
1611 
1612 
1613 
1614  }
1615  case XrdHttpReq::rtPATCH:
1616  {
1617  prot->SendSimpleResp(501, NULL, NULL, (char *) "Request not supported yet.", 0, false);
1618 
1619  return -1;
1620  }
1622  {
1623 
1624 
1625 
1626  switch (reqstate) {
1627 
1628  case 0: // Stat() and add the current item to the list of the things to send
1629  {
1630 
1631  if (length > 0) {
1632  TRACE(REQ, "Reading request body " << length << " bytes.");
1633  char *p = 0;
1634  // We have to specifically read all the request body
1635 
1636  if (prot->BuffgetData(length, &p, true) < length) {
1637  prot->SendSimpleResp(501, NULL, NULL, (char *) "Error in getting the PROPFIND request body.", 0, false);
1638  return -1;
1639  }
1640 
1641  if ((depth > 1) || (depth < 0)) {
1642  prot->SendSimpleResp(501, NULL, NULL, (char *) "Invalid depth value.", 0, false);
1643  return -1;
1644  }
1645 
1646 
1647  parseBody(p, length);
1648  }
1649 
1650 
1651  // --------- STAT is always the first step
1652  memset(&xrdreq, 0, sizeof (ClientRequest));
1653  xrdreq.stat.requestid = htons(kXR_stat);
1654  std::string s = resourceplusopaque.c_str();
1655 
1656 
1657  l = resourceplusopaque.length() + 1;
1658  xrdreq.stat.dlen = htonl(l);
1659 
1660  if (!prot->Bridge->Run((char *) &xrdreq, (char *) resourceplusopaque.c_str(), l)) {
1661  prot->SendSimpleResp(501, NULL, NULL, (char *) "Could not run request.", 0, false);
1662  return -1;
1663  }
1664 
1665 
1666  if (depth == 0) {
1667  // We don't need to be invoked again
1668  return 1;
1669  } else
1670  // We need to be invoked again to complete the request
1671  return 0;
1672 
1673 
1674 
1675  break;
1676  }
1677 
1678  default: // Dirlist()
1679  {
1680 
1681  // --------- DIRLIST
1682  memset(&xrdreq, 0, sizeof (ClientRequest));
1684 
1685  std::string s = resourceplusopaque.c_str();
1687  //s += "?xrd.dirstat=1";
1688 
1689  l = s.length() + 1;
1690  xrdreq.dirlist.dlen = htonl(l);
1691 
1692  if (!prot->Bridge->Run((char *) &xrdreq, (char *) s.c_str(), l)) {
1693  prot->SendSimpleResp(501, NULL, NULL, (char *) "Could not run request.", 0, false);
1694  return -1;
1695  }
1696 
1697  // We don't want to be invoked again after this request is finished
1698  return 1;
1699  }
1700  }
1701 
1702 
1703  break;
1704  }
1705  case XrdHttpReq::rtMKCOL:
1706  {
1707 
1708  // --------- MKDIR
1709  memset(&xrdreq, 0, sizeof (ClientRequest));
1710  xrdreq.mkdir.requestid = htons(kXR_mkdir);
1711 
1712  std::string s = resourceplusopaque.c_str();
1714 
1715  l = s.length() + 1;
1716  xrdreq.mkdir.dlen = htonl(l);
1717 
1718  if (!prot->Bridge->Run((char *) &xrdreq, (char *) s.c_str(), l)) {
1719  prot->SendSimpleResp(501, NULL, NULL, (char *) "Could not run request.", 0, false);
1720  return -1;
1721  }
1722 
1723  // We don't want to be invoked again after this request is finished
1724  return 1;
1725  }
1726  case XrdHttpReq::rtMOVE:
1727  {
1728 
1729  // --------- MOVE
1730  memset(&xrdreq, 0, sizeof (ClientRequest));
1731  xrdreq.mv.requestid = htons(kXR_mv);
1732 
1733  std::string s = resourceplusopaque.c_str();
1734  s += " ";
1735 
1736  char buf[256];
1737  char *ppath;
1738  int port = 0;
1739  if (parseURL((char *) destination.c_str(), buf, port, &ppath)) {
1740  prot->SendSimpleResp(501, NULL, NULL, (char *) "Cannot parse destination url.", 0, false);
1741  return -1;
1742  }
1743 
1744  char buf2[256];
1745  strcpy(buf2, host.c_str());
1746  char *pos = strchr(buf2, ':');
1747  if (pos) *pos = '\0';
1748 
1749  // If we are a redirector we enforce that the host field is equal to
1750  // whatever was written in the destination url
1751  //
1752  // If we are a data server instead we cannot enforce anything, we will
1753  // just ignore the host part of the destination
1754  if ((prot->myRole == kXR_isManager) && strcmp(buf, buf2)) {
1755  prot->SendSimpleResp(501, NULL, NULL, (char *) "Only in-place renaming is supported for MOVE.", 0, false);
1756  return -1;
1757  }
1758 
1759 
1760 
1761 
1762  s += ppath;
1763 
1764  l = s.length() + 1;
1765  xrdreq.mv.dlen = htonl(l);
1767 
1768  if (!prot->Bridge->Run((char *) &xrdreq, (char *) s.c_str(), l)) {
1769  prot->SendSimpleResp(501, NULL, NULL, (char *) "Could not run request.", 0, false);
1770  return -1;
1771  }
1772 
1773  // We don't want to be invoked again after this request is finished
1774  return 1;
1775 
1776  }
1777  default:
1778  {
1779  prot->SendSimpleResp(501, NULL, NULL, (char *) "Request not supported.", 0, false);
1780  return -1;
1781  }
1782 
1783  }
1784 
1785  return 1;
1786 }
kXR_unt16 requestid
Definition: XProtocol.hh:479
kXR_char options[1]
Definition: XProtocol.hh:248
kXR_int16 arg1len
Definition: XProtocol.hh:430
#define kXR_isManager
Definition: XProtocol.hh:1156
kXR_unt16 requestid
Definition: XProtocol.hh:806
struct ClientCloseRequest close
Definition: XProtocol.hh:851
kXR_char fhandle[4]
Definition: XProtocol.hh:807
struct ClientMkdirRequest mkdir
Definition: XProtocol.hh:858
kXR_int32 dlen
Definition: XProtocol.hh:431
kXR_int64 offset
Definition: XProtocol.hh:646
kXR_unt16 requestid
Definition: XProtocol.hh:644
kXR_unt16 options
Definition: XProtocol.hh:481
struct ClientDirlistRequest dirlist
Definition: XProtocol.hh:852
kXR_unt16 requestid
Definition: XProtocol.hh:228
@ kXR_open_wrto
Definition: XProtocol.hh:469
@ kXR_delete
Definition: XProtocol.hh:453
@ kXR_open_read
Definition: XProtocol.hh:456
@ kXR_mkpath
Definition: XProtocol.hh:460
@ kXR_new
Definition: XProtocol.hh:455
@ kXR_retstat
Definition: XProtocol.hh:463
struct ClientOpenRequest open
Definition: XProtocol.hh:860
@ kXR_dstat
Definition: XProtocol.hh:240
kXR_unt16 requestid
Definition: XProtocol.hh:428
kXR_char fhandle[4]
Definition: XProtocol.hh:645
kXR_char fhandle[4]
Definition: XProtocol.hh:229
@ kXR_read
Definition: XProtocol.hh:125
@ kXR_mkdir
Definition: XProtocol.hh:120
@ kXR_dirlist
Definition: XProtocol.hh:116
@ kXR_rm
Definition: XProtocol.hh:126
@ kXR_write
Definition: XProtocol.hh:131
@ kXR_rmdir
Definition: XProtocol.hh:127
@ kXR_mv
Definition: XProtocol.hh:121
@ kXR_stat
Definition: XProtocol.hh:129
@ kXR_close
Definition: XProtocol.hh:115
kXR_int32 dlen
Definition: XProtocol.hh:699
struct ClientRmRequest rm
Definition: XProtocol.hh:869
kXR_int32 dlen
Definition: XProtocol.hh:648
struct ClientReadRequest read
Definition: XProtocol.hh:867
struct ClientMvRequest mv
Definition: XProtocol.hh:859
kXR_unt16 requestid
Definition: XProtocol.hh:768
kXR_int32 dlen
Definition: XProtocol.hh:483
struct ClientRmdirRequest rmdir
Definition: XProtocol.hh:870
kXR_unt16 requestid
Definition: XProtocol.hh:415
kXR_unt16 mode
Definition: XProtocol.hh:480
kXR_char options[1]
Definition: XProtocol.hh:416
kXR_unt16 requestid
Definition: XProtocol.hh:697
@ kXR_mkdirpath
Definition: XProtocol.hh:410
struct ClientStatRequest stat
Definition: XProtocol.hh:873
kXR_int64 offset
Definition: XProtocol.hh:808
struct ClientWriteRequest write
Definition: XProtocol.hh:876
kXR_int32 dlen
Definition: XProtocol.hh:772
kXR_int32 rlen
Definition: XProtocol.hh:647
@ kXR_gw
Definition: XProtocol.hh:444
@ kXR_ur
Definition: XProtocol.hh:440
@ kXR_uw
Definition: XProtocol.hh:441
@ kXR_gr
Definition: XProtocol.hh:443
@ kXR_or
Definition: XProtocol.hh:446
@ kXR_isDir
Definition: XProtocol.hh:1221
kXR_unt16 requestid
Definition: XProtocol.hh:708
int kXR_int32
Definition: XPtypes.hh:89
unsigned char kXR_char
Definition: XPtypes.hh:65
#define DEBUG(x)
Definition: XrdBwmTrace.hh:54
int parseURL(char *url, char *host, int &port, char **path)
Definition: XrdHttpUtils.cc:77
std::vector< XrdOucIOVec2 > XrdHttpIOList
Definition: XrdHttpUtils.hh:95
std::string obfuscateAuth(const std::string &input)
#define TRACE_DEBUG
Definition: XrdTrace.hh:36
#define TRACING(x)
Definition: XrdTrace.hh:70
#define TRACEI(act, x)
Definition: XrdTrace.hh:66
XrdHttpChecksumRawPtr getChecksumToRun(const std::string &userDigest) const
std::string getXRootDConfigDigestName() const
virtual int ProcessReq(XrdHttpExtReq &)=0
static kXR_int32 myRole
Our role.
XrdXrootd::Bridge * Bridge
The Bridge that we use to exercise the xrootd internals.
static char * staticredir
static XrdHttpChecksumHandler cksumHandler
int doChksum(const XrdOucString &fname)
Perform a checksum request.
static XrdOucHash< StaticPreloadInfo > * staticpreload
int doStat(char *fname)
Perform a Stat request.
static char * listredir
Url to redirect to in the case a listing is requested.
static bool listdeny
If true, any form of listing is denied.
static bool embeddedstatic
If true, use the embedded css and icons.
const XrdHttpIOList & NextReadList()
return XrdHttpIOList for sending to read or readv
bool isSingleRange()
indicates a single range (implied whole file, or single range) or empty file
int reqstate
State machine to talk to the bridge.
Definition: XrdHttpReq.hh:331
char fhandle[4]
Definition: XrdHttpReq.hh:324
int ReqReadV(const XrdHttpIOList &cl)
Prepare the buffers for sending a readv request.
Definition: XrdHttpReq.cc:393
int parseBody(char *body, long long len)
Parse the body of a request, assuming that it's XML and that it's entirely in memory.
Definition: XrdHttpReq.cc:94
std::vector< readahead_list > ralist
Definition: XrdHttpReq.hh:197
XrdOucString resource
The resource specified by the request, stripped of opaque data.
Definition: XrdHttpReq.hh:249
int ProcessHTTPReq()
Definition: XrdHttpReq.cc:939
long fileflags
Definition: XrdHttpReq.hh:321
XrdOucString resourceplusopaque
The resource specified by the request, including all the opaque data.
Definition: XrdHttpReq.hh:253
std::string host
The host field specified in the req.
Definition: XrdHttpReq.hh:273
XrdHttpChecksumHandler::XrdHttpChecksumRawPtr m_req_cksum
The checksum that was ran for this request.
Definition: XrdHttpReq.hh:281
bool m_appended_hdr2cgistr
Definition: XrdHttpReq.hh:292
void appendOpaque(XrdOucString &s, XrdSecEntity *secent, char *hash, time_t tnow)
Definition: XrdHttpReq.cc:637
bool m_appended_asize
Track whether we already appended the oss.asize argument for PUTs.
Definition: XrdHttpReq.hh:294
XrdOucString m_resource_with_digest
Definition: XrdHttpReq.hh:286
long long filesize
Definition: XrdHttpReq.hh:320
bool readClosing
Definition: XrdHttpReq.hh:261
void Put(const char *varname, const char *value)
Definition: XrdOucEnv.hh:85
const char * c_str() const
int erasefromend(int sz=0)
bool endswith(char c)
bool beginswith(char c)
int length() const
void append(const int i)
virtual int setSF(kXR_char *fhandle, bool seton=false)=0
virtual bool Run(const char *xreqP, char *xdataP=0, int xdataL=0)=0

References XrdOucString::append(), appendOpaque(), ClientMvRequest::arg1len, XrdOucString::beginswith(), XrdHttpProtocol::Bridge, XrdOucString::c_str(), XrdHttpProtocol::cksumHandler, ClientRequest::close, closeAfterError, XrdHttpProtocol::StaticPreloadInfo::data, DEBUG, depth, destination, ClientRequest::dirlist, ClientDirlistRequest::dlen, ClientMkdirRequest::dlen, ClientMvRequest::dlen, ClientOpenRequest::dlen, ClientReadRequest::dlen, ClientRmRequest::dlen, ClientRmdirRequest::dlen, ClientStatRequest::dlen, ClientWriteRequest::dlen, XrdHttpProtocol::doChksum(), XrdHttpProtocol::doStat(), XrdHttpProtocol::embeddedstatic, XrdOucString::endswith(), XrdOucString::erasefromend(), ClientCloseRequest::fhandle, ClientReadRequest::fhandle, ClientWriteRequest::fhandle, fhandle, fileflags, filesize, fopened, XrdHttpChecksumHandler::getChecksumToRun(), XrdHttpChecksum::getXRootDConfigDigestName(), hdr2cgistr, host, XrdHttpReadRangeHandler::isSingleRange(), keepalive, kXR_close, kXR_delete, kXR_dirlist, kXR_dstat, kXR_gr, kXR_gw, kXR_isDir, kXR_isManager, kXR_mkdir, kXR_mkdirpath, kXR_mkpath, kXR_mv, kXR_new, kXR_open, kXR_open_read, kXR_open_wrto, kXR_or, kXR_read, kXR_retstat, kXR_rm, kXR_rmdir, kXR_stat, kXR_ur, kXR_uw, kXR_write, XrdHttpProtocol::StaticPreloadInfo::len, length, XrdOucString::length(), XrdHttpProtocol::listdeny, XrdHttpProtocol::listredir, m_appended_asize, m_appended_hdr2cgistr, m_req_cksum, m_req_digest, m_resource_with_digest, ClientRequest::mkdir, ClientOpenRequest::mode, ClientRequest::mv, XrdHttpProtocol::myRole, XrdHttpReadRangeHandler::NextReadList(), obfuscateAuth(), ClientReadRequest::offset, ClientWriteRequest::offset, opaque, ClientRequest::open, ClientDirlistRequest::options, ClientMkdirRequest::options, ClientOpenRequest::options, parseBody(), parseURL(), XrdHttpExtHandler::ProcessReq(), XrdOucEnv::Put(), quote(), ralist, ClientRequest::read, readClosing, readRangeHandler, ReqReadV(), reqstate, request, ClientCloseRequest::requestid, ClientDirlistRequest::requestid, ClientMkdirRequest::requestid, ClientMvRequest::requestid, ClientOpenRequest::requestid, ClientReadRequest::requestid, ClientRmRequest::requestid, ClientRmdirRequest::requestid, ClientStatRequest::requestid, ClientWriteRequest::requestid, reset(), resource, resourceplusopaque, ClientReadRequest::rlen, ClientRequest::rm, ClientRequest::rmdir, rtDELETE, rtGET, rtHEAD, rtMalformed, rtMKCOL, rtMOVE, rtOPTIONS, rtPATCH, rtPROPFIND, rtPUT, rtUnknown, rtUnset, XrdXrootd::Bridge::Run(), sendcontinue, XrdXrootd::Bridge::setSF(), ClientRequest::stat, XrdHttpProtocol::staticpreload, XrdHttpProtocol::staticredir, TRACE, TRACE_DEBUG, TRACEI, TRACING, ClientRequest::write, writtenbytes, and xrdreq.

Referenced by XrdHttpProtocol::Process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Redir()

bool XrdHttpReq::Redir ( XrdXrootd::Bridge::Context info,
int  port,
const char *  hname 
)
virtual

Redirect the client to another host:port.

The Redir() method is called when the client must be redirected to another host.

Parameters
infothe context associated with the result.
portthe port number in host byte format.
hnamethe DNS name of the host or IP address is IPV4 or IPV6 format (i.e. "n.n.n.n" or "[ipv6_addr]").
Returns
true continue normal processing. false terminate the bridge and close the link.
Parameters
infothe result context
portthe port number
hnamethe destination host

Implements XrdXrootd::Bridge::Result.

Definition at line 541 of file XrdHttpReq.cc.

544  {
545 
546 
547 
548  char buf[512];
549  char hash[512];
550  hash[0] = '\0';
551 
552  if (prot->isdesthttps)
553  redirdest = "Location: https://";
554  else
555  redirdest = "Location: http://";
556 
557  // port < 0 signals switch to full URL
558  if (port < 0)
559  {
560  if (strncmp(hname, "file://", 7) == 0)
561  {
562  TRACE(REQ, " XrdHttpReq::Redir Switching to file:// ");
563  redirdest = "Location: "; // "file://" already contained in hname
564  }
565  }
566  // Beware, certain Ofs implementations (e.g. EOS) add opaque data directly to the host name
567  // This must be correctly treated here and appended to the opaque info
568  // that we may already have
569  char *pp = strchr((char *)hname, '?');
570  char *vardata = 0;
571  if (pp) {
572  *pp = '\0';
573  redirdest += hname;
574  vardata = pp+1;
575  int varlen = strlen(vardata);
576 
577  //Now extract the remaining, vardata points to it
578  while(*vardata == '&' && varlen) {vardata++; varlen--;}
579 
580  // Put the question mark back where it was
581  *pp = '?';
582  }
583  else
584  redirdest += hname;
585 
586  if (port > 0) {
587  sprintf(buf, ":%d", port);
588  redirdest += buf;
589  }
590 
592 
593  // Here we put back the opaque info, if any
594  if (vardata) {
595  char *newvardata = quote(vardata);
596  redirdest += "?&";
597  redirdest += newvardata;
598  free(newvardata);
599  }
600 
601  // Shall we put also the opaque data of the request? Maybe not
602  //int l;
603  //if (opaque && opaque->Env(l))
604  // redirdest += opaque->Env(l);
605 
606 
607  time_t timenow = 0;
608  if (!prot->isdesthttps && prot->ishttps) {
609  // If the destination is not https, then we suppose that it
610  // will need this token to fill its authorization info
611  timenow = time(0);
612  calcHashes(hash, this->resource.c_str(), (kXR_int16) request,
613  &prot->SecEntity,
614  timenow,
615  prot->secretkey);
616  }
617 
618  if (hash[0]) {
619  appendOpaque(redirdest, &prot->SecEntity, hash, timenow);
620  } else
621  appendOpaque(redirdest, 0, 0, 0);
622 
623 
624  TRACE(REQ, " XrdHttpReq::Redir Redirecting to " << obfuscateAuth(redirdest.c_str()).c_str());
625 
626  if (request != rtGET)
627  prot->SendSimpleResp(307, NULL, (char *) redirdest.c_str(), 0, 0, keepalive);
628  else
629  prot->SendSimpleResp(302, NULL, (char *) redirdest.c_str(), 0, 0, keepalive);
630 
631  bool ret_keepalive = keepalive; // reset() clears keepalive
632  reset();
633  return ret_keepalive;
634 };
short kXR_int16
Definition: XPtypes.hh:66
void calcHashes(char *hash, const char *fn, kXR_int16 request, XrdSecEntity *secent, time_t tim, const char *key)
static char * secretkey
The key used to calculate the url hashes.
static bool isdesthttps
True if the redirections must be towards https targets.
XrdSecEntity SecEntity
Authentication area.
XrdOucString redirdest
Definition: XrdHttpReq.hh:311

References appendOpaque(), XrdOucString::c_str(), calcHashes(), XrdHttpProtocol::isdesthttps, keepalive, obfuscateAuth(), quote(), redirdest, request, reset(), resource, rtGET, XrdHttpProtocol::SecEntity, XrdHttpProtocol::secretkey, and TRACE.

+ Here is the call graph for this function:

◆ ReqReadV()

int XrdHttpReq::ReqReadV ( const XrdHttpIOList cl)

Prepare the buffers for sending a readv request.

Definition at line 393 of file XrdHttpReq.cc.

393  {
394 
395 
396  // Now we build the protocol-ready read ahead list
397  // and also put the correct placeholders inside the cache
398  int n = cl.size();
399  ralist.clear();
400  ralist.reserve(n);
401 
402  int j = 0;
403  for (const auto &c: cl) {
404  ralist.emplace_back();
405  auto &ra = ralist.back();
406  memcpy(&ra.fhandle, this->fhandle, 4);
407 
408  ra.offset = c.offset;
409  ra.rlen = c.size;
410  j++;
411  }
412 
413  if (j > 0) {
414 
415  // Prepare a request header
416 
417  memset(&xrdreq, 0, sizeof (xrdreq));
418 
419  xrdreq.header.requestid = htons(kXR_readv);
420  xrdreq.readv.dlen = htonl(j * sizeof (struct readahead_list));
421 
422  clientMarshallReadAheadList(j);
423 
424 
425  }
426 
427  return (j * sizeof (struct readahead_list));
428 }
struct ClientReadVRequest readv
Definition: XProtocol.hh:868
@ kXR_readv
Definition: XProtocol.hh:137

References ClientReadVRequest::dlen, ClientRequest::header, kXR_readv, ralist, ClientRequest::readv, ClientRequestHdr::requestid, and xrdreq.

Referenced by ProcessHTTPReq().

+ Here is the caller graph for this function:

◆ reset()

void XrdHttpReq::reset ( )
virtual

State machine to talk to the bridge

Definition at line 2815 of file XrdHttpReq.cc.

2815  {
2816 
2817  TRACE(REQ, " XrdHttpReq request ended.");
2818 
2819  //if (xmlbody) xmlFreeDoc(xmlbody);
2821  readClosing = false;
2822  closeAfterError = false;
2823  writtenbytes = 0;
2824  etext.clear();
2825  redirdest = "";
2826 
2827  // // Here we should deallocate this
2828  // const struct iovec *iovP //!< pointer to data array
2829  // int iovN, //!< array count
2830  // int iovL, //!< byte count
2831  // bool final //!< true -> final result
2832 
2833 
2834  //xmlbody = 0;
2835  depth = 0;
2838  ralist.clear();
2839  ralist.shrink_to_fit();
2840 
2841  request = rtUnset;
2842  resource = "";
2843  allheaders.clear();
2844 
2845  // Reset the state of the request's digest request.
2846  m_req_digest.clear();
2847  m_digest_header.clear();
2848  m_req_cksum = nullptr;
2849 
2851  m_user_agent = "";
2852 
2853  headerok = false;
2854  keepalive = true;
2855  length = 0;
2856  filesize = 0;
2857  depth = 0;
2858  sendcontinue = false;
2859 
2860  m_transfer_encoding_chunked = false;
2861  m_current_chunk_size = -1;
2862  m_current_chunk_offset = 0;
2863 
2864  m_trailer_headers = false;
2865  m_status_trailer = false;
2866 
2868  reqstate = 0;
2869 
2870  memset(&xrdreq, 0, sizeof (xrdreq));
2871  memset(&xrdresp, 0, sizeof (xrdresp));
2873 
2874  etext.clear();
2875  redirdest = "";
2876 
2877  stringresp = "";
2878 
2879  host = "";
2880  destination = "";
2881  hdr2cgistr = "";
2882  m_appended_hdr2cgistr = false;
2883  m_appended_asize = false;
2884 
2885  iovP = 0;
2886  iovN = 0;
2887  iovL = 0;
2888 
2889 
2890  if (opaque) delete(opaque);
2891  opaque = 0;
2892 
2893  fopened = false;
2894 
2895  final = false;
2896 
2897  mScitag = -1;
2898 }
@ kXR_noErrorYet
Definition: XProtocol.hh:1027
@ kXR_noResponsesYet
Definition: XProtocol.hh:908
void reset()
resets this handler
std::string m_digest_header
The computed digest for the HTTP response header.
Definition: XrdHttpReq.hh:288
std::string stringresp
If we want to give a string as a response, we compose it here.
Definition: XrdHttpReq.hh:328

References allheaders, closeAfterError, depth, destination, etext, filesize, fopened, hdr2cgistr, headerok, host, iovL, iovN, iovP, keepalive, kXR_noErrorYet, kXR_noResponsesYet, length, m_appended_asize, m_appended_hdr2cgistr, m_digest_header, m_req_cksum, m_req_digest, m_resource_with_digest, mScitag, opaque, ralist, readClosing, readRangeHandler, redirdest, reqstate, request, XrdHttpReadRangeHandler::reset(), resource, rtUnset, sendcontinue, stringresp, TRACE, writtenbytes, xrderrcode, xrdreq, and xrdresp.

Referenced by ~XrdHttpReq(), Data(), Done(), Error(), XrdHttpProtocol::Process(), ProcessHTTPReq(), and Redir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTransferStatusHeader()

void XrdHttpReq::setTransferStatusHeader ( std::string &  header)

Definition at line 2117 of file XrdHttpReq.cc.

2117  {
2118  if (m_status_trailer) {
2119  if (header.empty()) {
2120  header += "Trailer: X-Transfer-Status";
2121  } else {
2122  header += "\r\nTrailer: X-Transfer-Status";
2123  }
2124  }
2125 }

◆ userAgent()

const std::string& XrdHttpReq::userAgent ( ) const
inline

Definition at line 215 of file XrdHttpReq.hh.

215 {return m_user_agent;}

Referenced by XrdHttpProtocol::Process().

+ Here is the caller graph for this function:

Member Data Documentation

◆ allheaders

std::map<std::string, std::string> XrdHttpReq::allheaders

Definition at line 246 of file XrdHttpReq.hh.

Referenced by parseLine(), and reset().

◆ closeAfterError

bool XrdHttpReq::closeAfterError

Definition at line 265 of file XrdHttpReq.hh.

Referenced by ProcessHTTPReq(), and reset().

◆ depth

int XrdHttpReq::depth

Definition at line 269 of file XrdHttpReq.hh.

Referenced by XrdHttpReq(), parseLine(), ProcessHTTPReq(), and reset().

◆ destination

std::string XrdHttpReq::destination

The destination field specified in the req.

Definition at line 275 of file XrdHttpReq.hh.

Referenced by parseLine(), ProcessHTTPReq(), and reset().

◆ etext

std::string XrdHttpReq::etext

Definition at line 310 of file XrdHttpReq.hh.

Referenced by Error(), and reset().

◆ fhandle

char XrdHttpReq::fhandle[4]

Definition at line 324 of file XrdHttpReq.hh.

Referenced by ProcessHTTPReq().

◆ filectime

long XrdHttpReq::filectime

Definition at line 323 of file XrdHttpReq.hh.

◆ fileflags

long XrdHttpReq::fileflags

Definition at line 321 of file XrdHttpReq.hh.

Referenced by XrdHttpProtocol::doStat(), and ProcessHTTPReq().

◆ filemodtime

long XrdHttpReq::filemodtime

Definition at line 322 of file XrdHttpReq.hh.

Referenced by XrdHttpProtocol::doStat().

◆ filesize

long long XrdHttpReq::filesize

Definition at line 320 of file XrdHttpReq.hh.

Referenced by XrdHttpProtocol::doStat(), ProcessHTTPReq(), and reset().

◆ final

bool XrdHttpReq::final

true -> final result

Definition at line 317 of file XrdHttpReq.hh.

◆ fopened

bool XrdHttpReq::fopened

Definition at line 325 of file XrdHttpReq.hh.

Referenced by XrdHttpReq(), ProcessHTTPReq(), and reset().

◆ hdr2cgistr

std::string XrdHttpReq::hdr2cgistr

Additional opaque info that may come from the hdr2cgi directive.

Definition at line 291 of file XrdHttpReq.hh.

Referenced by addCgi(), appendOpaque(), ProcessHTTPReq(), and reset().

◆ headerok

bool XrdHttpReq::headerok

Tells if we have finished reading the header.

Definition at line 257 of file XrdHttpReq.hh.

Referenced by XrdHttpReq(), XrdHttpProtocol::Process(), and reset().

◆ host

std::string XrdHttpReq::host

The host field specified in the req.

Definition at line 273 of file XrdHttpReq.hh.

Referenced by ProcessHTTPReq(), and reset().

◆ iovL

int XrdHttpReq::iovL

byte count

Definition at line 316 of file XrdHttpReq.hh.

Referenced by Data(), and reset().

◆ iovN

int XrdHttpReq::iovN

array count

Definition at line 315 of file XrdHttpReq.hh.

Referenced by Data(), Done(), and reset().

◆ iovP

const struct iovec* XrdHttpReq::iovP

The latest data chunks got from the xrd layer. These are valid only inside the callbacks!

pointer to data array

Definition at line 314 of file XrdHttpReq.hh.

Referenced by Data(), and reset().

◆ keepalive

bool XrdHttpReq::keepalive

Definition at line 267 of file XrdHttpReq.hh.

Referenced by parseFirstLine(), parseLine(), ProcessHTTPReq(), Redir(), and reset().

◆ length

long long XrdHttpReq::length

◆ m_appended_asize

bool XrdHttpReq::m_appended_asize {false}

Track whether we already appended the oss.asize argument for PUTs.

Definition at line 294 of file XrdHttpReq.hh.

Referenced by ProcessHTTPReq(), and reset().

◆ m_appended_hdr2cgistr

bool XrdHttpReq::m_appended_hdr2cgistr

Definition at line 292 of file XrdHttpReq.hh.

Referenced by ProcessHTTPReq(), and reset().

◆ m_digest_header

std::string XrdHttpReq::m_digest_header

The computed digest for the HTTP response header.

Definition at line 288 of file XrdHttpReq.hh.

Referenced by reset().

◆ m_req_cksum

XrdHttpChecksumHandler::XrdHttpChecksumRawPtr XrdHttpReq::m_req_cksum = nullptr

The checksum that was ran for this request.

Definition at line 281 of file XrdHttpReq.hh.

Referenced by ProcessHTTPReq(), and reset().

◆ m_req_digest

std::string XrdHttpReq::m_req_digest

The requested digest type.

Definition at line 278 of file XrdHttpReq.hh.

Referenced by parseLine(), ProcessHTTPReq(), and reset().

◆ m_resource_with_digest

XrdOucString XrdHttpReq::m_resource_with_digest

The checksum algorithm is specified as part of the opaque data in the URL. Hence, when a digest is generated to satisfy a request, we cache the tweaked URL in this data member.

Definition at line 286 of file XrdHttpReq.hh.

Referenced by ProcessHTTPReq(), and reset().

◆ mScitag

int XrdHttpReq::mScitag

Definition at line 336 of file XrdHttpReq.hh.

Referenced by XrdHttpExtReq::XrdHttpExtReq(), XrdHttpReq(), and reset().

◆ opaque

XrdOucEnv* XrdHttpReq::opaque

The opaque data, after parsing.

Definition at line 251 of file XrdHttpReq.hh.

Referenced by XrdHttpExtReq::XrdHttpExtReq(), XrdHttpReq(), appendOpaque(), parseLine(), XrdHttpProtocol::Process(), ProcessHTTPReq(), and reset().

◆ ralist

std::vector<readahead_list> XrdHttpReq::ralist

Definition at line 197 of file XrdHttpReq.hh.

Referenced by ProcessHTTPReq(), ReqReadV(), and reset().

◆ readClosing

bool XrdHttpReq::readClosing

Definition at line 261 of file XrdHttpReq.hh.

Referenced by ProcessHTTPReq(), and reset().

◆ readRangeHandler

XrdHttpReadRangeHandler XrdHttpReq::readRangeHandler

Tracking the next ranges of data to read during GET.

Definition at line 260 of file XrdHttpReq.hh.

Referenced by File(), parseLine(), ProcessHTTPReq(), and reset().

◆ redirdest

XrdOucString XrdHttpReq::redirdest

Definition at line 311 of file XrdHttpReq.hh.

Referenced by Redir(), and reset().

◆ reqstate

int XrdHttpReq::reqstate

State machine to talk to the bridge.

Definition at line 331 of file XrdHttpReq.hh.

Referenced by XrdHttpProtocol::Process(), ProcessHTTPReq(), and reset().

◆ request

ReqType XrdHttpReq::request

The request we got.

Definition at line 241 of file XrdHttpReq.hh.

Referenced by Error(), parseFirstLine(), parseLine(), XrdHttpProtocol::Process(), ProcessHTTPReq(), Redir(), and reset().

◆ requestverb

std::string XrdHttpReq::requestverb

Definition at line 242 of file XrdHttpReq.hh.

Referenced by parseFirstLine().

◆ resource

XrdOucString XrdHttpReq::resource

The resource specified by the request, stripped of opaque data.

Definition at line 249 of file XrdHttpReq.hh.

Referenced by XrdHttpExtReq::XrdHttpExtReq(), XrdHttpProtocol::Process(), ProcessHTTPReq(), Redir(), and reset().

◆ resourceplusopaque

XrdOucString XrdHttpReq::resourceplusopaque

The resource specified by the request, including all the opaque data.

Definition at line 253 of file XrdHttpReq.hh.

Referenced by XrdHttpExtReq::XrdHttpExtReq(), and ProcessHTTPReq().

◆ rwOpDone

unsigned int XrdHttpReq::rwOpDone

To coordinate multipart responses across multiple calls.

Definition at line 302 of file XrdHttpReq.hh.

◆ rwOpPartialDone

unsigned int XrdHttpReq::rwOpPartialDone

Definition at line 302 of file XrdHttpReq.hh.

◆ sendcontinue

bool XrdHttpReq::sendcontinue

Definition at line 270 of file XrdHttpReq.hh.

Referenced by parseLine(), ProcessHTTPReq(), and reset().

◆ stringresp

std::string XrdHttpReq::stringresp

If we want to give a string as a response, we compose it here.

Definition at line 328 of file XrdHttpReq.hh.

Referenced by reset().

◆ writtenbytes

long long XrdHttpReq::writtenbytes

In a long write, we track where we have arrived.

Definition at line 334 of file XrdHttpReq.hh.

Referenced by XrdHttpReq(), ProcessHTTPReq(), and reset().

◆ xrderrcode

XErrorCode XrdHttpReq::xrderrcode

Definition at line 309 of file XrdHttpReq.hh.

Referenced by Error(), and reset().

◆ xrdreq

ClientRequest XrdHttpReq::xrdreq

The last issued xrd request, often pending.

Definition at line 305 of file XrdHttpReq.hh.

Referenced by XrdHttpProtocol::doChksum(), XrdHttpProtocol::doStat(), Error(), XrdHttpProtocol::Process(), ProcessHTTPReq(), ReqReadV(), and reset().

◆ xrdresp

XResponseType XrdHttpReq::xrdresp

The last response data we got.

Definition at line 308 of file XrdHttpReq.hh.

Referenced by Data(), Done(), Error(), and reset().


The documentation for this class was generated from the following files: