Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mamantoha/http_proxy
A HTTP Proxy server and client written in Crystal
https://github.com/mamantoha/http_proxy
crystal hacktoberfest http http-proxy http-server proxy-client proxy-server
Last synced: 14 days ago
JSON representation
A HTTP Proxy server and client written in Crystal
- Host: GitHub
- URL: https://github.com/mamantoha/http_proxy
- Owner: mamantoha
- License: mit
- Created: 2017-10-28T11:44:41.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-07-26T14:50:08.000Z (4 months ago)
- Last Synced: 2024-10-03T12:33:52.546Z (about 1 month ago)
- Topics: crystal, hacktoberfest, http, http-proxy, http-server, proxy-client, proxy-server
- Language: Crystal
- Homepage:
- Size: 115 KB
- Stars: 39
- Watchers: 5
- Forks: 6
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# HTTP::Proxy
![Crystal CI](https://github.com/mamantoha/http_proxy/workflows/Crystal%20CI/badge.svg)
[![GitHub release](https://img.shields.io/github/release/mamantoha/http_proxy.svg)](https://github.com/mamantoha/http_proxy/releases)
[![License](https://img.shields.io/github/license/mamantoha/http_proxy.svg)](https://github.com/mamantoha/http_proxy/blob/master/LICENSE)A HTTP Proxy server and client written in Crystal
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
http_proxy:
github: mamantoha/http_proxy
```## Usage
### Server
```crystal
require "http_proxy"host = "127.0.0.1"
port = 8080server = HTTP::Proxy::Server.new
address = server.bind_tcp(host, port)
puts "Listening on http://#{address}"
server.listen
``````crystal
require "http_proxy"
require "option_parser"host = "192.168.0.1"
port = 3128OptionParser.parse! do |opts|
opts.on("-h HOST", "--host HOST", "define host to run server") do |opt|
host = opt
endopts.on("-p PORT", "--port PORT", "define port to run server") do |opt|
port = opt.to_i
end
endserver = HTTP::Proxy::Server.new(handlers: [
HTTP::LogHandler.new,
]) do |context|
context.perform
endaddress = server.bind_tcp(host, port)
puts "Listening on http://#{address}"
server.listen
```#### Basic Authentication
```crystal
server = HTTP::Proxy::Server.new(handlers: [
HTTP::LogHandler.new,
HTTP::Proxy::Server::BasicAuthHandler.new("user", "passwd"),
]) do |context|
context.request.headers.add("X-Forwarded-For", "127.0.0.1")
context.perform
end
```### Client
#### Make request with proxy
```crystal
require "http_proxy"proxy_client = HTTP::Proxy::Client.new("127.0.0.1", 8080)
uri = URI.parse("http://httpbingo.org")
client = HTTP::Client.new(uri)
client.proxy = proxy_client
response = client.get("/get")
```#### Client Authentication
```crystal
uri = URI.parse("https://httpbingo.org")
proxy_client = HTTP::Proxy::Client.new("127.0.0.1", 8080, username: "user", password: "passwd")response = HTTP::Client.new(uri) do |client|
client.proxy = proxy_client
client.get("/get")
endputs response.status_code
puts response.body
```## Development
### Proxy server
* [x] Basic HTTP Proxy: GET, POST, PUT, DELETE support
* [x] Basic HTTP Proxy: OPTIONS support
* [x] HTTPS Proxy: CONNECT support
* [x] Make context.request & context.response writable
* [x] Basic Authentication
* [ ] MITM HTTPS Proxy### Proxy client
* [x] Basic HTTP Proxy: GET, POST, PUT, DELETE support
* [x] Basic HTTP Proxy: OPTIONS support
* [x] HTTPS Proxy: CONNECT support
* [x] Basic Authentication## Contributing
1. Fork it ()
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request## Contributors
* [bbtfr](https://github.com/bbtfr) Theo Li - creator, maintainer
* [mamantoha](https://github.com/mamantoha) Anton Maminov - maintainer