-
Notifications
You must be signed in to change notification settings - Fork 149
/
XrdHttpExtHandler.cc
114 lines (91 loc) · 3.63 KB
/
XrdHttpExtHandler.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//------------------------------------------------------------------------------
// This file is part of XrdHTTP: A pragmatic implementation of the
// HTTP/WebDAV protocol for the Xrootd framework
//
// Copyright (c) 2017 by European Organization for Nuclear Research (CERN)
// Author: Fabrizio Furano <furano@cern.ch>
// File Date: May 2017
//------------------------------------------------------------------------------
// XRootD is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// XRootD is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
//------------------------------------------------------------------------------
#include "Xrd/XrdLink.hh"
#include "XrdHttpExtHandler.hh"
#include "XrdHttpReq.hh"
#include "XrdHttpProtocol.hh"
#include "XrdOuc/XrdOucEnv.hh"
/// Sends a basic response. If the length is < 0 then it is calculated internally
int XrdHttpExtReq::SendSimpleResp(int code, const char* desc, const char* header_to_add, const char* body, long long int bodylen)
{
if (!prot) return -1;
// @FIXME
// - need this to circumvent missing API calls and keep ABI compatibility
// - when large files are returned we cannot return them in a single buffer
// @TODO: for XRootD 5.0 this two hidden calls should just be added to the external handler API and the code here can be removed
if ( code == 0 ) {
return prot->StartSimpleResp(200, desc, header_to_add, bodylen, true);
}
if ( code == 1 ) {
return prot->SendData(body, bodylen);
}
return prot->SendSimpleResp(code, desc, header_to_add, body, bodylen, true);
}
int XrdHttpExtReq::StartChunkedResp(int code, const char *desc, const char *header_to_add)
{
if (!prot) return -1;
return prot->StartChunkedResp(code, desc, header_to_add, true);
}
int XrdHttpExtReq::ChunkResp(const char *body, long long bodylen)
{
if (!prot) return -1;
return prot->ChunkResp(body, bodylen);
}
int XrdHttpExtReq::BuffgetData(int blen, char **data, bool wait) {
if (!prot) return -1;
int nb = prot->BuffgetData(blen, data, wait);
return nb;
}
void XrdHttpExtReq::GetClientID(std::string &clid)
{
char buff[512];
prot->Link->Client(buff, sizeof(buff));
clid = buff;
}
const XrdSecEntity &XrdHttpExtReq::GetSecEntity() const
{
return prot->SecEntity;
}
XrdHttpExtReq::XrdHttpExtReq(XrdHttpReq *req, XrdHttpProtocol *pr): prot(pr),
verb(req->requestverb), headers(req->allheaders) {
// Here we fill the request summary with all the fields we can
resource = req->resource.c_str();
int envlen = 0;
headers["xrd-http-query"] = req->opaque?req->opaque->Env(envlen):"";
const char * resourcePlusOpaque = req->resourceplusopaque.c_str();
headers["xrd-http-fullresource"] = resourcePlusOpaque != nullptr ? resourcePlusOpaque:"";
headers["xrd-http-prot"] = prot->isHTTPS()?"https":"http";
// These fields usually identify the client that connected
if (prot->SecEntity.moninfo) {
clientdn = prot->SecEntity.moninfo;
trim(clientdn);
}
if (prot->SecEntity.host) {
clienthost = prot->SecEntity.host;
trim(clienthost);
}
if (prot->SecEntity.vorg) {
clientgroups = prot->SecEntity.vorg;
trim(clientgroups);
}
length = req->length;
}