-
-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using Rack::Proxy as a middleware instead of using it as a standard Ruby class #55
Conversation
@@ -39,7 +39,8 @@ def reconstruct_header_name(name) | |||
end | |||
|
|||
# @option opts [String, URI::HTTP] :backend Backend host to proxy requests to | |||
def initialize(opts = {}) | |||
def initialize(app = nil, opts= {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would have to be backward compatible: if the first arg is a hash, then it should be assigned to the opts
variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, just wanted to make sure. Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still need that conditional check for the app param being a hash :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added the conditional
This idea seems sensible. It would have to be backward compatible though, and docs and tests should be updated too. I think this change would fully deserve a new minor version: 0.6.0 :) |
i can work on tests, but it seems rack-test is not compatible with ruby > 2.1.5 . Would you mind if i rewrite tests to use rspec instead? or maybe minitest? which seems to be compatible . You can see this issue here: https://travis-ci.org/bogdanRada/rack-proxy |
I'm running Ruby 2.3.0 and the tests run fine (except one is failing, but /dev/rack-proxy (master)$ ruby -v ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15] ~/dev/rack-proxy (master)$ rake test /Users/ncr/.rubies/ruby-2.3.0/bin/ruby -I"lib:test" Loaded suite Started _........._F Failure: Google always sets a cookie, yo. Where my cookies at?!. is not true. test_http_full_request_headers(RackProxyTest) /Users/ncr/dev/rack-proxy/test/rack_proxy_test.rb:35:in
...... Finished in 3.767812 seconds. 16 tests, 43 assertions, 1 failures, 0 errors, 0 pendings, 0 omissions, 0 93.75% passed 4.25 tests/s, 11.41 assertions/s rake aborted! Command failed with status (1): [ruby -I"lib:test" czw., 19.05.2016 o 12:56 użytkownik rada bogdan raul <
|
I am really nto sure how you're doing that. I get this error: cannot load such file -- test/unit (LoadError) . Do you have something locally installed? |
I was able to fix it by adding to gemspec this line:
I think this should be included in the gem , otherwise people would have hard time running tests I commited the changes in this pull request for that. Hope that is fine. The tests for this branch are passing https://travis-ci.org/bogdanRada/rack-proxy/builds/131397008 . So i don;t think we need to update tests. |
Looks ok. czw., 19.05.2016 o 14:03 użytkownik rada bogdan raul <
|
updated the readme too. I think now the only change is to bump the version, but that i think should be done after merging the pull request by the owner or one of the collaborators. Let me know if it looks ok, Thank you very much |
@@ -105,6 +106,7 @@ def perform_request(env) | |||
http.read_timeout = read_timeout | |||
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if use_ssl && ssl_verify_none | |||
http.ssl_version = @ssl_version if @ssl_version | |||
http.set_debug_output($stdout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed . Added that by mistake. I was using it to debug the proxy requests locally
updated the code, Build is passing: https://travis-ci.org/bogdanRada/rack-proxy/builds/131414275 |
Build is still passing https://travis-ci.org/bogdanRada/rack-proxy/builds/131415945 |
def initialize(opts = {}) | ||
def initialize(app = nil, opts= {}) | ||
@app = app | ||
opts = app.is_a?(Hash) ? app.merge(opts) : opts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why app.merge(opts)
. In case the old way of calling things is used, this has no effect I think.
I would write it like this:
if app.is_a?(Hash)
opts = app
@app = nil
else
@app = app
end
This way, we also avoid having incorrectly set @app
.
Applied suggestion for conditional . Build is passing :https://travis-ci.org/bogdanRada/rack-proxy/builds/131432384 |
Thanks a lot! Will release a new gem shortly. |
Awesome . thanks |
In order for Rack Proxy to work as middleware for a Rack application (Rails or sinatra or any rack based application ) the initialize method for the Rack::Proxy class needed to be changed to receive first the application and then the options.
why is it useful?
Consider folowing scenario: Having a application that uses by default Savon for doing request to a web-service, but want to proxy only some requests to another server. could be easily achieved doing this:
This means in Rails you could use this like this:
and in sintra you could do like this:
instead of doing
In this example only requests that end with ".php" are proxied , the other requests are not proxied.
This might be a backward incompatible change and the README might need updated too. I am opened though to suggestions.
This fixes also #53
Let me know what you think. Thank you very much