fix(http): drop deprecated curl_close calls; resolve Proxy destination lazily
PHP 8.5 deprecates curl_close() (no-op since 8.0) and Libs\Proxy fataled on class load because SOURCE_URL was evaluated in a static property initializer. Stamps http with per-component core data for load-verified clients (aria2, proxy, compreFace).
This commit is contained in:
@@ -2,16 +2,52 @@
|
|||||||
"name": "http",
|
"name": "http",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Utilidades HTTP (CurlRequest, Aria2, Proxy, CompreFace)",
|
"description": "Utilidades HTTP (CurlRequest, Aria2, Proxy, CompreFace)",
|
||||||
"core": { "requires": ">=0.1", "tested": "0.1" },
|
"core": {
|
||||||
|
"requires": ">=0.1",
|
||||||
|
"tested": "0.1"
|
||||||
|
},
|
||||||
"php": ">=8.1",
|
"php": ">=8.1",
|
||||||
"components": {
|
"components": {
|
||||||
"curlRequest": { "files": ["src/Libs/CurlRequest.php"] },
|
"curlRequest": {
|
||||||
"aria2": { "files": ["src/Libs/Aria2.php"] },
|
"files": [
|
||||||
"proxy": { "files": ["src/Libs/Proxy.php"] },
|
"src/Libs/CurlRequest.php"
|
||||||
"compreFace": {
|
]
|
||||||
"files": ["src/Libs/CompreFace.php"],
|
},
|
||||||
"require": { "http:curlRequest": ">=0.1" }
|
"aria2": {
|
||||||
|
"files": [
|
||||||
|
"src/Libs/Aria2.php"
|
||||||
|
],
|
||||||
|
"core": {
|
||||||
|
"requires": ">=0.1",
|
||||||
|
"tested": "0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"default": ["curlRequest", "aria2", "proxy", "compreFace"]
|
"proxy": {
|
||||||
|
"files": [
|
||||||
|
"src/Libs/Proxy.php"
|
||||||
|
],
|
||||||
|
"core": {
|
||||||
|
"requires": ">=0.1",
|
||||||
|
"tested": "0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"compreFace": {
|
||||||
|
"files": [
|
||||||
|
"src/Libs/CompreFace.php"
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"http:curlRequest": ">=0.1"
|
||||||
|
},
|
||||||
|
"core": {
|
||||||
|
"requires": ">=0.1",
|
||||||
|
"tested": "0.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default": [
|
||||||
|
"curlRequest",
|
||||||
|
"aria2",
|
||||||
|
"proxy",
|
||||||
|
"compreFace"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,16 +40,6 @@ class Aria2
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Destructor
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __destruct()
|
|
||||||
{
|
|
||||||
curl_close($this->ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows starting a batch call.
|
* Allows starting a batch call.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -52,10 +52,6 @@ class CurlRequest
|
|||||||
$this->responseBody = curl_exec($handler);
|
$this->responseBody = curl_exec($handler);
|
||||||
$this->responseHeaders = curl_getinfo($handler, CURLINFO_HEADER_OUT);
|
$this->responseHeaders = curl_getinfo($handler, CURLINFO_HEADER_OUT);
|
||||||
$this->statusCode = curl_getinfo($handler, CURLINFO_HTTP_CODE);
|
$this->statusCode = curl_getinfo($handler, CURLINFO_HTTP_CODE);
|
||||||
|
|
||||||
// throw new Exception('Error al realizar la solicitud. '. curl_error($handler));
|
|
||||||
|
|
||||||
curl_close($handler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -22,9 +22,25 @@ class Proxy
|
|||||||
'Location',
|
'Location',
|
||||||
];
|
];
|
||||||
public static $proxy_base_url_canonical = '/';
|
public static $proxy_base_url_canonical = '/';
|
||||||
public static $destination_host = SOURCE_URL;
|
public static ?string $destination_host = null;
|
||||||
protected static $filters = [];
|
protected static $filters = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Host destino efectivo: el asignado explicitamente o la constante
|
||||||
|
* SOURCE_URL del proyecto si existe. Se resuelve tarde para que la
|
||||||
|
* simple carga de la clase no falle sin configuracion.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected static function destinationHost(): string
|
||||||
|
{
|
||||||
|
if (static::$destination_host !== null) {
|
||||||
|
return static::$destination_host;
|
||||||
|
}
|
||||||
|
|
||||||
|
return defined('SOURCE_URL') ? (string) SOURCE_URL : '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a callable (AKA filter) that will receive the content
|
* Adds a callable (AKA filter) that will receive the content
|
||||||
* and should return a string.
|
* and should return a string.
|
||||||
@@ -76,7 +92,7 @@ class Proxy
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate the final URL
|
// Generate the final URL
|
||||||
$proxy_request_url = static::$destination_host . $proxy_request_uri;
|
$proxy_request_url = static::destinationHost() . $proxy_request_uri;
|
||||||
|
|
||||||
// cURL initialization
|
// cURL initialization
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
@@ -121,11 +137,10 @@ class Proxy
|
|||||||
|
|
||||||
// Execute the request
|
// Execute the request
|
||||||
$res = curl_exec($ch);
|
$res = curl_exec($ch);
|
||||||
curl_close($ch);
|
|
||||||
|
|
||||||
// Parse the response
|
// Parse the response
|
||||||
list($headers, $body) = explode("\r\n\r\n", $res, 2);
|
list($headers, $body) = explode("\r\n\r\n", $res, 2);
|
||||||
$headers = str_replace(static::$destination_host, '/', $headers);
|
$headers = str_replace(static::destinationHost(), '/', $headers);
|
||||||
|
|
||||||
$headers = explode("\r\n", $headers);
|
$headers = explode("\r\n", $headers);
|
||||||
$hs = [];
|
$hs = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user