Modify/intercept response body

165 views
Skip to first unread message

ja...@getadmiral.com

unread,
Feb 20, 2017, 7:46:28 PM2/20/17
to headless-dev
What's the best way via the debugging protocol to modify/rewrite a request and it's response? For tests, we'd like to have predictable returns from external APIs and therefore we'd like to either be able to rewrite the destination (say, to our own server) or rewrite the response body.

Thanks!

Alex Clarke

unread,
Feb 21, 2017, 3:37:31 AM2/21/17
to ja...@getadmiral.com, headless-dev
The devtools protocol doesn't really support that use case.  I'd suggest one of the following options:

1. Write a proxy to stub out the APIs you want to test.
2. Use the C++ library and write a ProtocolHandler (e.g InMemoryProtocolHandler) to deal with http/https requests and stub things out that that level.  Here's an example of crating a WebContents with a ProtocolHandler.  If you want your ProtocolHandler to conditionally make real http requests, tale a look at  DeterministicHttpProtocolHandler::MaybeCreateJob which uses HttpURLFetcher to fetch resources.


On 21 February 2017 at 00:46, <ja...@getadmiral.com> wrote:
What's the best way via the debugging protocol to modify/rewrite a request and it's response? For tests, we'd like to have predictable returns from external APIs and therefore we'd like to either be able to rewrite the destination (say, to our own server) or rewrite the response body.

Thanks!

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev+unsubscribe@chromium.org.
To post to this group, send email to headle...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/headless-dev/6953e215-1ab7-42bf-a372-23d1960d1cc4%40chromium.org.

Sami Kyostila

unread,
Feb 21, 2017, 7:48:21 AM2/21/17
to Alex Clarke, ja...@getadmiral.com, headless-dev
Thanks Alex. Another option would be to extend the debugging protocol to allow this. If you think that's important for your use case, please file a bug here: https://bugs.chromium.org/p/chromium/issues/entry?labels=Proj-Headless

- Sami

ti 21. helmik. 2017 klo 8.37 'Alex Clarke' via headless-dev <headle...@chromium.org> kirjoitti:
The devtools protocol doesn't really support that use case.  I'd suggest one of the following options:

1. Write a proxy to stub out the APIs you want to test.
2. Use the C++ library and write a ProtocolHandler (e.g InMemoryProtocolHandler) to deal with http/https requests and stub things out that that level.  Here's an example of crating a WebContents with a ProtocolHandler.  If you want your ProtocolHandler to conditionally make real http requests, tale a look at  DeterministicHttpProtocolHandler::MaybeCreateJob which uses HttpURLFetcher to fetch resources.

On 21 February 2017 at 00:46, <ja...@getadmiral.com> wrote:
What's the best way via the debugging protocol to modify/rewrite a request and it's response? For tests, we'd like to have predictable returns from external APIs and therefore we'd like to either be able to rewrite the destination (say, to our own server) or rewrite the response body.

Thanks!

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.

To post to this group, send email to headle...@chromium.org.

James Hartig

unread,
Feb 21, 2017, 9:20:48 AM2/21/17
to Sami Kyostila, Alex Clarke, headless-dev
Thanks Alex and Sami! I've filed: https://bugs.chromium.org/p/chromium/issues/detail?id=694547

While I don't know C++, until the devtools protocol supports this, I'll try playing around with learning C++ and writing those protocols in the mean time.

On Tue, Feb 21, 2017 at 7:48 AM, Sami Kyostila <skyo...@chromium.org> wrote:
Thanks Alex. Another option would be to extend the debugging protocol to allow this. If you think that's important for your use case, please file a bug here: https://bugs.chromium.org/p/chromium/issues/entry?labels=Proj-Headless

- Sami

ti 21. helmik. 2017 klo 8.37 'Alex Clarke' via headless-dev <headle...@chromium.org> kirjoitti:
The devtools protocol doesn't really support that use case.  I'd suggest one of the following options:

1. Write a proxy to stub out the APIs you want to test.
2. Use the C++ library and write a ProtocolHandler (e.g InMemoryProtocolHandler) to deal with http/https requests and stub things out that that level.  Here's an example of crating a WebContents with a ProtocolHandler.  If you want your ProtocolHandler to conditionally make real http requests, tale a look at  DeterministicHttpProtocolHandler::MaybeCreateJob which uses HttpURLFetcher to fetch resources.

On 21 February 2017 at 00:46, <ja...@getadmiral.com> wrote:
What's the best way via the debugging protocol to modify/rewrite a request and it's response? For tests, we'd like to have predictable returns from external APIs and therefore we'd like to either be able to rewrite the destination (say, to our own server) or rewrite the response body.

Thanks!

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev+unsubscribe@chromium.org.

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev+unsubscribe@chromium.org.

To post to this group, send email to headle...@chromium.org.
Reply all
Reply to author
Forward
0 new messages