Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spider-gazelle/connect-proxy
crystal lang connect / HTTP proxy implementation
https://github.com/spider-gazelle/connect-proxy
Last synced: 9 days ago
JSON representation
crystal lang connect / HTTP proxy implementation
- Host: GitHub
- URL: https://github.com/spider-gazelle/connect-proxy
- Owner: spider-gazelle
- License: mit
- Created: 2019-10-07T02:05:52.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-13T05:32:04.000Z (3 months ago)
- Last Synced: 2024-08-14T05:45:43.431Z (3 months ago)
- Language: Crystal
- Size: 20.5 KB
- Stars: 7
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - connect-proxy - Connect method style of HTTP tunnelling / HTTP proxy (Network Protocols)
- awesome-crystal - connect-proxy - Connect method style of HTTP tunnelling / HTTP proxy (Network Protocols)
README
# Connect Proxy
[![CI](https://github.com/spider-gazelle/connect-proxy/actions/workflows/ci.yml/badge.svg)](https://github.com/spider-gazelle/connect-proxy/actions/workflows/ci.yml)
A simple implementation of the [connect method](https://en.wikipedia.org/wiki/HTTP_tunnel#HTTP_CONNECT_method) for HTTP tunnelling.
Most commonly used in [HTTP proxy servers](https://en.wikipedia.org/wiki/Proxy_server#Web_proxy_servers).# Usage
The most common usage of this shard is to use the crystal `::HTTP::Client` via a proxy server
```crystal
host = URI.parse("https://www.google.com")
response = ConnectProxy::HTTPClient.new(host) do |client|
client.exec("GET", "/")
end
response.success?
```By default the HTTP client will pick up the `https_proxy` or `http_proxy` environment variables and use the URLs configured in there.
However you can override the environment or provide your own proxy server.```crystal
host = URI.parse("https://www.google.com")
client = ConnectProxy::HTTPClient.new(host)
proxy = ConnectProxy.new("134.209.219.234", 80, {username: "admin", password: "pass"})
client.set_proxy(proxy)
response = client.exec("GET", "/")
response.success?
```## Forcing Proxy Support
It's possible to simply introduce proxy support to any app by including extensions to the core classes.
I wouldn't recommend this unless there are too many libs to patch / you don't control the code directly```crystal
# Patches ::HTTP::Client
require "connect-proxy/ext/http-client"# Patches ::HTTP::Websocket
require "connect-proxy/ext/websocket"```
This method requires you to use the standard proxy ENV vars