Using curl, http_request_get will return the response header of the FIRST request. If a requests results in one or multiple redirect this will break expected behavior as the first (instead of the last) response headers are returned. I can submit patch for this (as soon as I have one done).

Comments

gnucifer’s picture

StatusFileSize
new721 bytes

Patch submitted.

gnucifer’s picture

Status: Active » Needs review
emackn’s picture

Can you provide me a feed that does this so I can check it out?

Also, can you explain a little about what you are doing with the lines you added?
It looks like you are splitting up all the headers, and then splitting again on the last set of headers for $header_lines.

Thanks.

gnucifer’s picture

The feed is fetched from a webservice that required authentication, so can't give you give you an example. This is how the headers returned by curl looks like though.

HTTP/1.1 302 Found
Cache-Control: private
Content-Length: 195
Content-Type: text/html; charset=iso-8859-1
Location: /data/CBild/3UOQASUN/QGSBJG1J_q70_mFile_cmNone.jpg
Server: Microsoft-IIS/7.0
X-AspNet-Version: 1.1.4322
X-Powered-By: ASP.NET
Date: Thu, 22 Dec 2011 20:02:06 GMT

HTTP/1.1 200 OK
Content-Type: image/jpeg
Last-Modified: Thu, 22 Dec 2011 17:55:56 GMT
Accept-Ranges: bytes
ETag: "f81298f4d2c0cc1:0"
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Date: Thu, 22 Dec 2011 20:02:06 GMT
Content-Length: 114477

The current code will return the header for the first resonse. To fix this I split the headerblocks on the separator (two \r\n) so that only the last one is parsed and included in the response-object.

Ideally I would also like the file to be saved as basename(/data/CBild/3UOQASUN/QGSBJG1J_q70_mFile_cmNone.jpg), the location of the last redirect) instead of the original request url. But have not figured out a way to do this in a clean way.

emackn’s picture

Status: Needs review » Reviewed & tested by the community

Code works well. Were you checking the headers for some other processing that led you to this?

emackn’s picture

StatusFileSize
new937 bytes

had to re-roll the patch since the some other things have been added to dev in the last week.

emackn’s picture

Status: Reviewed & tested by the community » Patch (to be ported)
emackn’s picture

committed to 7.x-2.x

gnucifer’s picture

emackn: Yes, I was checking the headers primarily for mime-type checking etc as discussed in this issue: http://drupal.org/node/706908. I later dropped the idea of checking mime-type in headers in favor of downloading the file to perform mime-checking with fileinfo. The mime-type in the response can't be trusted anyway, so I don't see how it's usable besides giving an indication of what type of file to expect.

emackn’s picture

Nice catch by the way. ;)

dave reid’s picture

Version: 7.x-2.0-alpha4 » 6.x-1.x-dev
twistor’s picture

Assigned: gnucifer » Unassigned
Status: Patch (to be ported) » Fixed

This was committed to 6.x some time ago.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.