-
Notifications
You must be signed in to change notification settings - Fork 168
/
billy.rb
45 lines (42 loc) · 1.35 KB
/
billy.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'billy/version'
require 'billy/config'
require 'billy/handlers/handler'
require 'billy/handlers/request_handler'
require 'billy/handlers/request_log'
require 'billy/handlers/stub_handler'
require 'billy/handlers/proxy_handler'
require 'billy/handlers/cache_handler'
require 'billy/proxy_request_stub'
require 'billy/cache'
require 'billy/ssl/certificate_helpers'
require 'billy/ssl/authority'
require 'billy/ssl/certificate'
require 'billy/ssl/certificate_chain'
require 'billy/proxy'
require 'billy/proxy_connection'
require 'billy/railtie' if defined?(Rails)
module Billy
def self.proxy
@billy_proxy ||= (
proxy = Billy::Proxy.new
proxy.start
proxy
)
end
def self.certificate_authority
@certificate_authority ||= Billy::Authority.new
end
# This global shortcut can be used inside of request stubs. You can modify
# the request beforehand and/or modify the actual response which is passed
# back by this method. But you can also implement a custom proxy passing
# method if you like to. This is just a shortcut.
def self.pass_request(params, headers, body, url, method)
handler = proxy.request_handler.handlers[:proxy]
response = handler.handle_request(method, url, headers, body)
{
code: response[:status],
body: response[:content],
headers: response[:headers]
}
end
end