]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_fcgi.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
7 size_t RGWFCGX::write_data(const char* const buf
, const size_t len
)
9 /* According to the documentation of FCGX_PutStr if there is no error
10 * (signalised by negative return value), then always ret == len. */
11 const auto ret
= FCGX_PutStr(buf
, len
, fcgx
->out
);
13 throw rgw::io::Exception(-ret
, std::system_category());
18 size_t RGWFCGX::read_data(char* const buf
, const size_t len
)
20 const auto ret
= FCGX_GetStr(buf
, len
, fcgx
->in
);
22 throw rgw::io::Exception(-ret
, std::system_category());
30 FCGX_FFlush(fcgx
->out
);
33 void RGWFCGX::init_env(CephContext
* const cct
)
35 env
.init(cct
, (char **)fcgx
->envp
);
38 size_t RGWFCGX::send_status(const int status
, const char* const status_name
)
40 static constexpr size_t STATUS_BUF_SIZE
= 128;
42 char statusbuf
[STATUS_BUF_SIZE
];
43 const auto statuslen
= snprintf(statusbuf
, sizeof(statusbuf
),
44 "Status: %d %s\r\n", status
, status_name
);
46 return txbuf
.sputn(statusbuf
, statuslen
);
49 size_t RGWFCGX::send_100_continue()
51 const auto sent
= send_status(100, "Continue");
56 size_t RGWFCGX::send_header(const boost::string_ref
& name
,
57 const boost::string_ref
& value
)
59 static constexpr char HEADER_SEP
[] = ": ";
60 static constexpr char HEADER_END
[] = "\r\n";
64 sent
+= txbuf
.sputn(name
.data(), name
.length());
65 sent
+= txbuf
.sputn(HEADER_SEP
, sizeof(HEADER_SEP
) - 1);
66 sent
+= txbuf
.sputn(value
.data(), value
.length());
67 sent
+= txbuf
.sputn(HEADER_END
, sizeof(HEADER_END
) - 1);
72 size_t RGWFCGX::send_content_length(const uint64_t len
)
74 static constexpr size_t CONLEN_BUF_SIZE
= 128;
76 char sizebuf
[CONLEN_BUF_SIZE
];
77 const auto sizelen
= snprintf(sizebuf
, sizeof(sizebuf
),
78 "Content-Length: %" PRIu64
"\r\n", len
);
80 return txbuf
.sputn(sizebuf
, sizelen
);
83 size_t RGWFCGX::complete_header()
85 static constexpr char HEADER_END
[] = "\r\n";
86 const size_t sent
= txbuf
.sputn(HEADER_END
, sizeof(HEADER_END
) - 1);