• Stars
    star
    39
  • Rank 693,563 (Top 14 %)
  • Language
    Crystal
  • License
    MIT License
  • Created about 7 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A HTTP Proxy server and client written in Crystal

HTTP::Proxy

Crystal CI GitHub release License

A HTTP Proxy server and client written in Crystal

Installation

Add this to your application's shard.yml:

dependencies:
  http_proxy:
    github: mamantoha/http_proxy

Usage

Server

require "http_proxy"

host = "127.0.0.1"
port = 8080

server = HTTP::Proxy::Server.new

address = server.bind_tcp(host, port)
puts "Listening on http://#{address}"
server.listen
require "http_proxy"
require "option_parser"

host = "192.168.0.1"
port = 3128

OptionParser.parse! do |opts|
  opts.on("-h HOST", "--host HOST", "define host to run server") do |opt|
    host = opt
  end

  opts.on("-p PORT", "--port PORT", "define port to run server") do |opt|
    port = opt.to_i
  end
end

server = HTTP::Proxy::Server.new(handlers: [
  HTTP::LogHandler.new,
]) do |context|
  context.perform
end

address = server.bind_tcp(host, port)
puts "Listening on http://#{address}"
server.listen

Basic Authentication

server = HTTP::Proxy::Server.new(handlers: [
  HTTP::LogHandler.new,
  HTTP::Proxy::Server::BasicAuth.new("user", "passwd"),
]) do |context|
  context.request.headers.add("X-Forwarded-For", "127.0.0.1")
  context.perform
end

Client

Make request with proxy

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

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")
end

puts response.status_code
puts response.body

Development

Proxy server

  • Basic HTTP Proxy: GET, POST, PUT, DELETE support
  • Basic HTTP Proxy: OPTIONS support
  • HTTPS Proxy: CONNECT support
  • Make context.request & context.response writable
  • Basic Authentication
  • MITM HTTPS Proxy

Proxy client

  • Basic HTTP Proxy: GET, POST, PUT, DELETE support
  • Basic HTTP Proxy: OPTIONS support
  • HTTPS Proxy: CONNECT support
  • Basic Authentication

Contributing

  1. Fork it (https://github.com/mamantoha/http_proxy/fork)
  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 Theo Li - creator, maintainer
  • mamantoha Anton Maminov - maintainer

More Repositories

1

crest

HTTP and REST client for Crystal
Crystal
234
star
2

omniauth-vkontakte

Vkontakte OAuth2 Strategy for OmniAuth
Ruby
141
star
3

zipstream

A command line tool that allows you to easily share files and directories over the network
Crystal
60
star
4

nanoid.cr

Crystal implementation of Nanoid, secure URL-friendly unique ID generator.
Crystal
41
star
5

shards-info

Source code of https://shards.info/
Crystal
38
star
6

humanize_time

Adds the humanize method to reports the approximate distance in time between two Time. humanize supports i18n translations too so it can be used in internationalized apps.
Crystal
23
star
7

vkontakte_client

VKontakte API Client for Ruby
Ruby
22
star
8

mpd_client

Simple Music Player Daemon library written entirely in Ruby
Ruby
16
star
9

cryMPD

A minimalistic web-based MPD client
Crystal
14
star
10

twitter-crystal

A library to access the Twitter API using Crystal
Crystal
14
star
11

uaenv

UaEnv - модуль для роботи з українським текстом в Ruby. Головна ціль UaEnv - полегшити розробку україномовних програм на Ruby
Ruby
11
star
12

crystal_mpd

Concurrent MPD client written in Crystal
Crystal
10
star
13

xml_converter

Create hashes from XML documents easily.
Crystal
8
star
14

time_zone

A helper to work with time zones in Crystal
Crystal
8
star
15

iso_codes

🌐 Lists of various ISO standards (ISO 3166-1 for countries and ISO 639-2 for languages) with translations for Crystal
Crystal
8
star
16

zci

Zendesk and Crowdin integration Command Line Interface (CLI)
Ruby
7
star
17

dotfiles

Shell
6
star
18

crystal-cmark-gfm

Minimal C bindings for parsing and rendering with cmark-gfm
Crystal
6
star
19

zendesk_help_center_api_client_rb

Zendesk Help Center REST API Client
Ruby
6
star
20

crystal-hunspell

Crystal bindings for Hunspell.
Crystal
6
star
21

lifecell_api

lifecell_api is used to interact with the lifecell API from Ruby
Ruby
6
star
22

foaas_client

A Crystal client for FOAAS - a modern, RESTful, scalable solution to the common problem of telling people to fuck off
Crystal
5
star
23

mongo-sinatra-admin

Web-based MongoDB admin interface written with Ruby and Sinatra
Ruby
5
star
24

detransport_ternopil_telegram

Public transport in Ternopil 🇺🇦
Crystal
5
star
25

bytes_ext

Byte Conversion Library for Crystal
Crystal
5
star
26

detransport_lviv_telegram

Public transport in Lviv 🇺🇦
Crystal
4
star
27

telegram_bot

Telegram Bot API Wrapper for Crystal 💎
Crystal
4
star
28

shards_spec

A shard.yml parser for the Crystal language
Crystal
3
star
29

resolv-crystal

A DNS resolver library written in Crystal
Crystal
3
star
30

http-client-digest_auth

An implementation of RFC 2617 Digest Access Authentication for Crystal
Crystal
2
star
31

crystal-exif

Crystal bindings for libexif
Crystal
2
star
32

rbtorstat

rbtorstat is a simple web page generator, written in Ruby, which shows status information about the rTorrent bittorrent client
Ruby
2
star
33

fci

Freshdesk and Crowdin integration Command Line Interface (CLI)
Ruby
2
star
34

time_duration

Provides a structured and convenient way to work with durations of time in the Crystal programming language
Crystal
2
star
35

air_alert_map_ua_wallpaper

A CLI tool for setting the Air Raid Alert Map of Ukraine as a desktop background
Crystal
2
star
36

ydokey

A simple command-line utility for Linux to convert key commands to raw keycodes which used in ydotool
Crystal
2
star
37

crystal-hidapi

A Crystal interface to HIDAPI library.
Crystal
2
star
38

matiuky_regexp

A collection of usefull regular expressions for matiuky
Ruby
2
star
39

crystal-bplist

Generate and parse Apple binary .plist files with Crystal
Crystal
1
star
40

i18n_plural_rules

Custom plural rules support for i18n.cr library.
Crystal
1
star
41

uz-api

A Ruby interface to the Ukrzaliznytsia API (http://booking.uz.gov.ua/)
Ruby
1
star
42

validates_nested_uniqueness

Library for validating nested uniqueness in Rails.
Ruby
1
star
43

time_by_example

Provides a Crystal implementation of Go-style time formatting by example.
Crystal
1
star