mirror of
https://github.com/ceph/ceph
synced 2025-02-19 00:47:49 +00:00
rgw: introduce a std::string-returning version of dump_time_header().
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
This commit is contained in:
parent
80e050b3a7
commit
e5b0e4a309
@ -464,19 +464,33 @@ void dump_redirect(struct req_state *s, const string& redirect)
|
||||
STREAM_IO(s)->print("Location: %s\r\n", redirect.c_str());
|
||||
}
|
||||
|
||||
static bool dump_time_header_impl(char (×tr)[TIME_BUF_SIZE],
|
||||
const real_time t)
|
||||
{
|
||||
const utime_t ut(t);
|
||||
time_t secs = static_cast<time_t>(ut.sec());
|
||||
|
||||
struct tm result;
|
||||
const struct tm * const tmp = gmtime_r(&secs, &result);
|
||||
if (tmp == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strftime(timestr, sizeof(timestr),
|
||||
"%a, %d %b %Y %H:%M:%S %Z", tmp) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void dump_time_header(struct req_state *s, const char *name, real_time t)
|
||||
{
|
||||
utime_t ut(t);
|
||||
time_t secs = (time_t)ut.sec();
|
||||
|
||||
char timestr[TIME_BUF_SIZE];
|
||||
struct tm result;
|
||||
struct tm *tmp = gmtime_r(&secs, &result);
|
||||
if (tmp == NULL)
|
||||
return;
|
||||
|
||||
if (strftime(timestr, sizeof(timestr), "%a, %d %b %Y %H:%M:%S %Z", tmp) == 0)
|
||||
if (! dump_time_header_impl(timestr, t)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int r = STREAM_IO(s)->print("%s: %s\r\n", name, timestr);
|
||||
if (r < 0) {
|
||||
@ -484,6 +498,15 @@ void dump_time_header(struct req_state *s, const char *name, real_time t)
|
||||
}
|
||||
}
|
||||
|
||||
std::string dump_time_to_str(const real_time& t)
|
||||
{
|
||||
char timestr[TIME_BUF_SIZE];
|
||||
dump_time_header_impl(timestr, t);
|
||||
|
||||
return timestr;
|
||||
}
|
||||
|
||||
|
||||
void dump_last_modified(struct req_state *s, real_time t)
|
||||
{
|
||||
dump_time_header(s, "Last-Modified", t);
|
||||
|
@ -543,6 +543,7 @@ extern void dump_range(struct req_state* s, uint64_t ofs, uint64_t end,
|
||||
extern void dump_continue(struct req_state *s);
|
||||
extern void list_all_buckets_end(struct req_state *s);
|
||||
extern void dump_time(struct req_state *s, const char *name, real_time *t);
|
||||
extern std::string dump_time_to_str(const real_time& t);
|
||||
extern void dump_bucket_from_state(struct req_state *s);
|
||||
extern void dump_uri_from_state(struct req_state *s);
|
||||
extern void dump_redirect(struct req_state *s, const string& redirect);
|
||||
|
Loading…
Reference in New Issue
Block a user