Short circuit requests via RESTful API

391 views
Skip to first unread message

I Telic

unread,
Nov 20, 2015, 6:03:29 AM11/20/15
to BrowserMob Proxy
Hi,

I'm working on a node full stack javascript application, and am using browsermob to examine network traffic during integration tests using selenium.

However, I'm also using mountebank to mock service endpoints during tests.

I'd be interested in moving the mountebank mocks in to browsermob if possible.

This would involve completely intercepting the requests so they don't reach their final endpoint, and simply responding with the test responses I want.

Keeping in mind there's no java in my project, and that I'll be relying on running browsermob as a standalone app that I maniuplate via it's restful interface...

Is it possible to create a short circuiting request filter via restful calls?

This doesn't seem possible to me at the moment because an appropriately typed response object can not be returned.

In other words, it seems that the request filter only has access to `request`, `contents`, and `messageInfo` objects.

Is it possible to create an `io.netty.handler.codec.http.HttpResponse`type response object from within the plain javascript passed to the Restful API?

Or would it be possible for a future version of BMP to include a default Response type object in the request filter, for easy manipulation of a short-circuiting response?

(And if the `contents` and `response` objects are separate, how would I then modify the response content as opposed to the request content when short-circuiting within a request filter? - I had expected the content to be a property of the request and response objects...?)

je...@outlook.com

unread,
Dec 27, 2015, 9:49:43 PM12/27/15
to BrowserMob Proxy
Hi,

Yes, it is possible to short-circuit a request with Javascript. You need to return an instance of DefaultFullHttpResponse from the Javascript code. I was intrigued by this question, so I added a test case that does exactly that: https://github.com/lightbody/browsermob-proxy/blob/master/browsermob-rest/src/test/groovy/net/lightbody/bmp/proxy/FilterTest.groovy#L244

The Javascript as written in the test requires that BMP be running on Java 8 (using the Nashorn Javascript engine), but it should work on Java 7 with some adjustments to the Java.type code.

I do agree it would be nice to have an easier way to short-circuit responses from Javascript. Perhaps this could be incorporated into the future REST refactoring.

Hope that helps!
Jason
Reply all
Reply to author
Forward
0 new messages