Re-issue new request based on response?

100 views
Skip to first unread message

Klaus Johannes Rusch

unread,
Feb 2, 2010, 10:56:32 AM2/2/10
to Fiddler
Is there an easy way to re-issue a request based on the response, and
return that response to the client (or issue another request if
needed)?

The idea is to "hide" redirect responses and return the object from
the new location instead, so assuming http://example.com/1 redirects
to http://example.com/2, which in turn redirects to http://example.com/3,
a request to http://example.com/1 through Fiddler should return the
results of http://example.com/3, not the 301/302 response.

Thanks

--
Klaus Johannes Rusch
Klaus...@atmedia.net
http://www.atmedia.net/KlausRusch/

EricLaw

unread,
Feb 2, 2010, 5:35:16 PM2/2/10
to Fiddler
There's no *easy* way to do this. You could write a pretty complicated
script (or plugin) to do this, but it would be very interesting to
learn why this would be desirable.

On Feb 2, 7:56 am, Klaus Johannes Rusch <KlausRu...@atmedia.net>
wrote:


> Is there an easy way to re-issue a request based on the response, and
> return that response to the client (or issue another request if
> needed)?
>
> The idea is to "hide" redirect responses and return the object from
> the new location instead, so assuminghttp://example.com/1redirects

> tohttp://example.com/2, which in turn redirects tohttp://example.com/3,
> a request tohttp://example.com/1through Fiddler should return the
> results ofhttp://example.com/3, not the 301/302 response.


>
> Thanks
>
> --
> Klaus Johannes Rusch

> KlausRu...@atmedia.nethttp://www.atmedia.net/KlausRusch/

Klaus Johannes Rusch

unread,
Feb 2, 2010, 5:45:44 PM2/2/10
to Fiddler

On Feb 2, 11:35 pm, EricLaw <bay...@gmail.com> wrote:
> There's no *easy* way to do this. You could write a pretty complicated
> script (or plugin) to do this, but it would be very interesting to
> learn why this would be desirable.

I need to run an application that doesn't handle redirects well, so
trying to pretend the content is available at the URL that actually
sends a 302 response to another URL.

EricLaw

unread,
Feb 2, 2010, 6:30:40 PM2/2/10
to Fiddler
Oh, interesting.

You may be able to piggy-back on the work that I did for the request
builder's "follow redirects" feature in Fiddler 2.2.8.6....

Inside OnBeforeREQUEST, do this:

if (oSession.HostnameIs("whatevertarget.com"))
{
// Instruct Fiddler to itself follow up to two 3xx redirections...
oSession["x-Builder-MaxRedir"] = "2";
}

Note, of course, that when you do this, Fiddler will not pass the
redirect responses to the client. So, if the 3xx response, say, set a
cookie, that cookie will never be seen by the client.

On Feb 2, 2:45 pm, Klaus Johannes Rusch <KlausRu...@atmedia.net>
wrote:


> On Feb 2, 11:35 pm, EricLaw <bay...@gmail.com> wrote:
>
> > There's no *easy* way to do this. You could write a pretty complicated
> > script (or plugin) to do this, but it would be very interesting to
> > learn why this would be desirable.
>
> I need to run an application that doesn't handle redirects well, so
> trying to pretend the content is available at the URL that actually
> sends a 302 response to another URL.
>
> --
> Klaus Johannes Rusch

> KlausRu...@atmedia.nethttp://www.atmedia.net/KlausRusch/

Klaus Johannes Rusch

unread,
Feb 4, 2010, 4:03:39 AM2/4/10
to Fiddler

On Feb 3, 12:30 am, EricLaw <bay...@gmail.com> wrote:
> You may be able to piggy-back on the work that I did for the request
> builder's "follow redirects" feature in Fiddler 2.2.8.6....
>
> Inside OnBeforeREQUEST, do this:
>
> if (oSession.HostnameIs("whatevertarget.com"))
> {
> // Instruct Fiddler to itself follow up to two 3xx redirections...
> oSession["x-Builder-MaxRedir"] = "2";
>
> }

Fantastic, thanks Eric!

I also added the following to onBeforeResponse to pass the actual URL
to the client:

oSession.oResponse["Content-Base"] = oSession.url;
if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "text/
html")) {
oSession.utilDecodeResponse();
var oBody =
System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
if (!oBody.match(/<base/i)) {
oBody = oBody.replace(/<\/head>/gi, "<!-- Inserted by Fiddler
rule --><base href=\"" + encodeURI(oSession.url) + "\"><!-- end --></
head>");
oSession.utilSetResponseBody(oBody);

EricLaw

unread,
Feb 4, 2010, 9:44:48 AM2/4/10
to Fiddler
That's a neat addition! Of course, that code adds a BASE to every HTML
response, not just those that are a result of the redirection trick.

On Feb 4, 1:03 am, Klaus Johannes Rusch <KlausRu...@atmedia.net>
wrote:

> KlausRu...@atmedia.nethttp://www.atmedia.net/KlausRusch/

Klaus Johannes Rusch

unread,
Feb 4, 2010, 10:41:47 AM2/4/10
to Fiddler
EricLaw wrote:
> That's a neat addition! Of course, that code adds a BASE to every HTML
> response, not just those that are a result of the redirection trick.
>
That's right; it shouldn't do any harm since it matches the actual URL
for "normal" requests. The placement at the bottom of the head section
is a bit of a compromise, relative references earlier in the head
section may not work properly but adding a base tag early has some side
effects too.

Klaus Johannes Rusch

unread,
Feb 5, 2010, 3:59:02 AM2/5/10
to Fiddler
One small correction, should be oSession.fullURL :-)

// Silently follow redirects
if (m_redirects) {
oSession.oResponse["Content-Base"] = oSession.fullUrl;
if (oSession.oResponse.headers.ExistsAndContains("Content-Type",
"text/html")) {


oSession.utilDecodeResponse();
var oBody =
System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
if (!oBody.match(/<base/i)) {
oBody = oBody.replace(/<\/head>/gi, "<!-- Inserted by Fiddler

rule --><base href=\"" + encodeURI(oSession.fullUrl) + "\"><!-- end --
></head>");

Reply all
Reply to author
Forward
0 new messages