Skip to content

Commit fdbf1f0

Browse files
author
MateuszSeczkowski
committed
add filterRequest and filterResponse bindings
1 parent 4206fe2 commit fdbf1f0

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,25 @@ Full API
413413
* REWRITE_OBJ an object with 2 mandatory keys: matchRegex and replace. Any set keys will be set on the specified proxy port
414414
* CALLBACK(ERROR) function
415415
1. ERROR string if there was an error
416+
417+
**filterRequest(PORT, FILTER_DATA, CALLBACK)**
418+
419+
Allows intercepting requests for proxy on PORT
420+
421+
PARAMETERS:
422+
423+
* PORT of proxy for this command
424+
* FILTER_DATA string with code to intercept requests. Javascript request filters have access to the variables `request` (type io.netty.handler.codec.http.HttpRequest), `contents` (type net.lightbody.bmp.util.HttpMessageContents), and `messageInfo` (type net.lightbody.bmp.util.HttpMessageInfo). `messageInfo` contains additional information about the message.
425+
* CALLBACK(ERROR) function
426+
1. ERROR string if there was an error
427+
428+
**filterResponse(PORT, FILTER_DATA, CALLBACK)**
429+
430+
Allows intercepting responses for proxy on PORT
431+
432+
PARAMETERS:
433+
434+
* PORT of proxy for this command
435+
* FILTER_DATA string with code to intercept responses. Javascript response filters have access to the variables `response` (type io.netty.handler.codec.http.HttpResponse), `contents` (type net.lightbody.bmp.util.HttpMessageContents), and `messageInfo` (type net.lightbody.bmp.util.HttpMessageInfo). As in the request filter, `messageInfo` contains additional information about the message.
436+
* CALLBACK(ERROR) function
437+
1. ERROR string if there was an error

index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,24 @@ Proxy.prototype = {
220220
this.doReq("PUT", "/proxy/" + port + "/rewrite", data, cb);
221221
},
222222

223+
filterRequest: function (port, data, cb) {
224+
var options = {
225+
host: this.host, port: this.port, method: 'POST', path: '/proxy/' + port + '/filter/request', headers: {
226+
'Content-Type': 'text/plain'
227+
}
228+
};
229+
this.doReqWithOptions(options, data, cb);
230+
},
231+
232+
filterResponse: function (port, data, cb) {
233+
var options = {
234+
host: this.host, port: this.port, method: 'POST', path: '/proxy/' + port + '/filter/response', headers: {
235+
'Content-Type': 'text/plain'
236+
}
237+
};
238+
this.doReqWithOptions(options, data, cb);
239+
},
240+
223241
doReq: function (method, url, postData, cb) {
224242
var options = {
225243
host: this.host, port: this.port, method: method, path: url, headers: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "browsermob-proxy",
33
"description": "Javascript bindings for the browsermob-proxy",
44
"keywords": ["selenium", "test", "testing", "proxy", "tests", "har"],
5-
"version": "1.0.10",
5+
"version": "1.0.11",
66
"author": "Mark Ethan Trostler <mark@zzo.com>",
77
"repository": {
88
"type": "git",

0 commit comments

Comments
 (0)