Dancer2 icon indicating copy to clipboard operation
Dancer2 copied to clipboard

Add 'is_forward' key to request on forward

Open SysPete opened this issue 9 years ago • 7 comments

Perhaps 'is_internal_forward'? Thoughts appreciated. Will sort a PR after #1246 is merged.

SysPete avatar Oct 07 '16 12:10 SysPete

What about forwarded_from with the original link? is_internal_forward - do we have external forwards?

racke avatar Oct 07 '16 12:10 racke

The question about naming is purely to make it clear that this is related to the use of the 'forward' keyword as opposed to the request having been forwarded to the app via a proxy.

SysPete avatar Oct 07 '16 13:10 SysPete

If including the URL, it would be useful for this to be stored as an arrayref, as it's possible to have multiple forwards, and sometimes you will be interested in the original URL, while on other occasions, you will be interested in the immediately preceding URL.

pdl avatar Oct 16 '16 19:10 pdl

Excellent point.

xsawyerx avatar Oct 16 '16 20:10 xsawyerx

Very good idea indeed.

racke avatar Oct 17 '16 06:10 racke

I'm now thinking that this might be a greater issue. If you think of forward, you might have multiple forward requests. you might want to track all of them. A pass does something similar and you might want to track that as well. Two different keys? One key?

My proposal is to implement this cleanly using var which exists for the particular purpose of retaining information between requests. Here's a native implementation:

get '/hello' => {
  push @{ vars->{'previous_reqs'} }, request->path;
  forward '/next';
};

This can also be wrapped in nicer syntax:

# This can be in a plugin
sub track {
  push @{ vars->{'previous_reqs'} }, request->path;
  return 1;
}

get '/hello' => sub {
    track and forward '/';
};

xsawyerx avatar Nov 06 '16 20:11 xsawyerx