cherokee / webserver

Cherokee Web Server
GNU General Public License v2.0
568 stars 104 forks source link

handler_fcgi.c is not handling HEAD requests properly (V. 1.2.101) #1203

Closed finnianr closed 6 years ago

finnianr commented 6 years ago

My Eiffel FastCGI client works fine for normal GET requests. For example:

finnian@MacMini ~/dev/Eiffel/myching-server $ curl -i http://localhost/en/screenshots/viewing-a-journal-page.html
HTTP/1.1 200 OK
Date: Sat, 24 Feb 2018 16:56:28 GMT
Server: Cherokee/1.2.101 (Ubuntu)
Connection: close
Content-Type: text/html; charset=UTF-8
Last-Modified: Fri, 09 Oct 2015 14:33:38 02
Content-Length: 1771

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
..

However this is what I get if send a HEAD request

finnian@MacMini ~/dev/Eiffel/myching-server $ curl --head http://localhost/en/screenshots/viewing-a-journal-page.html
HTTP/1.1 500 Internal Server Error
Connection: close
Date: Sat, 24 Feb 2018 18:31:25 GMT
Server: Cherokee/1.2.101 (Ubuntu)
Content-Length: 308
Content-Type: text/html
Cache-Control: no-cache
Pragma: no-cache

There are three things wrong with this:

  1. Cherokee reports a 500 error
  2. Cherokee has reduced the length to 308
  3. Cherokee has added 2 extra headers that were not in the original namely: Cache-Control and Pragma

This is the client code from class FCGI_SERVLET_RESPONSE that returns the response.

send
   -- send response headers and content
   local
      list: like sorted_headers
   do
      if not is_sent then
         set_content_length (content_buffer.count)
         -- NOTE: There is no need to send the HTTP status line because
         -- the FastCGI protocol does it for us.
         if status = Http_status.ok then
            set_default_headers; set_cookie_headers
         end

         list := sorted_headers
         if not is_head_request then
             -- Making linefeed conditional fixes the Cherokee broken network pipe problem
            list.extend (Carriage_return_new_line)
            list.extend (content_buffer.text)
         end
         write (list.joined_strings)

         is_sent := True
      end
   end

Is this a bug or am I missing something?

finnianr commented 6 years ago

I rolled back to an earlier FastCGI implemenation I was using and the problem went away, so the bug seems to be in my new implemenation.