8000
Skip to content

Replace custom HTTP client with libcurl#2035

Draft
Copilot wants to merge 5 commits intomasterfrom
copilot/replace-http-client-library
Draft

Replace custom HTTP client with libcurl#2035
Copilot wants to merge 5 commits intomasterfrom
copilot/replace-http-client-library

Conversation

Copy link
Copy Markdown
Contributor
Copilot AI commented Jan 4, 2026

The custom HTTP client implementation (~2100 lines of C) handles socket connections, SSL/TLS, chunked encoding, redirects, and RTSP protocol manually. This creates significant maintenance burden and bug risk. Replace with libcurl.

Changes

  • Build system: libcurl is now a mandatory dependency

    • configure: Added libcurl detection, removed optional flag
    • Makefile: Unconditionally link libcurl
  • HTTP client rewrite (src/httpc.c):

    • Replaced custom socket/SSL implementation with libcurl easy interface
    • Maintained existing API: http_client_connect, http_client_send, http_client_run, callbacks
    • RTSP support via CURLOPT_RTSP_REQUEST
    • SSL peer verification via CURLOPT_SSL_VERIFYPEER
  • Header cleanup (src/http.h):

    • Removed hc_ssl field (no longer needed)
    • Added hc_curl and hc_curl_headers for libcurl handles
    • Removed ENABLE_CURL conditionals

API preserved

// All existing usage continues to work
http_client_t *hc = http_client_connect(aux, HTTP_VERSION_1_1, "https", host, 443, NULL);
hc->hc_handle_location = 1;
hc->hc_data_complete = my_callback;
http_client_ssl_peer_verify(hc, 1);
http_client_simple(hc, &url);
http_client_run(hc);

Result

~1200 fewer lines of code. Delegates socket management, SSL/TLS, redirect handling, and HTTP parsing to a well-tested library.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 239.255.255.250
    • Triggering command: REDACTED, pid is -1 (packet block)
  • my.pcloud.com
    • Triggering command: /usr/bin/python /usr/bin/python /home/REDACTED/work/tvheadend/tvheadend/support/pcloud.py publink_download kZ54ee7ZUvsSYmb9VGSpnmoVzcAUhpBXLq8k misc/staticlib/Ubuntu 24.04/x86_64/ffmpeg-45c8a20913aaa75ddec13f3d89c0ce4049850075.tgz /home/REDACTED/work/tvheadend/tvheadend/build.linux/.ffmpeg-45c8a20913aaa75ddec13f3d89c0ce4049850075.tgz.tmp -I adend gnu -D_REENTRANcat .0/include -I adend/build.linux -I in.so /lto-wrapper adend gnu -D_REENTRANtr linux-gnu/dbus-1abcdefghijklmnopqrstuvwxyz -I k/tvheadend/tvheadend/build.linu-o (dns block)
    • Triggering command: /usr/bin/python3 python3 /home/REDACTED/work/tvheadend/tvheadend/support/pcloud.py publink_download kZ54ee7ZUvsSYmb9VGSpnmoVzcAUhpBXLq8k misc/staticlib/Ubuntu 24.04/x86_64/ffmpeg-45c8a20913aaa75ddec13f3d89c0ce4049850075.tgz /home/REDACTED/work/tvheadend/tvheadend/build.linux/.ffmpeg-45c8a20913aaa75ddec13f3d89c0ce4049850075.tgz.tmp -I adend -I .0/include -I adend/build.linux -I adend/src -I ndor/bin/git -I linux-gnu/dbus-1.0/include -I k/tvheadend/tvheadend/build.linux (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Replace the custom http client with an appropriate library in order to reduce the risk of bugs and reduce the maintenance burden


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Jan 4, 2026
- Add libcurl option to configure script (auto-detected)
- Create httpc_curl.c as alternative HTTP client using libcurl
- Update Makefile to conditionally use httpc_curl.c when libcurl is enabled
- Add ENABLE_CURL conditional fields to http_client struct in http.h
- Maintain full API compatibility with existing code
- Original httpc.c is used as fallback when libcurl is not available

Co-authored-by: Flole998 <9951871+Flole998@users.noreply.github.com>
8000
Copilot AI and others added 3 commits January 4, 2026 01:28
Co-authored-by: Flole998 <9951871+Flole998@users.noreply.github.com>
- Make libcurl a mandatory dependency (not optional)
- Remove old httpc.c custom implementation (2100+ lines of C code)
- Rename httpc_curl.c to httpc.c as the sole implementation
- Update configure to require libcurl
- Update Makefile to remove conditional compilation
- Update http.h to remove ENABLE_CURL conditionals
- Reduces maintenance burden and bug risk by using well-tested library

Co-authored-by: Flole998 <9951871+Flole998@users.noreply.github.com>
- Fix memory leak in realloc failure path
- Fix potential buffer overflow in URL construction using dynamic sizing
- Fix potential buffer overflow in header construction using dynamic sizing
- Remove duplicate ternary expression with local variable
- Remove unused hc_ssl field from http_client struct

Co-authored-by: Flole998 <9951871+Flole998@users.noreply.github.com>
Copilot AI changed the title [WIP] Replace custom HTTP client with a library Replace custom HTTP client with libcurl Jan 4, 2026
Copilot AI requested a review from Flole998 January 4, 2026 01:38
@sonarqubecloud
Copy link
Copy Markdown
sonarqubecloud bot commented Jan 4, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
6 Security Hotspots
D Security Rating on New Code (required ≥ A)
B Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

hc->hc_keepalive = 0;
}
http_arg_flush(header);
curl = curl_easy_init();

Check failure

Code scanning / SonarCloud

Weak SSL/TLS protocols should not be used High

Use stronger SSL and TLS versions See more on SonarQube Cloud
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
} else {
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);

Check failure

Code scanning / SonarCloud

Server certificates should be verified during SSL/TLS connections High

Enable certification chain verification on this SSL/TLS connection See more on SonarQube Cloud
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
} else {
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);

Check failure

Code scanning / SonarCloud

Server hostnames should be verified during SSL/TLS connections High

Enable server hostname verification on this SSL/TLS connection See more on SonarQube Cloud
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0