Skip to content

Commit 2e963e2

Browse files
committed
Allow http() to have the content type forceably set - paving the way to deliver XML files
1 parent 8f81877 commit 2e963e2

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

lib/VWF/Display.pm

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ sub get_template_path
350350
return $filename;
351351
}
352352

353+
# Sets cookie values in the object.
354+
# Takes either a hash reference or a list of key-value pairs as input.
355+
# Iterates over the CGI parameters and stores them in the object's _cookies hash.
356+
# Returns the object itself, allowing for method chaining.
353357
sub set_cookie
354358
{
355359
my $self = shift;
@@ -364,6 +368,7 @@ sub set_cookie
364368
sub http
365369
{
366370
my $self = shift;
371+
my %params = (ref($_[0]) eq 'HASH') ? %{$_[0]} : @_;
367372

368373
# Handle session cookies
369374
# TODO: Only session cookies as the moment
@@ -378,14 +383,19 @@ sub http
378383
# TODO: Change the headers, e.g. character set, based on the language
379384
# my $language = $self->{_lingua} ? $self->{_lingua}->language() : 'English';
380385

381-
# Determine content type
382-
my $filename = $self->get_template_path();
383386
my $rc;
384-
if ($filename =~ /\.txt$/) {
385-
$rc = "Content-Type: text/plain\n";
387+
if($params{'Content-Type'}) {
388+
# Allow the content type to be forceably set
389+
$rc = $params{'Content-Type'} . "\n";
386390
} else {
387-
binmode(STDOUT, ':utf8');
388-
$rc = "Content-Type: text/html; charset=UTF-8\n";
391+
# Determine content type
392+
my $filename = $self->get_template_path();
393+
if ($filename =~ /\.txt$/) {
394+
$rc = "Content-Type: text/plain\n";
395+
} else {
396+
binmode(STDOUT, ':utf8');
397+
$rc = "Content-Type: text/html; charset=UTF-8\n";
398+
}
389399
}
390400

391401
# Security headers

0 commit comments

Comments
 (0)