Skip to content

Commit 73ff4c2

Browse files
committed
Set content type and content length.
1 parent 7895b10 commit 73ff4c2

File tree

2 files changed

+74
-3
lines changed

2 files changed

+74
-3
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
Changes with v1.0.1
33

4+
*) Set content type and content length. [Graham Leggett <minfrin@sharp.fm>]
5+
46
*) Add the option to explicitly set the base directory against which
57
wildcards are interpreted. [Graham Leggett <minfrin@sharp.fm>]
68

mod_rrd.c

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,67 @@ static int options_wadl(request_rec *r, rrd_conf *conf)
464464
return OK;
465465
}
466466

467+
static const char *lookup_content_type(const char *format)
468+
{
469+
switch(format[0]) {
470+
case 'p':
471+
case 'P':
472+
if (strcasecmp(format, "PNG") == 0) {
473+
return "image/png";
474+
}
475+
if (strcasecmp(format, "PDF") == 0) {
476+
return "application/pdf";
477+
}
478+
break;
479+
case 's':
480+
case 'S':
481+
if (strcasecmp(format, "SVG") == 0) {
482+
return "image/svg+xml";
483+
}
484+
if (strcasecmp(format, "SSV") == 0) {
485+
return "text/plain";
486+
}
487+
break;
488+
case 'e':
489+
case 'E':
490+
if (strcasecmp(format, "EPS") == 0) {
491+
return "application/eps";
492+
}
493+
break;
494+
case 'x':
495+
case 'X':
496+
if (strcasecmp(format, "XML") == 0) {
497+
return "application/xml";
498+
}
499+
if (strcasecmp(format, "XMLENUM") == 0) {
500+
return "application/xml";
501+
}
502+
break;
503+
case 'j':
504+
case 'J':
505+
if (strcasecmp(format, "JSON") == 0) {
506+
return "application/json";
507+
}
508+
if (strcasecmp(format, "JSONTIME") == 0) {
509+
return "application/json";
510+
}
511+
break;
512+
case 'c':
513+
case 'C':
514+
if (strcasecmp(format, "CSV") == 0) {
515+
return "text/csv";
516+
}
517+
break;
518+
case 't':
519+
case 'T':
520+
if (strcasecmp(format, "TSV") == 0) {
521+
return "text/tab-separated-values";
522+
}
523+
break;
524+
}
525+
return NULL;
526+
}
527+
467528
static const char *parse_rrdgraph_suffix(request_rec *r)
468529
{
469530
const char *fname = ap_strrchr_c(r->filename, '/');
@@ -478,7 +539,7 @@ static const char *parse_rrdgraph_suffix(request_rec *r)
478539
if (strcasecmp(suffix, ".png") == 0) {
479540
return "PNG";
480541
}
481-
if (strcasecmp(suffix, "pdf") == 0) {
542+
if (strcasecmp(suffix, ".pdf") == 0) {
482543
return "PDF";
483544
}
484545
break;
@@ -487,7 +548,7 @@ static const char *parse_rrdgraph_suffix(request_rec *r)
487548
if (strcasecmp(suffix, ".svg") == 0) {
488549
return "SVG";
489550
}
490-
if (strcasecmp(suffix, "ssv") == 0) {
551+
if (strcasecmp(suffix, ".ssv") == 0) {
491552
return "SSV";
492553
}
493554
break;
@@ -2211,6 +2272,7 @@ static int generate_args(request_rec *r, rrd_cmds_t *cmds, apr_array_header_t **
22112272
apr_array_header_t *args;
22122273
rrd_cmd_t *cmd;
22132274
rrd_opt_t *opt;
2275+
const char *format;
22142276
int i, num = 4, ret = OK;
22152277

22162278
rrd_conf *conf = ap_get_module_config(r->per_dir_config,
@@ -2239,14 +2301,20 @@ static int generate_args(request_rec *r, rrd_cmds_t *cmds, apr_array_header_t **
22392301
num++;
22402302
}
22412303

2304+
/* work out the format */
2305+
format = conf->format ? conf->format : parse_rrdgraph_suffix(r);
2306+
2307+
/* set the content type */
2308+
ap_set_content_type(r, lookup_content_type(format));
2309+
22422310
/* create arguments of the correct size */
22432311
args = *pargs = apr_array_make(r->pool, num, sizeof(const char *));
22442312

22452313
/* the argv array */
22462314
APR_ARRAY_PUSH(args, const char *) = "rrdgraph";
22472315
APR_ARRAY_PUSH(args, const char *) = "-";
22482316
APR_ARRAY_PUSH(args, const char *) = "--imgformat";
2249-
APR_ARRAY_PUSH(args, const char *) = conf->format ? conf->format : parse_rrdgraph_suffix(r);
2317+
APR_ARRAY_PUSH(args, const char *) = format;
22502318

22512319
/* first create the options */
22522320
for (i = 0; i < cmds->opts->nelts; ++i) {
@@ -2426,6 +2494,7 @@ static int get_rrdgraph(request_rec *r)
24262494
if (strcmp(grinfo->key, "image") == 0) {
24272495
apr_brigade_write(bb, NULL, NULL, (const char *)grinfo->value.u_blo.ptr,
24282496
grinfo->value.u_blo.size);
2497+
ap_set_content_length(r, grinfo->value.u_blo.size);
24292498
break;
24302499
}
24312500
/* skip anything else */

0 commit comments

Comments
 (0)