Skip to content

Add reusable cURL request wrapper for consistent network handling #17

Description

@allamiro

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions