symphonycms/symphony-2 — Issue #972: Implications of Server API (CGI) for HTTP Response Status-Line
Author: DavidOliver
Created: 2011-12-15 01:43:08+00:00
State: open

This issue particularly concerns JIT, but I expect it may also apply to other parts of Symphony.

I set up a [hiawatha webserver](http://www.hiawatha-webserver.org/) after seeing it [recommended on the forum](http://symphony-cms.com/discuss/thread/67073/), and used FastCGI for PHP.

> This webserver runs on Linux, BSD, MacOS X and Windows. Although it can run any kind of CGI / FastCGI application, it has been optimized for usage with PHP.

Cached JIT images were not behaving properly: depending on the web browser in use, JIT-processed images would either be reloaded or not show and be broken.

Michael replied to a post I made at the forum, pointing me to JIT's image.php file and [code returning a 304 status](https://github.com/symphonycms/jit_image_manipulation/blob/master/lib/image.php#L198).

Because the server API is CGI, the Status-Line needs to be sent as

header('Status: 304 Not Modified');

instead of

header('HTTP/1.1 304 Not Modified');

However, the CGI-style of Status-Line doesn't work for my local test webserver which has PHP running via the Apache module route: mod_php5 (the most common configuration).

## Info

[Apache module vs. CGI](http://stackoverflow.com/a/2712839/513536)

[CGI 1.1 spec: Status](http://tools.ietf.org/html/rfc3875#section-6.3.3)

[PHP Header function parameters](http://php.net/manual/en/function.header.php#refsect1-function.header-parameters) - see FastCGI note

[Hugo Leisink on this issue as it occurred in DokuWiki](http://www.hiawatha-webserver.org/forum/topic/667):

> Found the bug. It's in 'http_conditionalRequest()' in the file 'inc/httputils.php'. At line 56, there is a statement 'header('HTTP/1.0 304 Not Modified');'. This is not allowed in a CGI script. If a CGI script wants to change the status code of a HTTP response, it should us the Status CGI header. It's clear that the Dokuwiki follow the Apache standards instead of the official standards. You can fix this bug by changing that line into 'header("Status: 304");'. You should consider reporting it to the Dokuwiki developers.

I don't know about the technical/historical reasons for the difference, but it seems clear that both the Apache module and CGI configurations should be accounted for by Symphony.

## Possible solution

Use [this phpinfo_array function](http://www.php.net/manual/en/function.phpinfo.php#87463) found in a comment in the PHP manual to detect the server API and send appropriate header accordingly.