Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from pex/beautify-readme
Beautify README for github
- Loading branch information
Showing
2 changed files
with
55 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
A request/response rewriting HTTP proxy. A Rack app. | ||
Subclass `Rack::Proxy` and provide your `rewrite_env` and `rewrite_response` methods. | ||
|
||
|
||
## Example | ||
|
||
```ruby | ||
class Foo < Rack::Proxy | ||
|
||
def rewrite_env(env) | ||
env["HTTP_HOST"] = "example.com" | ||
|
||
env | ||
end | ||
|
||
def rewrite_response(triplet) | ||
status, headers, body = triplet | ||
|
||
headers["X-Foo"] = "Bar" | ||
|
||
triplet | ||
end | ||
|
||
end | ||
``` | ||
|
||
### Disable SSL session verification when proxying a server with e.g. self-signed SSL certs | ||
|
||
```ruby | ||
class TrustingProxy < Rack::Proxy | ||
|
||
def rewrite_env(env) | ||
env["rack.ssl_verify_none"] = true | ||
|
||
env | ||
end | ||
|
||
end | ||
``` | ||
|
||
The same can be achieved for *all* requests going through the `Rack::Proxy` instance by using | ||
|
||
```ruby | ||
Rack::Proxy.new(ssl_verify_none: true) | ||
``` | ||
|
||
See tests for more examples. | ||
|
||
## WARNING | ||
|
||
Doesn't work with fakeweb/webmock. Both libraries monkey-patch net/http code. | ||
|
||
## Todos | ||
|
||
* Make the docs up to date with the current use case for this code: everything except streaming which involved a rather ugly monkey patch and only worked in 1.8, but does not work now. |