File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,15 @@ def clear_blacklist
105105 @resource [ 'blacklist' ] . delete
106106 end
107107
108+ def rewrite ( match_regex , replace )
109+ regex = Regexp === match_regex ? match_regex . source : match_regex . to_s
110+ @resource [ 'rewrite' ] . put :matchRegex => regex , :replace => replace
111+ end
112+
113+ def clear_rewrites
114+ @resource [ 'rewrite' ] . delete
115+ end
116+
108117 def header ( hash )
109118 @resource [ 'headers' ] . post hash . to_json , :content_type => "application/json"
110119 end
Original file line number Diff line number Diff line change @@ -19,7 +19,8 @@ module Proxy
1919 "headers" => double ( "resource[headers]" ) ,
2020 "auth/basic/#{ DOMAIN } " => double ( "resource[auth/basic/#{ DOMAIN } ]" ) ,
2121 "hosts" => double ( "resource[hosts]" ) ,
22- "timeout" => double ( "resource[timeout]" )
22+ "timeout" => double ( "resource[timeout]" ) ,
23+ "rewrite" => double ( "resource[rewrite]" )
2324 } . each do |path , mock |
2425 resource . stub ( :[] ) . with ( path ) . and_return ( mock )
2526 end
@@ -231,6 +232,19 @@ module Proxy
231232 client . remap_dns_hosts ( DOMAIN => '1.2.3.4' )
232233 end
233234
235+ it 'sets a rewrite rule' do
236+ resource [ 'rewrite' ] . should_receive ( :put ) .
237+ with ( :matchRegex => 'old.com' , :replace => 'new.com' )
238+
239+ client . rewrite ( %r[old.com] , 'new.com' )
240+ end
241+
242+ it 'clears the rewrite rules' do
243+ resource [ 'rewrite' ] . should_receive ( :delete )
244+
245+ client . clear_rewrites
246+ end
247+
234248 context "#selenium_proxy" do
235249 it "defaults to HTTP proxy only" do
236250 proxy = client . selenium_proxy
You can’t perform that action at this time.
0 commit comments