Code Monkey home page Code Monkey logo

http_proxy's Issues

Not Found bug

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

Update to work with Crystal 0.30.0

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

incompatible with kemal

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

Set proxies according to the *_PROXY environment variables

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

  1. When used, it would automatically load the appropriate settings from ENV and create the corresponding HTTP::Proxy::Client objects.
  2. It would then monkey-patch the 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.

Pooling connections to the proxy

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

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.