• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What's the interest of setting CURLOPT_HEADER to true by default?

#1
Hello,

I was working for the first time with the CurlRequestClass today and found out that CURLOPT_HEADER was at true by default in CURLRequest.php. As a reminder this makes CURL set some headers in the body response which can be unhandy while working with REST API for example.

I wonder what's the main point of this and, if there's any, why isn't there any method in the library to set the curl options ourselves?  Smile
I might aswell miss something.

Thanks for your responses.
Reply

#2
Too my knowledge it's set so that we can get for example the status code back from the server. So we know it have been succeeded or denied.

Take a look at setResponseHeaders().
Reply

#3
To go further I identified the problem I was running into.

Codeigniter Curl lib uses the header sent in the body response with CURLOPT_HEADER = true to actually set the header of the Response object. However, the API I was using has a Digest Authentification and that's where the problem comes from.
To make it short, Digest Auth forces you to make a first call to get some infos from the server and a second one to get your desired data without you doing anything. This makes you with a curl response which looks like this :

Code:
HTTP/1.1 401 Unauthorized
FIRST CALL IS 401 BECAUSE I'M NOT LOGGED.
CLIENT IS GETTING INFO FROM THE SERVER.
// first headers go here

HTTP/1.1 200 OK
SECOND HTTP CALL IS OK, I PROVIDED AUTH RESOURCE
// second headers go here

MY RESULT IS HERE

Problem is from the CURLRequest lib starting at line 458

PHP Code:
// Split out our headers and body
$break strpos($output"\r\n\r\n");

if (
$break !== false)
{
    
// Our headers
    
$headers explode("\n"substr($output0$break));

    
$this->setResponseHeaders($headers);

    
// Our body
    
$body substr($output$break 4);
    
$this->response->setBody($body);


This basically go to the first double carriage return and set the first occurence to the headers and the second one to the body.
Because I'm using digest auth and having a double headers in my curl response, it set the first response as my header (which is the wrong one) and keep the good header in my body response. The lib should ignore the first header response in case of a digest auth.

I'm lucky enough to own the source code of the server I was calling so I made it to a basic auth and everything's fine.

Can someone confirm this is a bug from the lib or maybe the digest auth was not properly handled from the server side?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.