Hello,
There is a slight bug in drupal_http_request().
The function uses fsockopen(); in http://au.php.net/manual/en/function.fsockopen.php you read:
errno
If provided, holds the system level error number that occurred in the system-level connect() call.
If the value returned in errno is 0 and the function returned FALSE, it is an indication that the error occurred before the
connect() call. This is most likely due to a problem initializing the socket.
The second sentence is where the problem lies. If you use drupal_http_request() on a NON-EXISTING URL, it will fail - but errno will be 0 and errstr will be empty (the socked wasn't initialized). As a result, for any calling function, $result->error will be '0' (FALSE). No error!
Basically, the code needs to check the condition where fp is NULL *and* errno is 0 - in which case, it needs to create an error "artificially".
This is exactly what my patch does.
It's a 3 liner - it would be great if it were included in 6.x
Bye,
Merc.
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | 193073-drupal_http_request.patch | 1.35 KB | pol |
| #14 | 193073-drupal_http_request.patch.txt | 1.35 KB | pol |
| #11 | 193073-drupal_http_request.patch | 1.33 KB | brianV |
| #8 | 193073-8-drupal_http_request.patch | 717 bytes | pasqualle |
| #6 | 193073-6-drupal_http_request.patch | 737 bytes | pasqualle |
Comments
Comment #1
mercmobily commentedHi,
...anybody?
Merc.
Comment #2
mercmobily commentedHi,
I realise this is not a very important bug, as it doesn't affect many users. However, I do think it has _some_ importance...
Bye,
Merc.
Comment #3
mercmobily commentedHi,
I don't like raising a bug's importance.
However, this bug has been sitting here for more than 3 months now. Not a comment, nothing.
Can somebody please look at this? If an URL doesn't work, anybody calling drupal_http_request() on a non-existing URL won't be able to tell that there was a problem at all.
I don't think it's urgent. However, after 3 months, I think it has somehow *become* urgent.
Bye,
Merc.
Comment #4
drummPatches won't get much review if they are not marked as such.
This looks okay on initial inspection, but needs more spaces to match http://drupal.org/coding-standards
Patches are usually best made against the current development version and then back-ported as necessary.
Comment #5
mercmobily commentedHi,
I don't have a Drupal 7 right now.
However, the patch should be exactly the same, since the code has the same bug.
It's easy to just add the 3 lines by hand, in fact.
Please let me know if you will go forwards with this. Since it's such a tiny patch, backporting it to D6 and D5 would be grand!
Merc.
Comment #6
pasqualleComment #8
pasqualleComment #9
pasqualleComment #10
mercmobily commentedAny luck with this patch?
Comment #11
brianV commentedBumping to D8. I updated the patch a bit to match current coding standards. As $errno can be 0 if the socket is not initialized, and -0 is still 0, we assign a specific error code of -1004.
Comment #12
mikeytown2 commentedIf your looking to use this right now, I've added this patch to #1320222-1: Bring in other drupal patches. I'm expecting to commit it to httprl sometime tomorrow.
If you know of any other issues that deal with drupal_http_request() let me know!
Comment #13
xjmTagging as novice for the task of rerolling the Drupal 8.x patch on account of #22336: Move all core Drupal files under a /core folder to improve usability and upgrades.
If you need help rerolling this patch, you can come to core office hours or ask in #drupal-gitsupport on IRC.
Comment #14
polRerolled the patch.
Comment #15
xjmComment #16
xjmEr, we need to strip .txt from the filename so testbot will test it. :)
Comment #17
polOuch, my bad sorry.
Comment #18
xjmAnd setting to NR so testbot tests it. :)
Comment #19
mercmobily commentedHi,
Wow, I submitted this patch some 4 years ago... (!).
@mikeytown2: did this end up getting committed?
Merc.
Comment #20
mikeytown2 commented@mercmobily
This patch did get committed to HTTPRL
Comment #21
mercmobily commentedHi Mike,
Ah, I see. But it hasn't been included in Core yet, right?
Merc.
Comment #22
mikeytown2 commentedMoving this to D7 as D8 has guzzle now.