Subject: | JSON::RPC::Server::CGI should be using CGI.pm to send headers |
Right now JSON::RPC::Server::CGI uses CGI.pm to do all sorts of stuff
about processing the request, but it doesn't use it to send back headers.
Using CGI.pm to send back headers allows it to work in different sorts of
situations, including situations (like mine) where we've overridden
$self->cgi to our own CGI.pm subclass, and it creates headers
differently.
Attached is a patch that does this.
Subject: | json-rpc-cgi.diff |
--- CGI.pm.old 2010-03-19 22:59:03.000000000 -0700
+++ CGI.pm 2010-03-19 23:00:00.000000000 -0700
@@ -54,11 +54,20 @@
sub response {
my ($self, $response) = @_;
- print "Status: " . $response->code . "\015\012" . $response->headers_as_string("\015\012")
- . "\015\012" . $response->content;
+ my $headers = $response->headers;
+ my @header_args;
+ foreach my $name ($headers->header_field_names) {
+ my @values = $headers->header($name);
+ $name =~ s/-/_/g;
+ foreach my $value (@values) {
+ push(@header_args, "-$name", $value);
+ }
+ }
+ my $cgi = $self->cgi;
+ print $cgi->header(-status => $response->code, @header_args);
+ print $response->content;
}
-
sub cgi {
$_[0]->{cgi} ||= new CGI;
}