Jump to content

PW 3.0.166 – Core updates


ryan
 Share

Recommended Posts

@ryan looks like a nice set of improvements, thank you.

With regard to the new location() method, I can understand the move away from the second parameter in the existing redirect() call as it is a little confusing.  Although this isn't in the spirit of the move to simplify, if I wanted to do a 303 redirect would I have to manually set the location header using sendHeader() and then return a 303 via sendStatusHeader()?  I wonder if the existing redirect() call be changed to accept either the existing bool or an int for the second parameter? In the case of an int, maybe one of the 300 (301/302/303/307/308) codes could explicitly be passed and used as the return code. That would certainly make its use more explicit and more intuitive than the existing none/true/false as the second parameter.

Regardless, excellent work as usual.

  • Like 1
Link to comment
Share on other sites

@netcarver You'll be glad to know that's exactly what changed with the redirect method in 3.0.166— The optional 2nd argument is now an http status code, enabling you to send any redirect status that you want, so long as it's somewhere in between 300 and 399. So if you wanted to send a 303 "see other" redirect, then you would do it like this:

$session->redirect('http://domain.com/path', 303); 

The method of course also still accepts true or false to mean 301 and 302, and the default is still 301. The new location() method sends only a "Location: url" header without an http status code, which browsers interpret as a temporary redirect.

  • Like 2
Link to comment
Share on other sites

4 hours ago, ryan said:

The new location() method sends only a "Location: url" header without an http status code, which browsers interpret as a temporary redirect.

The spec for http 1.1 (rfc 7231) only specifies the behaviour of the location header for http 201 and 3xx. I'm not sure it's a good idea to depend on undocumented behaviour of not setting a proper 3xx status code. Especially as this seems to happen even when explicitly calling:

$session->redirect($url, 302);

This not setting a http status code is waiting to cause people trouble. One isn't always dealing with browsers, which are usually quite forgiving.

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...