xrootd
Loading...
Searching...
No Matches
XrdHttpReq.hh
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// This file is part of XrdHTTP: A pragmatic implementation of the
3// HTTP/WebDAV protocol for the Xrootd framework
4//
5// Copyright (c) 2013 by European Organization for Nuclear Research (CERN)
6// Author: Fabrizio Furano <furano@cern.ch>
7// File Date: Nov 2012
8//------------------------------------------------------------------------------
9// XRootD is free software: you can redistribute it and/or modify
10// it under the terms of the GNU Lesser General Public License as published by
11// the Free Software Foundation, either version 3 of the License, or
12// (at your option) any later version.
13//
14// XRootD is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public License
20// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
21//------------------------------------------------------------------------------
22
23
24
25
26
27
28
38#ifndef XRDHTTPREQ_HH
39#define XRDHTTPREQ_HH
40
41
43
47
48#include <vector>
49#include <string>
50#include <map>
51
52//#include <libxml/parser.h>
53//#include <libxml/tree.h>
54
55
56
57#define READV_MAXCHUNKS 512
58#define READV_MAXCHUNKSIZE (1024*128)
59
61 // < 0 means "not specified"
62 long long bytestart;
63 long long byteend;
64};
65
67 std::string path;
68 long long size;
69 long id;
70 long flags;
71 long modtime;
72};
73
74
75class XrdHttpProtocol;
76class XrdOucEnv;
77
79private:
80 // HTTP response parameters to be sent back to the user
82 std::string httpStatusText;
83
84 // Whether transfer encoding was requested.
88
89 // Whether trailer headers were enabled
90 bool m_trailer_headers{false};
91
92 // Whether the client understands our special status trailer.
93 // The status trailer allows us to report when an IO error occurred
94 // after a response body has started
95 bool m_status_trailer{false};
96
97 int parseContentRange(char *);
98 int parseHost(char *);
99 int parseRWOp(char *);
100
101 //xmlDocPtr xmlbody; /* the resulting document tree */
103
106
107
109
110 // Process the checksum response and return a header that should
111 // be included in the response.
112 int PostProcessChecksum(std::string &digest_header);
113
119 int PostProcessHTTPReq(bool final = false);
120
121 // Parse a resource string, typically a filename, setting the resource field and the opaque data
122 void parseResource(char *url);
123 // Map an XRootD error code to an appropriate HTTP status code and message
125
126 // Sanitize the resource from http[s]://[host]/ questionable prefix
128
134 static void extractChecksumFromList(const std::string & checksumList, std::vector<std::string> & extractedChecksum);
135
142 static void determineXRootDChecksumFromUserDigest(const std::string & userDigest, std::vector<std::string> & xrootdChecksums);
143
144public:
145 XrdHttpReq(XrdHttpProtocol *protinstance) : keepalive(true) {
146
147 prot = protinstance;
148 length = 0;
149 //xmlbody = 0;
150 depth = 0;
151 ralist = 0;
152 opaque = 0;
153 writtenbytes = 0;
154 fopened = false;
155 headerok = false;
156 };
157
158 virtual ~XrdHttpReq();
159
160 virtual void reset();
161
163 int parseLine(char *line, int len);
164
166 int parseFirstLine(char *line, int len);
167
169 int parseBody(char *body, long long len);
170
172 int ReqReadV();
174
176 std::string buildPartialHdr(long long bytestart, long long byteend, long long filesize, char *token);
177
179 std::string buildPartialHdrEnd(char *token);
180
181 // Appends the opaque info that we have
182 // NOTE: this function assumes that the strings are unquoted, and will quote them
183 void appendOpaque(XrdOucString &s, XrdSecEntity *secent, char *hash, time_t tnow);
184
185 // ----------------
186 // Description of the request. The header/body parsing
187 // is supposed to populate these fields, for fast access while
188 // processing the request
189
191
207
210 std::string requestverb;
211
212 // We have to keep the headers for possible further processing
213 // by external plugins
214 std::map<std::string, std::string> allheaders;
215
222
223
226
227
228 // This can be largely optimized...
230 std::vector<ReadWriteOp> rwOps;
233 std::vector<ReadWriteOp> rwOps_split;
234
236 long long length; // Total size from client for PUT; total length of response TO client for GET.
237 int depth;
239
241 std::string host;
243 std::string destination;
244
246 std::string m_req_digest;
247
250
256 std::string m_digest_header;
257
259 std::string hdr2cgistr;
261
262 //
263 // Area for coordinating request and responses to/from the bridge
264 //
265
266
269
272
276 std::string etext;
278
280 const struct iovec *iovP;
281 int iovN;
282 int iovL;
283 bool final;
284
285 // The latest stat info got from the xrd layer
286 long long filesize;
290 char fhandle[4];
292
294 std::string stringresp;
295
298
300 long long writtenbytes;
301
302
303
304
305
312
313
314 // ------------
315 // Items inherited from the Bridge class
316 //
317
318 //-----------------------------------------------------------------------------
344 //-----------------------------------------------------------------------------
345
346 virtual bool Data(XrdXrootd::Bridge::Context &info,
347 const
348 struct iovec *iovP,
349 int iovN,
350 int iovL,
351 bool final
352 );
353
354 //-----------------------------------------------------------------------------
364 //-----------------------------------------------------------------------------
365
366 virtual bool Done(XrdXrootd::Bridge::Context &info);
367
368
369 //-----------------------------------------------------------------------------
382 //-----------------------------------------------------------------------------
383
385 int ecode,
386 const char *etext
387 );
388
389 //-----------------------------------------------------------------------------
402 //-----------------------------------------------------------------------------
403
405 int dlen
406 );
407
408 //-----------------------------------------------------------------------------
421 //-----------------------------------------------------------------------------
422
424 int port,
425 const char *hname
426 );
427
428};
429
430
431
432void trim(std::string &str);
433
434#endif /* XRDHTTPREQ_HH */
435
XErrorCode
Definition XProtocol.hh:987
XResponseType
Definition XProtocol.hh:896
void trim(std::string &str)
Definition XrdHttpChecksum.hh:32
Definition XrdHttpProtocol.hh:77
Definition XrdHttpReq.hh:78
int reqstate
State machine to talk to the bridge.
Definition XrdHttpReq.hh:297
char fhandle[4]
Definition XrdHttpReq.hh:290
int PostProcessHTTPReq(bool final=false)
bool keepalive
Definition XrdHttpReq.hh:235
std::vector< ReadWriteOp > rwOps
The original list of multiple reads to perform.
Definition XrdHttpReq.hh:230
unsigned int rwOpPartialDone
Definition XrdHttpReq.hh:268
ReqType
These are the HTTP/DAV requests that we support.
Definition XrdHttpReq.hh:192
@ rtUnset
Definition XrdHttpReq.hh:193
@ rtMalformed
Definition XrdHttpReq.hh:195
@ rtDELETE
Definition XrdHttpReq.hh:201
@ rtOPTIONS
Definition XrdHttpReq.hh:199
@ rtMOVE
Definition XrdHttpReq.hh:204
@ rtHEAD
Definition XrdHttpReq.hh:197
@ rtGET
Definition XrdHttpReq.hh:196
@ rtPATCH
Definition XrdHttpReq.hh:200
@ rtPROPFIND
Definition XrdHttpReq.hh:202
@ rtPUT
Definition XrdHttpReq.hh:198
@ rtUnknown
Definition XrdHttpReq.hh:194
@ rtPOST
Definition XrdHttpReq.hh:205
@ rtMKCOL
Definition XrdHttpReq.hh:203
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.
std::string httpStatusText
Definition XrdHttpReq.hh:82
long long length
Definition XrdHttpReq.hh:236
std::string destination
The destination field specified in the req.
Definition XrdHttpReq.hh:243
XrdOucString resource
The resource specified by the request, stripped of opaque data.
Definition XrdHttpReq.hh:217
std::vector< ReadWriteOp > rwOps_split
Definition XrdHttpReq.hh:233
bool headerok
Tells if we have finished reading the header.
Definition XrdHttpReq.hh:225
void clientMarshallReadAheadList(int nitems)
virtual void reset()
virtual bool Redir(XrdXrootd::Bridge::Context &info, int port, const char *hname)
XrdHttpProtocol * prot
Definition XrdHttpReq.hh:102
std::string m_digest_header
The computed digest for the HTTP response header.
Definition XrdHttpReq.hh:256
std::string etext
Definition XrdHttpReq.hh:276
std::string stringresp
If we want to give a string as a response, we compose it here.
Definition XrdHttpReq.hh:294
XResponseType xrdresp
The last response data we got.
Definition XrdHttpReq.hh:274
bool m_status_trailer
Definition XrdHttpReq.hh:95
XrdHttpReq(XrdHttpProtocol *protinstance)
Definition XrdHttpReq.hh:145
std::string requestverb
Definition XrdHttpReq.hh:210
ReqType request
The request we got.
Definition XrdHttpReq.hh:209
int ProcessHTTPReq()
virtual bool Done(XrdXrootd::Bridge::Context &info)
the result context
long long writtenbytes
In a long write, we track where we have arrived.
Definition XrdHttpReq.hh:300
XrdOucEnv * opaque
The opaque data, after parsing.
Definition XrdHttpReq.hh:219
long fileflags
Definition XrdHttpReq.hh:287
int PostProcessChecksum(std::string &digest_header)
int iovL
byte count
Definition XrdHttpReq.hh:282
void sanitizeResourcePfx()
static void determineXRootDChecksumFromUserDigest(const std::string &userDigest, std::vector< std::string > &xrootdChecksums)
int depth
Definition XrdHttpReq.hh:237
virtual bool Error(XrdXrootd::Bridge::Context &info, int ecode, const char *etext)
bool fopened
Definition XrdHttpReq.hh:291
const struct iovec * iovP
The latest data chunks got from the xrd layer. These are valid only inside the callbacks!
Definition XrdHttpReq.hh:280
int parseHost(char *)
int httpStatusCode
Definition XrdHttpReq.hh:81
std::string m_req_digest
The requested digest type.
Definition XrdHttpReq.hh:246
XrdOucString resourceplusopaque
The resource specified by the request, including all the opaque data.
Definition XrdHttpReq.hh:221
long filectime
Definition XrdHttpReq.hh:289
void getfhandle()
int parseRWOp(char *)
std::string hdr2cgistr
Additional opaque info that may come from the hdr2cgi directive.
Definition XrdHttpReq.hh:259
std::string host
The host field specified in the req.
Definition XrdHttpReq.hh:241
long filemodtime
Definition XrdHttpReq.hh:288
int parseFirstLine(char *line, int len)
Parse the first line of the header.
XrdOucString redirdest
Definition XrdHttpReq.hh:277
long long m_current_chunk_size
Definition XrdHttpReq.hh:87
void parseResource(char *url)
virtual int File(XrdXrootd::Bridge::Context &info, int dlen)
int parseLine(char *line, int len)
Parse the header.
std::string buildPartialHdrEnd(char *token)
Build the closing part for a multipart response.
int ReqReadV()
Prepare the buffers for sending a readv request.
XrdHttpChecksumHandler::XrdHttpChecksumRawPtr m_req_cksum
The checksum that was ran for this request.
Definition XrdHttpReq.hh:249
bool m_transfer_encoding_chunked
Definition XrdHttpReq.hh:85
void mapXrdErrorToHttpStatus()
bool m_appended_hdr2cgistr
Definition XrdHttpReq.hh:260
void appendOpaque(XrdOucString &s, XrdSecEntity *secent, char *hash, time_t tnow)
readahead_list * ralist
Definition XrdHttpReq.hh:173
int iovN
array count
Definition XrdHttpReq.hh:281
virtual bool Data(XrdXrootd::Bridge::Context &info, const struct iovec *iovP, int iovN, int iovL, bool final)
XrdOucString m_resource_with_digest
Definition XrdHttpReq.hh:254
long long filesize
Definition XrdHttpReq.hh:286
long long m_current_chunk_offset
Definition XrdHttpReq.hh:86
static void extractChecksumFromList(const std::string &checksumList, std::vector< std::string > &extractedChecksum)
bool m_trailer_headers
Definition XrdHttpReq.hh:90
XErrorCode xrderrcode
Definition XrdHttpReq.hh:275
void clientUnMarshallReadAheadList(int nitems)
std::map< std::string, std::string > allheaders
Definition XrdHttpReq.hh:214
unsigned int rwOpDone
To coordinate multipart responses across multiple calls.
Definition XrdHttpReq.hh:268
virtual ~XrdHttpReq()
int parseContentRange(char *)
bool sendcontinue
Definition XrdHttpReq.hh:238
ClientRequest xrdreq
The last issued xrd request, often pending.
Definition XrdHttpReq.hh:271
std::string buildPartialHdr(long long bytestart, long long byteend, long long filesize, char *token)
Build a partial header for a multipart response.
Definition XrdOucEnv.hh:42
Definition XrdOucString.hh:254
Definition XrdSecEntity.hh:65
Definition XrdXrootdBridge.hh:226
Definition XrdXrootdBridge.hh:294
Definition XrdHttpReq.hh:66
long long size
Definition XrdHttpReq.hh:68
long flags
Definition XrdHttpReq.hh:70
long id
Definition XrdHttpReq.hh:69
std::string path
Definition XrdHttpReq.hh:67
long modtime
Definition XrdHttpReq.hh:71
Definition XrdHttpReq.hh:60
long long byteend
Definition XrdHttpReq.hh:63
long long bytestart
Definition XrdHttpReq.hh:62
Definition XProtocol.hh:658
Definition XProtocol.hh:843