Stop hardcoding the HTTP protocol version
dema502 - January 11, 2008 - 10:23
| Project: | Drupal |
| Version: | 7.x-dev |
| Component: | base system |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed (maintainer needs more info) |
Description
I use drupal+apache on backend and ngnix on frontend
Nginx request apache by HTTP/1.0 but apache response HTTP/1.1 using chunked
Therefore, I have trouble displaying some pages.
My solution to the problem - run this
find includes/ | xargs grep -ilE 'header[(]'\''HTTP/1.1' | xargs perl -pi -e 's#'\''HTTP/1.1 #\$_SERVER['\''SERVER_PROTOCOL'\''].'\'' #g;'
It is replace
drupal_set_header('HTTP/1.1 503 Service Unavailable');
to
drupal_set_header($_SERVER['SERVER_PROTOCOL'].' 503 Service Unavailable');

#1
I think this is important to have, so we get away from hard coded HTTP protocol versions.
Here is a patch against today's HEAD.
Needs testing with various environments.
#2
Changing title ...
#3
Squid users also have problems with this. Its the cause of the random hex characters appearing at the top of error pages. There are several issues in the D5 queue about this already.
I don't think just using SERVER_PROTOCOL is sufficient. The page cache caches the response headers as well, so it will use the protocol version of the first user who requests the page. I see two solutions:
1. Just use HTTP/1.0 for error pages.
2. Modify the code to use the correct version on output.
While (2) is probably the best solution, it can be a bit tricky. I'm using (1) on all my D5 sites, i can live without HTTP/1.1 on error pages..
#4
Note that SERVER_PROTOCOL contains whatever protocol version the user sends.
If a client sometime in the future makes an HTTP/2.0 request to an HTTP/1.1 server, the server should not claim support for HTTP/2.0 but rather respond with HTTP/1.1.
Perhaps the third parameter for header() can be used.
#5
In Wordpress, the response is sent as either HTTP/1.0 or HTTP/1.1, depending on the request:
http://trac.wordpress.org/ticket/3886
#6
Patch #1 need to be re-rolled.
#7
New patch that eliminates the hard coded protocol.
#8
I'm not sure this is exactly what is needed.
If I read it correctly, this means that drupal_http_request will send its requests via the SERVER_PROTOCOL of the user which is requesting the page. This is not always desired. For instance, say I have a client who is accessing a page with HTTP 1.0, but on that page I have to load some data from a web service, and I want to use HTTP 1.1 to make that request. With this patch, the request goes out as 1.0
Perhaps better is to add a $conf variable for outgoing HTTP requests and use this in drupal_http_request.
Best,
Jacob
#9
drupal_http_request should stay HTTP 1.0. Here is a reroll.
#10
#11
Hi Damien,
Can you explain to me the rationale for your last statement? Defaulting to 1.0 is one thing, but I can't see any reason to hardcode it (or base outgoing request protocol versions on the incoming protocol version)
Best,
Jacob
#12
The HTTP client in drupal_http_request() is not HTTP/1.1 compliant but only supports HTTP/1.0.
For instance, HTTP/1.1 compliant clients MUST support the chunked transfer encoding, but this is not supported by drupal_http_request(). So if Drupal claims HTTP/1.1 support in the request header, the server may return something that drupal_http_request() doesn't understand.
So it is correct to hardcode the version number for outgoing requests - at least until Drupal gets support for HTTP/1.1.
#13
@c960657: thank you! I felt that our implementation was not HTTP/1.1 but I was unable to find a compelling argument.
#14
There was also an hardcoded version in install.php. Also, we are ensuring that the SERVER_PROTOCOL is sane in the new
drupal_initialize_variables().#15
The patch for install.php didn't make it for some reason.
#16
Ah! Thanks for the explanation.
Still, is there someway I can hack around it? Even if it means doing something like:
if (!defined('DRUPAL_HTTP_VERSION')) {
define('DRUPAL_HTTP_VERSION','HTTP/1.1');
}
Because I think there are cases where even though the drupal_http_client doesn't support all 1.1 features, other systems might require it but not actually require those features, and for hackers like me, there are cases.
I guess I just wonder why we would want to hardcode anything. If nothing else, a constant or a $conf var eliminates the need for someone to then hack core / replicate the function. But yeah, I get your point, it shouldn't be 1.1 by default.
Best,
Jacob
#17
@JacobSingh: drupal_http_request is a mess right now. There would be a lot of work to do on it to make it good. I don't want to cluter it more by adding a somewhat unneeded new feature.
#18
I've committed this patch to CVS HEAD. We can still discuss Jacob's case separately. Hence, I'm not marking this 'fixed' yet.
#19
That sounds like some rather exotic cases. Could you give some examples?
#20
@JacobSingh: Any comments on #19?
#21
re #19 - see: http://pajamadesign.com/2008/09/02/how-to-gzip-compression-between-drupa...
nginx does not support gzip unless it's HTTP 1.1