Skip to content

Conversation

@bmansvk
Copy link

@bmansvk bmansvk commented Oct 21, 2025

This commit adds HTTP proxy functionality to ocproxy, allowing users to create an HTTP proxy server that supports both HTTP and HTTPS connections through the CONNECT method.

Features:

  • New -H/--httpproxy option to spawn HTTP proxy on specified port
  • Support for CONNECT method for HTTPS tunneling
  • HTTP request parsing and validation
  • DNS resolution for hostnames in CONNECT requests
  • Error handling with proper HTTP status codes
  • Can be used alongside existing -D (SOCKS) and -L (port forward) options

The HTTP proxy works by:

  1. Accepting HTTP CONNECT requests from browsers/clients
  2. Parsing the target hostname and port
  3. Resolving DNS if needed (supports both IPs and hostnames)
  4. Creating a TCP tunnel through the VPN to the destination
  5. Returning "200 Connection established" on success

Usage example:
openconnect --script-tun --script "./ocproxy -H 8080" vpn.example.com

Then configure your browser to use HTTP proxy at 127.0.0.1:8080

Connection limits:

  • Shares the same connection pool (MAX_CONN=1024) with SOCKS/port forwarding
  • Can handle up to 1024 concurrent connections across all proxy types

🤖 Generated with Claude Code

This commit adds HTTP proxy functionality to ocproxy, allowing users
to create an HTTP proxy server that supports both HTTP and HTTPS
connections through the CONNECT method.

Features:
- New -H/--httpproxy option to spawn HTTP proxy on specified port
- Support for CONNECT method for HTTPS tunneling
- HTTP request parsing and validation
- DNS resolution for hostnames in CONNECT requests
- Error handling with proper HTTP status codes
- Can be used alongside existing -D (SOCKS) and -L (port forward) options

The HTTP proxy works by:
1. Accepting HTTP CONNECT requests from browsers/clients
2. Parsing the target hostname and port
3. Resolving DNS if needed (supports both IPs and hostnames)
4. Creating a TCP tunnel through the VPN to the destination
5. Returning "200 Connection established" on success

Usage example:
  openconnect --script-tun --script "./ocproxy -H 8080" vpn.example.com

Then configure your browser to use HTTP proxy at 127.0.0.1:8080

Connection limits:
- Shares the same connection pool (MAX_CONN=1024) with SOCKS/port forwarding
- Can handle up to 1024 concurrent connections across all proxy types

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@bmansvk
Copy link
Author

bmansvk commented Oct 21, 2025

Tested on macOS Tahoe and it works.

- Add complete HTTP proxy implementation for all methods (GET, POST, PUT, DELETE, etc.)
- Previously only CONNECT method (HTTPS tunneling) was supported
- Add HTTP relay mode to forward requests and responses bidirectionally
- Add new states: STATE_HTTP_HEADERS, STATE_HTTP_RELAY
- Add HTTP request parsing for both absolute and relative URLs
- Add proper memory management for HTTP request buffers
- Add portable strcasestr() implementation for non-glibc systems

Compilation fixes:
- Fix format-nonliteral warnings with function attributes
- Remove unused variable 'header_line'
- Fix lwIP pthread function cast warning using union
- Update autoconf macros: replace AC_TRY_COMPILE with AC_COMPILE_IFELSE
- Remove obsolete AC_GNU_SOURCE and AC_PROG_CC_C99 macros
- Create m4 directory to silence aclocal warning

Documentation:
- Add macOS build instructions with Homebrew dependencies
- Document full HTTP/HTTPS proxy feature set
- Add CPPFLAGS/LDFLAGS configuration for Intel and Apple Silicon Macs
- Log SOCKS5 connections as domain:port
- Log HTTP/HTTPS connections with full URL including path and query parameters
- Add -l/--logfile option to specify log file path
- Include timestamps in ISO 8601 format for all log entries
- Distinguish between HTTPS CONNECT tunnels and regular HTTP requests
- Log port forwarding connections
- Add comprehensive help text showing all command line options
- Include descriptions of environment variables
- Provide usage examples for common scenarios
- Check for help flag early before initialization to avoid VPNFD requirement
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