Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F803850
D278.id1081.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Feb 26, 8:59 AM
Size
2 KB
Mime Type
text/x-diff
Expires
Thu, Feb 27, 8:59 AM (10 h, 32 m)
Engine
blob
Format
Raw Data
Handle
576573
Attached To
D278: INP-1653 - Emulate "CURLINFO_REDIRECT_URL" option in "kCurlHelper" class
D278.id1081.diff
View Options
Index: core/units/helpers/curl_helper.php
===================================================================
--- core/units/helpers/curl_helper.php
+++ core/units/helpers/curl_helper.php
@@ -148,6 +148,11 @@
parent::__construct();
$this->debugMode = kUtil::constOn('DBG_CURL');
+
+ // Happens, when cURL binding version is below v7.18.2.
+ if ( !defined('CURLINFO_REDIRECT_URL') ) {
+ define('CURLINFO_REDIRECT_URL', 1048607);
+ }
}
/**
@@ -494,6 +499,20 @@
return $this->lastRedirectCount;
}
+ if ( $info_type == CURLINFO_REDIRECT_URL ) {
+ if ( $this->followLocation ) {
+ return '';
+ }
+
+ foreach ( $this->responseHeaders as $header ) {
+ if ( preg_match('/^location: (.*)$/i', $header, $matches) ) {
+ return $matches[1];
+ }
+ }
+
+ return '';
+ }
+
return curl_getinfo($this->connectionID, $info_type);
}
@@ -570,4 +589,4 @@
return ($this->lastHTTPCode == 200) || ($this->lastHTTPCode >= 300 && $this->lastHTTPCode < 310);
}
- }
\ No newline at end of file
+ }
Index: index.php
===================================================================
--- index.php
+++ index.php
@@ -19,7 +19,24 @@
$application =& kApplication::Instance();
$application->Init();
-$application->Run();
+
+/** @var kCurlHelper $curl_helper */
+$curl_helper = $application->recallObject('CurlHelper');
+
+
+$curl_helper->followLocation = false;
+$curl_helper->Send('http://www.google.com', false);
+echo 'Redirect URL (not following): [' . $curl_helper->getInfo(CURLINFO_REDIRECT_URL) . ']' . PHP_EOL;
+echo 'Effective URL (not following): [' . $curl_helper->getInfo(CURLINFO_EFFECTIVE_URL) . ']' . PHP_EOL;
+$curl_helper->CloseConnection();
+
+$curl_helper->followLocation = true;
+$curl_helper->Send('http://www.google.com', false);
+echo 'Redirect URL (following): [' . $curl_helper->getInfo(CURLINFO_REDIRECT_URL) . ']' . PHP_EOL;
+echo 'Effective URL (following): [' . $curl_helper->getInfo(CURLINFO_EFFECTIVE_URL) . ']' . PHP_EOL;
+$curl_helper->CloseConnection();
+
+// $application->Run();
$application->Done();
-$end = microtime(true);
\ No newline at end of file
+$end = microtime(true);
Event Timeline
Log In to Comment