The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. December 05, 2008, 11:01:55 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: A few questions for all you Curl Pros!  (Read 254 times)
DangerMouse
Expert
****
Offline Offline

Posts: 174



View Profile
« on: August 06, 2008, 02:35:47 AM »

Hey all,

I know there are a few cURL gurus out there on these boards, and was hoping for a little help with a few questions. I'm looking to basically strip down cURL so that it does very few things exept send reuqests and recieve responses. Whilst this may sound strange it's because I want the full control that a solution like Perk's Webrequest Class provides, but I want access to some specific cURL functionality - namely NTLM proxy authentication.

So basically I'm trying to achieve the following:

- Set all headers being used in the request manually - I'm guessing that simply passing a full header array to CURLOPT_HTTPHEADER should achieve this? Are there any nuances I should be aware of?

- Handle cookies manually - I'm hoping that by setting cookies in the HTTP Headers I won't have to bother dealing with the cURL cookie options? This relates to my next point in terms of getting the cookies that are set.

- Get access to a complete raw response for parsing. I'm hoping to just get cURL to return the entire HTTP response, so I can then parse out the return headers, body etc myself. This is the major one that I don't really have a clue how to achieve, and I'm concerned that cURL will try to be helpful and modify what I actually get back.

Any tips here, much apprecaited.

Cheers,

DM
Logged
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Online Online

Posts: 636



View Profile
« Reply #1 on: August 06, 2008, 05:27:20 AM »

The only gotchas to handling headers is that some web servers are a little weird, like Lighttpd. cURL balks on Continue: headers from Lighttpd.

You will need to define a headerfunc() for use in your cURL class/function/whatever. Then you use curl_setopt($ch, CURLOPT_HEADERFUNC, myHeaderFunc());

You will have to process *everything* a browser does in the headerfunc, including Location: directives, cookies, etc.

None of that is that hard, though.
Logged

DangerMouse
Expert
****
Offline Offline

Posts: 174



View Profile
« Reply #2 on: August 06, 2008, 06:01:34 AM »

The only gotchas to handling headers is that some web servers are a little weird, like Lighttpd. cURL balks on Continue: headers from Lighttpd.

Is this where a 100 or 101 response code is returned? What's the correct way to handle this? Is CURLOPT_HTTP200ALIASES useful here?

You will need to define a headerfunc() for use in your cURL class/function/whatever. Then you use curl_setopt($ch, CURLOPT_HEADERFUNC, myHeaderFunc());

You will have to process *everything* a browser does in the headerfunc, including Location: directives, cookies, etc.

None of that is that hard, though.

I don't mind processing everything, - if I used CURLOPT_RETURNTRANSFER 1, CURLOPT_HEADER 1 and CURLOPT_BINARYTRANSFER 1 will this be the equivilant of a raw server response? Or is this where HEADERFUNC is better? i.e. it guarantees getting everything. Does the string thats passed to HEADERFUNC include the "body" of the server response? How does this work with complicated things like chunked stuff, or funny encodings?

Thanks for the ideas!

Steve
Logged
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Online Online

Posts: 636



View Profile
« Reply #3 on: August 06, 2008, 06:26:57 AM »

The string passed to headerfunc() will include the headers. That's it. The body will still be returned to you normally at execution, provided you have CURLOPT_RETURNTRANSFER set.
Logged

Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!