Giter Club home page Giter Club logo

hcproxy's Introduction

hcproxy

hcproxy is a lightweight forward HTTP proxy that implements just one HTTP method -- CONNECT.

With decent network drivers tunneling is zero copy, which makes hcproxy fast and efficient. The price for this is 6 file descriptors per connection (client socket, server socket and two pipes).

Requirements

  • To compile: C++17 compiler.
  • To run: Linux, libc.
  • To run as daemon: systemd.

Compiling

git clone https://github.com/romkatv/hcproxy.git
cd hcproxy
make

Installing locally

Install hcproxy as a systemd service:

sudo make install

Verify that the service is running:

$ systemctl status hcproxy
โ— hcproxy.service - HTTP CONNECT proxy
   Loaded: loaded (/lib/systemd/system/hcproxy.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2018-07-13 13:02:09 UTC; 30s ago
   ...

Try it out:

$ curl -x localhost:8889 https://www.google.com/
<!doctype html>...

If you want to fetch an http URL (rather than https), use -p to force curl to use CONNECT for proxying all traffic:

$ curl -p -x localhost:8889 http://www.google.com/
<!doctype html>...

Installing remotely via SSH

./install-via-ssh certificate.pem [email protected]

Configuring

To change configuration, you'll need to modify the source code of main() in hcproxy.cc and recompile. For example, here's how you can change the port on which hcproxy listens and the timeout for establishing outgoing connections.

   hcproxy::Options opt;
+  opt.listen_port = 1234;
+  opt.connect_timeout = std::chrono::seconds(30);
   hcproxy::RunProxy(opt);

The list of options, their descriptions and default values can be found in the source code.

The behavior of hcproxy cannot be customized through request headers. It simply ignores all headers.

Using hcproxy as web browser proxy

You can use hcproxy as web browser proxy. However, unless you can convince your browser to tunnel all traffic via HTTP CONNECT, fetching plain http URLs won't work. WebSocket (ws and wss protocols) and https will work fine as they always go through CONNECT.

Troubleshooting

If hcproxy doesn't like an incoming request (e.g., it's not a CONNECT) or cannot connect to the downstream server, it simply closes the incoming connection. It never replies with an HTTP error. The only response it ever sends to the client is HTTP 200.

Logs are written to stderr. Severity levels:

  • INFO: Normal operation.
  • WARN: Request-related errors such as unparsable content or unresolvable hosts.
  • ERROR: Abnormal conditions that may affect all requests; for example, running out of file descriptors.
  • FATAL: Unexpected error or assertion failure; hcproxy will abort after writing the message.

To disable all logs except FATAL (which cannot be disabled), add -DHCP_MIN_LOG_LVL=FATAL compiler flag to Makefile and recompile.

If you've installed hcproxy as systemd service, you can read logs with journalctl. Start and stop events, as well as crashes and logs, are recorded there:

journalctl -u hcproxy | tail

hcproxy's People

Contributors

romkatv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hcproxy's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.