Modify HTTP request parameters

1,372 views
Skip to first unread message

Jeenu

unread,
Nov 27, 2011, 2:25:31 AM11/27/11
to Chromium-extensions
Hi,

I'm aware of the webRequest experimental API supported by Chromium.
AFAIU, it only lets me modify the HTTP request headers, and not
request parameters. What I wanted to do is something like intercept a
GET/POST request, store it locally, and maybe retry it if fails with
altered parameters. Is there anyway that I can do that in Chromium?

Thanks.

--
Jeenu

Ben

unread,
Nov 27, 2011, 3:45:56 AM11/27/11
to Jeenu, Chromium-extensions

Do you want to alter the parameters if the request fails, then retry, or
alter the parameters and retry if the request fails?

What parameters do you want to modify?

Are you referring to the query strings? ("?foo=bar&baz" in
"http://example.org/?foo=bar&baz", for example)? In that case, you can
use onBeforeRequest to store the original url, redirect to your modified
url (or vice versa), and use onCompleted with the given requestid to
check whether it was successfully completed.

onBeforeSendHeaders should work as usual/expected when redirecting.

I'm not sure if you can modify POST requests in the same way as
above--you may need to use onBeforeSendHeaders, and I don't know if that
header is available. Neither am I sure how you would retry; I guess it'd
depend on how the request was made, if it's possible at all.

Ben

unread,
Nov 27, 2011, 3:59:40 AM11/27/11
to Jeenu, Chromium-extensions
On Sun, 2011-11-27 at 02:45 -0600, Ben wrote:
> Do you want to alter the parameters if the request fails, then retry, or
> alter the parameters and retry if the request fails?

Both of those mean the same thing. XD

What I meant to ask was, do you want to:
A: Alter the parameters if the request fails, then retry with altered
parameters, or

B: Store the original parameters, request with altered parameters, then
retry with original if the request fails.

For those of us who find pseudo-code clearer:
C: params = [a,b,c]; request(params); if (fail()) request([b,a,c]); //A
D: params = [a,b,c]; request([b,a,c]); if (fail()) request(params); //B

Jeenu V

unread,
Nov 27, 2011, 11:45:33 AM11/27/11
to Chromium-extensions
On Sun, Nov 27, 2011 at 2:29 PM, Ben <benj...@gmail.com> wrote:
> What I meant to ask was, do you want to:
>  A: Alter the parameters if the request fails, then retry with altered
> parameters, or
>
>  B: Store the original parameters, request with altered parameters, then
> retry with original if the request fails.
>
> For those of us who find pseudo-code clearer:
>  C: params = [a,b,c]; request(params); if (fail()) request([b,a,c]); //A
>  D: params = [a,b,c]; request([b,a,c]); if (fail()) request(params); //B

I'd say I wanted to do A. But despite the order I want to do/store
things, what I essentially want to do is to manipulate the request.

> Are you referring to the query strings? ("?foo=bar&baz" in
> "http://example.org/?foo=bar&baz", for example)? In that case, you can
> use onBeforeRequest to store the original url, redirect to your modified
> url (or vice versa), and use onCompleted with the given requestid to
> check whether it was successfully completed.

Yes, I suppose that's what I would now do with GET requests.

> I'm not sure if you can modify POST requests in the same way as
> above--you may need to use onBeforeSendHeaders, and I don't know if that
> header is available. Neither am I sure how you would retry; I guess it'd
> depend on how the request was made, if it's possible at all.

I'm more interested in retrying POST requests, which is what I'm not
clear about. The API page doesn't mention about exposing any of the
POST request parameters to any of the callbacks. Nor does it mention
so about GET requests, but in that case URL is enough for us.

I didn't quite get to what you mean by the 'how the request was made'.
Did you mean the encoding scheme for the POST request? Assuming I've a
way to know that beforehand, do you see anyway to manipulate POST
request parameters?

Thanks.

--
Jeenu

Ben

unread,
Nov 27, 2011, 1:28:31 PM11/27/11
to Jeenu V, Chromium-extensions

see reply inline

On Sun, 2011-11-27 at 22:15 +0530, Jeenu V wrote:
> On Sun, Nov 27, 2011 at 2:29 PM, Ben <benj...@gmail.com> wrote:
> > What I meant to ask was, do you want to:
> > A: Alter the parameters if the request fails, then retry with altered
> > parameters, or
> >

> > For those of us who find pseudo-code clearer:
> > C: params = [a,b,c]; request(params); if (fail()) request([b,a,c]); //A
>

> I'd say I wanted to do A. But despite the order I want to do/store
> things, what I essentially want to do is to manipulate the request.
>
> > Are you referring to the query strings? ("?foo=bar&baz" in
> > "http://example.org/?foo=bar&baz", for example)? In that case, you can
> > use onBeforeRequest to store the original url, redirect to your modified
> > url (or vice versa), and use onCompleted with the given requestid to
> > check whether it was successfully completed.
>
> Yes, I suppose that's what I would now do with GET requests.
>
> > I'm not sure if you can modify POST requests in the same way as
> > above--you may need to use onBeforeSendHeaders, and I don't know if that
> > header is available. Neither am I sure how you would retry; I guess it'd
> > depend on how the request was made, if it's possible at all.
>
> I'm more interested in retrying POST requests, which is what I'm not
> clear about. The API page doesn't mention about exposing any of the
> POST request parameters to any of the callbacks. Nor does it mention
> so about GET requests, but in that case URL is enough for us.

Yeah, from what I can tell there's no way to modify parameters of a GET
request other than to change the url. And according to [0], they
currently don't allow you to modify the "content-length" header, so they
likely don't allow you to change POST parameters either. You can file a
feature request on http://new.crbug.com/

> I didn't quite get to what you mean by the 'how the request was made'.
> Did you mean the encoding scheme for the POST request? Assuming I've a
> way to know that beforehand, do you see anyway to manipulate POST
> request parameters?

Basically, what I meant was you probably would need to know whether the
request came from a tab, or an iframe, or some other element on a page
(and which tab that page/element is on). Of course you wouldn't need to
know that if there was some extension api that allowed you to retry a
request, but without one I would imagine it'd be pretty cumbersome.

>
> Thanks.
>

No problem, glad to help. ^_^

> --
> Jeenu
>

[0]http://code.google.com/chrome/extensions/experimental.webRequest.html#life_cycle_footnote

Dominic Battre

unread,
Nov 27, 2011, 4:29:50 PM11/27/11
to Jeenu V, Chromium-extensions
On Sun, Nov 27, 2011 at 5:45 PM, Jeenu V <gro...@jeenuv.otherinbox.com> wrote:
On Sun, Nov 27, 2011 at 2:29 PM, Ben <benj...@gmail.com> wrote:
> What I meant to ask was, do you want to:
>  A: Alter the parameters if the request fails, then retry with altered
> parameters, or
>
>  B: Store the original parameters, request with altered parameters, then
> retry with original if the request fails.
>
> For those of us who find pseudo-code clearer:
>  C: params = [a,b,c]; request(params); if (fail()) request([b,a,c]); //A
>  D: params = [a,b,c]; request([b,a,c]); if (fail()) request(params); //B

I'd say I wanted to do A. But despite the order I want to do/store
things, what I essentially want to do is to manipulate the request.

The webRequest API provides neither access to the POST request body nor does it allow you to create new requests.

The problem of POST request parameters is that they can be pretty large (think of a file attachment).

Creating new requests is extremely difficult because it would require some context within the browser (who sent the request? is it part of a resource referenced from the DOM? ...). It might be possible to trigger another redirection in case of a error code in the response before reporting the error to the renderer. This would be pretty difficult, though, so we would need a really good use case.  

Best regards,
Dominic
Reply all
Reply to author
Forward
0 new messages