mamantoha / http_proxy Goto Github PK
View Code? Open in Web Editor NEWA HTTP Proxy server and client written in Crystal
License: MIT License
A HTTP Proxy server and client written in Crystal
License: MIT License
Hello,
I was wondering if it is currently possible to pool together connections to the proxy?
I'm working on integrating this shard into a large application that makes a ton of requests to the same source. Having some way to reuse connections to the proxy will probably improve performance by quite a bit.
Thanks
Syeopite
require "http_proxy"
server = HTTP::Proxy::Server.new("127.0.0.1", 8088)
puts "Listening on http://#{server.host}:#{server.port}"
server.listen
Some strange errors when using proxy:
curl --proxy 127.0.0.1:8088 http://ya.ru
Not Found
curl --proxy 127.0.0.1:8088 http://mail.ru
Not Found
<html><body>Redirect...</body></html>
curl --proxy 127.0.0.1:8088 http://ipinfo.io
curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding
Crystal 0.35.0
Error:
Unhandled exception in spawn: Closed stream (IO::Error)
Related to crystal-lang/crystal#9243
The [protocol]_PROXY
and NO_PROXY
environment variables are commonly used to configure proxies in applications. Wget and Emacs are two examples. Python's requests
library also respects HTTP_PROXY
and HTTPS_PROXY
out of the box.
It would be great if we could have a helper method like HTTP::Proxy::Client.use_env
that would do the followings
HTTP::Proxy::Client
objects.HTTP::Client
class in the standard library so that the clients use the appropriate proxies in all requests.Here's an example implementation I used in my project. I will be happy to submit a PR if you think it's a good idea.
require "http_proxy"
require "kemal"
spawn do
server = HTTP::Proxy::Server.new("127.0.0.1", 8080)
puts "Listening on http://#{server.host}:#{server.port}"
server.listen
end
Kemal.run
Error in 1.cr:11: instantiating 'Kemal:Module#run()'
Kemal.run
^~~
in lib/kemal/src/kemal.cr:19: instantiating 'Kemal:Module#run(Nil)'
self.run(nil)
^~~
in lib/kemal/src/kemal.cr:12: instantiating 'Kemal:Module#run(Nil)'
self.run port do
^~~
in lib/kemal/src/kemal.cr:62: instantiating 'HTTP::Server:Class#new(String, Int32, Array(HTTP::Handler))'
require "http_proxy"
config.server ||= HTTP::Server.new(config.host_binding, config.port, config.handlers)
^~~
in /usr/local/Cellar/crystal-lang/0.24.2_1/src/http/server.cr:125: instantiating 'HTTP::Server:Class#build_middleware(Array(HTTP::Handler))'
handler = HTTP::Server.build_middleware handlers
^~~~~~~~~~~~~~~~
in /usr/local/Cellar/crystal-lang/0.24.2_1/src/http/server.cr:196: instantiating 'HTTP::Handler#next=(HTTP::Handler)'
0.upto(handlers.size - 2) { |i| handlers[i].next = handlers[i + 1] }
^~~~
in /usr/local/Cellar/crystal-lang/0.24.2_1/src/http/server/handler.cr:18: expanding macro
property next : Handler | Proc | Nil
^
in macro 'property' expanded macro: macro_4380348752:567, line 10:
1.
2.
3.
4. @next : Handler | Proc | Nil
5.
6. def next : Handler | Proc | Nil
7. @next
8. end
9.
> 10. def next=(@next : Handler | Proc | Nil)
11. end
12.
13.
14.
15.
instance variable '@next' of HTTP::Proxy::Server::Handler must be (HTTP::Proxy::Server::Handler | Proc(HTTP::Proxy::Server::Context, Nil) | Nil), not HTTP::Handler
There are some changes that have been made since 0.27.0 that keep this from working correctly, including the changing of HTTP::Handler::Proc
to HTTP::Handler::HandlerProc
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.