Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 8fc7721

Browse files
author
Greg Heitz
committed
Add filterRequest and filterReponse
1 parent b4f9815 commit 8fc7721

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/BrowserMob.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,18 @@ public function redirectUrl($match, $replace)
164164
return $this->response->success;
165165
}
166166

167+
public function filterRequest($script)
168+
{
169+
$this->_requestInterceptor($script);
170+
return $this->response->success;
171+
}
172+
173+
public function filterResponse($script)
174+
{
175+
$this->_responseInterceptor($script);
176+
return $this->response->success;
177+
}
178+
167179
// magic function that exposes BrowserMobProxy API pulic methods
168180
public function __call($name, $args)
169181
{

tests/_data/docker/start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
exec /browsermob-proxy/bin/browsermob-proxy -port 9090 -proxyPortRange 9091-9189
2+
exec /browsermob-proxy/bin/browsermob-proxy -port 9090 -proxyPortRange 9091-9189 --use-littleproxy false

tests/functional/BrowserMobProxyCest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,22 @@ public function redirectUrl(FunctionalTester $I)
9999
$I->assertEquals('http://codeception.com/', $har['log']['entries'][0]['request']['url']);
100100
$I->closeProxy();
101101
}
102+
103+
public function filterRequest(FunctionalTester $I)
104+
{
105+
$port = $I->openProxy();
106+
$I->assertNotNull($port, "`${port}` is not a valid port");
107+
$rep = $I->filterRequest("request.headers().remove('User-Agent'); request.headers().add('User-Agent', 'My-Custom-User-Agent-String 1.0');");
108+
$I->assertTrue($rep);
109+
$I->closeProxy();
110+
}
111+
112+
public function filterResponse(FunctionalTester $I)
113+
{
114+
$port = $I->openProxy();
115+
$I->assertNotNull($port, "`${port}` is not a valid port");
116+
$rep = $I->filterResponse("contents.setTextContents('<html><body>Response successfully intercepted</body></html>');");
117+
$I->assertTrue($rep);
118+
$I->closeProxy();
119+
}
102120
}

0 commit comments

Comments
 (0)