Summary
Create a reusable cURL request wrapper so all HTTP requests use the same setup, proxy handling, timeout configuration, SSL verification, error handling, and response validation.
Problem
The current code may require repeated cURL logic in multiple places, including:
curl_init()
curl_setopt()
- proxy configuration
curl_exec()
- cURL error checks
- HTTP status checks
curl_close()
This increases duplication and makes it harder to maintain consistent behavior across the application.
Proposed improvement
Add a reusable function, for example:
curlRequest(string $url): string
The function should handle the complete request lifecycle:
- validate the requested URL
- initialize cURL
- apply common cURL options
- apply proxy settings if configured
- execute the request
- detect cURL failures
- detect HTTP response errors
- close the cURL handle safely
- return the response body
Acceptance criteria
-
Add a reusable cURL request helper.
-
Use shared timeout settings for all requests.
-
Apply proxy settings through the existing proxy helper.
-
Enable SSL verification by default.
-
Return the response body on success.
-
Provide clear errors for:
- invalid URL
- missing cURL extension
- failed cURL initialization
- cURL execution failure
- HTTP status code
>= 400
-
Ensure curl_close() is always called after execution.
-
Replace duplicated cURL request code with the new wrapper where applicable.
Goal
This issue should make future network-related changes easier because timeout rules, proxy behavior, SSL settings, and error handling will be managed in one place instead of repeated across the codebase.
Summary
Create a reusable cURL request wrapper so all HTTP requests use the same setup, proxy handling, timeout configuration, SSL verification, error handling, and response validation.
Problem
The current code may require repeated cURL logic in multiple places, including:
curl_init()curl_setopt()curl_exec()curl_close()This increases duplication and makes it harder to maintain consistent behavior across the application.
Proposed improvement
Add a reusable function, for example:
The function should handle the complete request lifecycle:
Acceptance criteria
Add a reusable cURL request helper.
Use shared timeout settings for all requests.
Apply proxy settings through the existing proxy helper.
Enable SSL verification by default.
Return the response body on success.
Provide clear errors for:
>= 400Ensure
curl_close()is always called after execution.Replace duplicated cURL request code with the new wrapper where applicable.
Goal
This issue should make future network-related changes easier because timeout rules, proxy behavior, SSL settings, and error handling will be managed in one place instead of repeated across the codebase.