<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt"><div class="" style=""><span class="" style="">Hey,</span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal" class=""><span class="" style=""><br class="" style=""></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal" class="">So when I was looking at this it seemed to me the order of the middleware stack was correct, so I wrote a quick test case:</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;
 background-color: transparent; font-style: normal" class=""><br class="" style=""></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal" class=""><a href="https://github.com/perl-catalyst/catalyst-runtime/blob/master/t/head_middleware.t" class="" style="">https://github.com/perl-catalyst/catalyst-runtime/blob/master/t/head_middleware.t</a><br class="" style=""></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal" class=""><br class="" style=""></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal" class="">and it does seem to
 me that this works as desired (if you have an action that provides a body content, but hit it with a HEAD request, then the body gets removed by the Head middleware but not before the ContentLength middleware has time to calculate the missing content length header. &nbsp;Here's the current middleware stack for the most recent release of Catalyst:</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal" class=""><br class="" style=""></div><div style="background-color: transparent" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Plack::Middleware::HTTPExceptions-&gt;new,</div><div style="background-color: transparent" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Plack::Middleware::RemoveRedundantBody-&gt;new,</div><div style="background-color: transparent" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
 Plack::Middleware::FixMissingBodyInRedirect-&gt;new,</div><div style="background-color: transparent" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Plack::Middleware::ContentLength-&gt;new,</div><div style="background-color: transparent" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Plack::Middleware::MethodOverride-&gt;new,</div><div style="background-color: transparent" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Plack::Middleware::Head-&gt;new,</div><div class="" style=""><br class="" style=""></div><div class="" style="">Middleware handles a response from the top down (and the request comes the other way, from the bottom up). &nbsp;In fact I can make my test case fail by reversing the order of the Head and ContentLength middleware, so I am sure this is the case. &nbsp;I'm adding this test case to the next release of catalyst to help and to help prevent regressions.</div><div class="" style=""><br></div><div class="" style="">jnap</div><div
 class="yahoo_quoted" style="display: block;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 12pt" class=""> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 12pt" class=""> <div dir="ltr" class="" style=""> <font size="2" face="Arial" class="" style=""> On Thursday, May 1, 2014 6:01 PM, John Napiorkowski &lt;jjn1056@yahoo.com&gt; wrote:<br class="" style=""> </font> </div>  <div class="" style=""><div id="yiv1253053918" class="" style=""><div class="" style=""><div style="color:#000;background-color:#fff;font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt" class=""><div class="" style=""><span class="" style="">Content Length auto detection was moved from Catalyst core to middleware in a recent build of Catalyst. &nbsp;Its likely that the view you are using isn't bothering to
 set the length and the middleware is failing to provide it properly since the Head middleware has already removed it.</span></div><div class="" style="color:rgb(0, 0, 0);font-size:16px;font-family:HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;background-color:transparent;font-style:normal"><span class="" style=""><br clear="none" class="" style=""></span></div><div class="" style="color:rgb(0, 0, 0);font-size:16px;font-family:HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;background-color:transparent;font-style:normal"><span class="" style="">Since the content length SHOULD be provided for the case of HEAD, could you provide a test case and lets see if shuffling the order of the registered middleware fixes this problem?</span></div><div class="" style="color:rgb(0, 0, 0);font-size:16px;font-family:HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande',
 sans-serif;background-color:transparent;font-style:normal"><span class="" style=""><br clear="none" class="" style=""></span></div><div class="" style="color:rgb(0, 0, 0);font-size:16px;font-family:HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;background-color:transparent;font-style:normal"><span class="" style="">There's a method called 'registered_middlewares' in Catalyst.pm that dictates the order. &nbsp;If you can provide me a failing test case in the repo (https://github.com/perl-catalyst/catalyst-runtime) I am sure I could fix it pretty
 quick.</span></div><div class="" style="color:rgb(0, 0, 0);font-size:16px;font-family:HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;background-color:transparent;font-style:normal"><span class="" style=""><br clear="none" class="" style=""></span></div><div class="" style="color:rgb(0, 0, 0);font-size:16px;font-family:HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;background-color:transparent;font-style:normal"><span class="" style="">Sorry for the slow response, BTW, there's also middleware for the md5</span></div><div class="" style="color:rgb(0, 0, 0);font-size:16px;font-family:HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;background-color:transparent;font-style:normal"><span class="" style=""><br clear="none" class="" style=""></span></div><div class="" style="color:rgb(0, 0, 0);font-size:16px;font-family:HelveticaNeue, 'Helvetica Neue', Helvetica,
 Arial, 'Lucida Grande', sans-serif;background-color:transparent;font-style:normal"><span class="" style=""><a rel="nofollow" shape="rect" class="" target="_blank" href="https://metacpan.org/pod/Plack::Middleware::ContentMD5" style="">Plack::Middleware::ContentMD5 - Automatically sets the Content-MD5 header on all String bodies - metacpan.org</a><br clear="none" class="" style=""></span></div><div class="" id="yiv1253053918enhancrCard_0" style="width:450px;font-family:'Georgia', 'Times', 'Times New Roman', 'serif'" contenteditable="false"><table class="" cellspacing="0" cellpadding="0" style="width:450px;height:auto;display:block"><tbody class="" style=""><tr class="" style=""><td colspan="6" rowspan="1" class="" style="height:1px;background-color:#e5e5e5"><div class="" style="height:1px;background-color:#e5e5e5"></div></td></tr><tr class="" style=""><td colspan="1" rowspan="2" class="" style="width:1px;background-color:#e5e5e5"><div class=""
 style="width:1px;background-color:#e5e5e5"></div></td><td colspan="2" rowspan="1" class="" style="width:100%;vertical-align:middle;font-family:'Georgia', 'Times', 'Times New Roman', 'serif'"><div class="" style="line-height:16.5px;background-color:#ffffff;width:448px"><div class="" style="word-wrap:break-word;padding:7px 20px 0px 14px"><span class="" style=""></span><span class="" style=""></span><a rel="nofollow" shape="rect" class="" target="_blank" href="https://metacpan.org/pod/Plack::Middleware::ContentMD5" style="text-decoration: none !important; color: #000000 !important" contenteditable="false"><span class="" style="margin:0;font-weight:normal;font-size:18px;line-height:21px;max-height:43px;color:#000000;overflow:hidden;display:inline-block">Plack::Middleware::ContentMD5 - Automatically sets the Content-MD5 header on all String bodies...</span></a><div class=""
 style="font-size:13px;line-height:20px;color:#999999;max-height:81px;font-family:'Georgia', 'Times', 'Times New Roman', 'serif';overflow:hidden">Automatically sets the Content-MD5 header on all String bodies</div></div></div></td><td colspan="1" rowspan="2" class="" style="width:1px;background-color:#e5e5e5"><div class="" style="width:1px;background-color:#e5e5e5"></div></td></tr><tr class="" style=""><td colspan="1" rowspan="1" class="" style="width:100%;vertical-align:middle;font-family:'Arial', 'Helvetica Neue', 'Helvetica', 'sans-serif'"><div class="" style="font-size:0pt;padding:3px 20px 9px 14px"><a rel="nofollow" shape="rect" class="" target="_blank" href="https://metacpan.org/pod/Plack::Middleware::ContentMD5" style="color:black;text-decoration:none;cursor:pointer"><span class="" style="display:inline-block;line-height:11px;max-width:348px;min-width:288px;overflow:hidden;max-height:13px"><span class="" style="vertical-align:middle; font-size:
 9px; line-height: 11px; color: #999999; -moz-text-size-adjust: none; -ms-text-size-adjust: none; -webkit-text-size-adjust:none; text-size-adjust:none">View on <span class="" style="font-weight:bold">metacpan.org</span></span></span></a></div></td><td colspan="1" rowspan="1" class="" style="vertical-align:middle;width:100px;font-family:'Arial', 'Helvetica Neue', 'Helvetica', 'sans-serif'"><div class="" style="padding:6px 20px 12px 0px;max-width:100px;min-width:80px;overflow:hidden;text-align:right;line-height:11px;max-height:13px;font-size:0pt"><span class="" style="vertical-align:middle; font-size: 9px; line-height: 11px; color: #999999; -moz-text-size-adjust: none; -ms-text-size-adjust: none; -webkit-text-size-adjust:none; text-size-adjust:none">Preview by Yahoo</span></div></td></tr><tr class="" style=""><td colspan="6" rowspan="1" class="" style="height:1px;background-color:#e5e5e5"><div class=""
 style="height:1px;background-color:#e5e5e5"></div></td></tr></tbody></table></div><div class="" style="color:rgb(0, 0, 0);font-size:16px;font-family:HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;background-color:transparent;font-style:normal"><br clear="none" class="" style=""></div><div class="" style="color:rgb(0, 0, 0);font-size:16px;font-family:HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;background-color:transparent;font-style:normal">I could be talked into adding that as well, although maybe not everyone wants the overhead.</div><div class="" style="color:rgb(0, 0, 0);font-size:16px;font-family:HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;background-color:transparent;font-style:normal"><br clear="none" class="" style=""></div><div class="" style="color:rgb(0, 0, 0);font-size:16px;font-family:HelveticaNeue, 'Helvetica Neue', Helvetica, Arial,
 'Lucida Grande', sans-serif;background-color:transparent;font-style:normal">Any thoughts on that? &nbsp;--jnap</div><div class="" id="yiv1253053918yqt08584" style=""><div class="" style="display:block"> <div class="" style="font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt"> <div class="" style="font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt"> <div class="" dir="ltr" style=""> <font class="" size="2" face="Arial" style=""> On Wednesday, April 23, 2014 6:50 PM, Trevor Leffler &lt;tleffler@uw.edu&gt; wrote:<br clear="none" class="" style=""> </font> </div>  <div class="" style="">I've been playing with a toy application and inspecting its responses to <br clear="none" class="" style="">various HTTP methods and noticed that Content-Length is missing from the <br clear="none" class="" style="">HEAD response.&nbsp; Both Catalyst::Action::RenderView and
 C::A::Serialize <br clear="none" class="" style="">(from the C::A::REST package) seem to take the easy way out and "return <br clear="none" class="" style="">1 if $c-&gt;req-&gt;method eq 'HEAD'".&nbsp; Does anyone with CAR history know why <br clear="none" class="" style="">this is?<br clear="none" class="" style=""><br clear="none" class="" style="">To provide message-body-based headers (content-length, last-modified, <br clear="none" class="" style="">content-md5, etc) I'm doing this:<br clear="none" class="" style=""><br clear="none" class="" style="">sub render : ActionClass('RenderView') { }<br clear="none" class="" style=""><br clear="none" class="" style="">sub end : Private {<br clear="none" class="" style="">&nbsp;  my $self = shift;<br clear="none" class="" style="">&nbsp;  my ($c) = @_;<br clear="none" class="" style=""><br clear="none" class="" style="">&nbsp;  $c-&gt;forward('render');<br clear="none" class="" style=""><br clear="none"
 class="" style="">&nbsp;  # see also Catalyst::Action::RenderView or ::Serialize<br clear="none" class="" style="">&nbsp;  if ($c-&gt;req-&gt;method eq 'HEAD') {<br clear="none" class="" style="">&nbsp; &nbsp;  my $view = $c-&gt;view<br clear="none" class="" style="">&nbsp; &nbsp; &nbsp;  || die sprintf("%s could not find a view to forward to.\n", <br clear="none" class="" style="">__PACKAGE__);<br clear="none" class="" style="">&nbsp; &nbsp;  $c-&gt;forward($view);<br clear="none" class="" style="">&nbsp;  }<br clear="none" class="" style=""><br clear="none" class="" style="">&nbsp;  #
 fun with headers, for example...<br clear="none" class="" style="">&nbsp;  # or enable P::M::ContentMD5<br clear="none" class="" style="">&nbsp;  if ($c-&gt;res-&gt;has_body) {<br clear="none" class="" style="">&nbsp; &nbsp;  my $md5 = Digest::MD5::md5_hex($c-&gt;res-&gt;body);<br clear="none" class="" style="">&nbsp; &nbsp;  $c-&gt;res-&gt;headers-&gt;header(Content-MD5 =&gt; $md5);<br clear="none" class="" style="">&nbsp;  }<br clear="none" class="" style="">}<br clear="none" class="" style=""><br clear="none" class="" style="">I've noted that while $c-&gt;res-&gt;body now has my rendered view, it gets <br clear="none" class="" style="">removed by Plack::Middleware::Head prior to returning the response, so I <br clear="none" class="" style="">don't have to worry about that detail.<br clear="none" class="" style=""><br clear="none" class="" style="">--Trevor<br clear="none" class="" style=""><br clear="none" class=""
 style="">_______________________________________________<br clear="none" class="" style="">List: <a rel="nofollow" shape="rect" class="" ymailto="mailto:Catalyst@lists.scsys.co.uk" target="_blank" href="mailto:Catalyst@lists.scsys.co.uk" style="">Catalyst@lists.scsys.co.uk</a><br clear="none" class="" style="">Listinfo: <a rel="nofollow" shape="rect" class="" target="_blank" href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst" style="">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst</a><br clear="none" class="" style="">Searchable archive: <a rel="nofollow" shape="rect" class="" target="_blank" href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/" style="">http://www.mail-archive.com/catalyst@lists.scsys.co.uk/</a><br clear="none" class="" style="">Dev site: <a rel="nofollow" shape="rect" class="" target="_blank" href="http://dev.catalyst.perl.org/" style="">http://dev.catalyst.perl.org/</a><br clear="none" class=""
 style=""><br clear="none" class="" style=""><br clear="none" class="" style=""></div>  </div> </div>  </div></div> </div></div></div><br class="" style=""><br class="" style=""></div>  </div> </div>  </div> </div></body></html>