PerlDancer / Dancer2

Perl Dancer Next Generation (rewrite of Perl Dancer)
http://perldancer.org/
Other
543 stars 273 forks source link

Add 'is_forward' key to request on forward #1266

Open SysPete opened 7 years ago

SysPete commented 7 years ago

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

racke commented 7 years ago

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

SysPete commented 7 years ago

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.

pdl commented 7 years ago

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.

xsawyerx commented 7 years ago

Excellent point.

racke commented 7 years ago

Very good idea indeed.

xsawyerx commented 7 years ago

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 '/';
};