I've been playing with a toy application and inspecting its responses to various HTTP methods and noticed that Content-Length is missing from the HEAD response. Both Catalyst::Action::RenderView and C::A::Serialize (from the C::A::REST package) seem to take the easy way out and "return 1 if $c->req->method eq 'HEAD'". Does anyone with CAR history know why this is?

To provide message-body-based headers (content-length, last-modified, content-md5, etc) I'm doing this:

sub render : ActionClass('RenderView') { }

sub end : Private {
  my $self = shift;
  my ($c) = @_;

  $c->forward('render');

  # see also Catalyst::Action::RenderView or ::Serialize
  if ($c->req->method eq 'HEAD') {
    my $view = $c->view
|| die sprintf("%s could not find a view to forward to.\n", __PACKAGE__);
    $c->forward($view);
  }

  # fun with headers, for example...
  # or enable P::M::ContentMD5
  if ($c->res->has_body) {
    my $md5 = Digest::MD5::md5_hex($c->res->body);
    $c->res->headers->header(Content-MD5 => $md5);
  }
}

I've noted that while $c->res->body now has my rendered view, it gets removed by Plack::Middleware::Head prior to returning the response, so I don't have to worry about that detail.

--Trevor

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

Reply via email to