// ----------------------------------------------------------------------------
-// RRDR options
+// RRDR dimension options
#define RRDR_EMPTY 0x01 // the dimension contains / the value is empty (null)
#define RRDR_RESET 0x02 // the dimension contains / the value is reset
#define RRDR_HIDDEN 0x04 // the dimension contains / the value is hidden
#define RRDR_NONZERO 0x08 // the dimension contains / the value is non-zero
+// RRDR result options
+#define RRDR_RESULT_OPTION_ABSOLUTE 0x00000001
+#define RRDR_RESULT_OPTION_RELATIVE 0x00000002
typedef struct rrdresult {
RRDSET *st; // the chart this result refers to
+ uint32_t result_options; // RRDR_RESULT_OPTION_*
+
int d; // the number of dimensions
long n; // the number of values in the arrays
long rows; // the number of rows used
RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int group_method)
{
int debug = st->debug;
+ int absolute_period_requested = -1;
time_t first_entry_t = rrdset_first_entry_t(st);
time_t last_entry_t = rrdset_last_entry_t(st);
if(before == 0 && after == 0) {
before = last_entry_t;
after = first_entry_t;
+ absolute_period_requested = 0;
}
// allow relative for before and after
- if(before <= st->update_every * st->entries)
+ if(before <= st->update_every * st->entries) {
before = last_entry_t + before;
+ absolute_period_requested = 0;
+ }
- if(after <= st->update_every * st->entries)
+ if(after <= st->update_every * st->entries) {
after = last_entry_t + after;
+ absolute_period_requested = 0;
+ }
+
+ if(absolute_period_requested == -1)
+ absolute_period_requested = 1;
// make sure they are within our timeframe
if(before > last_entry_t) before = last_entry_t;
return r;
}
+ if(absolute_period_requested == 1)
+ r->result_options |= RRDR_RESULT_OPTION_ABSOLUTE;
+ else
+ r->result_options |= RRDR_RESULT_OPTION_RELATIVE;
+
// find how many dimensions we have
long dimensions = r->d;
return 500;
}
+ if(r->result_options & RRDR_RESULT_OPTION_RELATIVE)
+ wb->options |= WB_CONTENT_NO_CACHEABLE;
+ else if(r->result_options & RRDR_RESULT_OPTION_ABSOLUTE)
+ wb->options |= WB_CONTENT_CACHEABLE;
+
options = rrdr_check_options(r, options, (dimensions)?buffer_tostring(dimensions):NULL);
if(dimensions)
"Access-Control-Allow-Origin: *\r\n"
"Access-Control-Allow-Methods: GET, OPTIONS\r\n"
"Access-Control-Allow-Headers: accept, x-requested-with\r\n"
+ "Access-Control-Max-Age: 86400\r\n"
"Date: %s\r\n"
, code, code_msg
, w->keepalive?"keep-alive":"close"
if(buffer_strlen(w->response.header))
buffer_strcat(w->response.header_output, buffer_tostring(w->response.header));
- if(w->mode == WEB_CLIENT_MODE_NORMAL) {
+ if(w->mode == WEB_CLIENT_MODE_NORMAL && (w->response.data->options & WB_CONTENT_NO_CACHEABLE)) {
buffer_sprintf(w->response.header_output,
"Expires: %s\r\n"
"Cache-Control: no-cache\r\n"
- "Access-Control-Max-Age: 0\r\n"
, date);
}
else {
- buffer_strcat(w->response.header_output, "Cache-Control: public\r\n");
- buffer_strcat(w->response.header_output, "Access-Control-Max-Age: 3600\r\n");
+ char edate[100];
+ time_t et = w->response.data->date + 86400;
+ struct tm etmbuf, *etm = gmtime_r(&et, &etmbuf);
+ strftime(edate, sizeof(edate), "%a, %d %b %Y %H:%M:%S %Z", etm);
+
+ buffer_sprintf(w->response.header_output,
+ "Expires: %s\r\n"
+ "Cache-Control: public\r\n"
+ , edate);
}
// if we know the content length, put it