Skip to content

Conversation

@benoitc
Copy link
Owner

@benoitc benoitc commented Jul 24, 2025

Summary

When proxy environment variables (http_proxy, https_proxy, etc.) are set to empty strings or whitespace-only values, hackney crashes with a pattern match error in hackney_url:parse_netloc/2.

Problem

  • export http_proxy="" causes all hackney requests to fail
  • The empty string is passed to URL parsing which expects a valid URL format
  • This affects users who clear proxy variables by setting them to empty strings

Solution

  • Check for empty strings in do_get_proxy_env/1 before attempting to parse
  • Strip whitespace from proxy URLs and treat whitespace-only values as empty
  • Skip to the next proxy variable in the list when empty values are found

Test plan

  • Added comprehensive unit tests in test/hackney_proxy_tests.erl
  • Tests cover empty strings, whitespace-only strings, and valid proxy URLs
  • Integration tests verify that requests work correctly with empty proxy variables
  • Exported internal functions for testing when compiled with -DTEST flag

@benoitc benoitc force-pushed the fix-empty-proxy-env branch from 79dc20d to 831b440 Compare July 24, 2025 12:37
When proxy environment variables (http_proxy, https_proxy, etc.) are set
to empty strings or whitespace-only values, hackney would crash with a
pattern match error in hackney_url:parse_netloc/2.

This fix:
- Checks for empty strings in do_get_proxy_env/1
- Strips whitespace from proxy URLs and treats whitespace-only as empty
- Adds comprehensive unit tests to prevent regression
- Exports proxy functions for testing when compiled with -DTEST

Fixes the issue where export http_proxy="" would cause hackney requests to fail.
@benoitc benoitc force-pushed the fix-empty-proxy-env branch from 831b440 to 77aa238 Compare July 24, 2025 12:40
@benoitc benoitc merged commit 76b03b2 into master Jul 24, 2025
5 checks passed
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.

2 participants