RSS for Andrew Cairns

Error: Header size too large. Phil Sturgeon’s cURL Library

When inheriting an app utilising an old version of Phil Sturgeon’s REST Implementation for CodeIgniter, I uncovered a bug with a strange error – “Request header is too large” in my Apache log!

Since CodeIgniter stores loaded resources within the singleton super object, reusing classes require a small amount of garbage collection. While debugging the requests I found that the $headers member array wasn’t being cleared between requests. At the time, I wasn’t aware Phil had fixed the issue, so I started to dignose the symptoms.

Headers usually communicate information about the requesting client. This can be common things like encoding or cache-control, however some platforms may require additional headers to be set for things such as auth tokens. If your app does a large number of requests with headers, you may find a build up can quickly exceed some of Apache’s default limits.

Apache directive LimitRequestFields is set to 100 by default and limits the number of headers that can be present within a request. LimitRequestFieldsize limits the field size of a header. The LimitRequestLine directive limits the length of the request-line which includes the HTTP method, URI and the protocol version.

The fix is really simple. Either update to Phil’s newest version or open up Curl.php, scroll down to the execute() method and find both occurrences of :

curl_close($this->session);
$this->session = NULL;

After clearing the session, clear the headers array:

curl_close($this->session);
$this->session = NULL;
$this->headers = array();

The headers passed with each request should now be cleared.

I have since updated the app and have found Phil’s REST implementation to be quite solid. If anyone is making HTTP requests with CodeIgniter and has yet to check out Phil’s cURL library, I suggest they take a look.

Phil regularly maintains his public code and is very active on Twitter (@philsturgeon). Should you need to ask him a question, I’m sure he can point you in the right direction!

Leave a Response

*