Problem/Motivation
If you have an empty view result you want to change the actual HTTP response code to 404/403 for example, so google knows what is going on.
Proposed resolution
Add an area handler which alters the http response similar to the title area handler which allows you to change the title of the page.
| Comment | File | Size | Author |
|---|---|---|---|
| #56 | vdc-1849356-56.patch | 6.29 KB | dawehner |
| #56 | interdiff.txt | 793 bytes | dawehner |
| #54 | vdc-1849356-54.patch | 6.29 KB | dawehner |
| #54 | interdiff.txt | 631 bytes | dawehner |
| #52 | vdc-1849356-52.patch | 6.31 KB | dawehner |
Comments
Comment #1
dawehnerThe actual response seems to have problems.
Comment #2
dawehnerLet's use some funny http status code and fix the tests
Comment #4
dawehnerThis feels like a bug in the depths of drupal, as it just don't work for pages with forms.
Comment #5
dawehnerHere is a proove that something doesn't work with the response object, wow.
Comment #6
dawehnerWrong patch.
Comment #8
dawehnerFilled a new issue for that #1865116: Form submit doesn't work when using response objects
Comment #9
dawehnerOH you have to drupal_render_page() the actual output...
Comment #10
Crell commentedQuestion. If the Area response is returning a status code, how do you control what the actual response body is? (Most response codes can have a legal body, unless the request was a HEAD request, but that's already handled by Symfony.)
Comment #11
dawehnerThe actual body of the response is the actual body of the view, so it could be an empty text. This handler just alters the response code.
Comment #12
tim.plunkettNitpicks!
s/http/HTTP
*whistles* That is nice :)
Except I'm not sure about t($title), can we get away with that?
Tests
Out of scope ;)
Comment #13
dawehnerThank you for the review, good points.
I don't think we can get rid of t($title), unless we want to hardcode the strings in that class and not pull it from symfony directly,
as it's the case currently.
Funny, you spotted "Test" but not "tha".
PS: The removed change in ViewExecutable is not part of the interdiff.
Comment #14
dawehnerSo
Comment #15
Crell commentedt($title) is not sufficient as it doesn't make the strings translatable. Check with Gabor or Karen about how we handled timezone labels for Drupal 7. We'll have to do the same.
Comment #16
dawehnerHere is a screenshot to show the editing.
Comment #17
gábor hojtsyI think these are standard HTTP names, not sure why would we want to translate them. If we do want to translate them anyway, a list of the code names as t()ed strings somewhere in the code (no need for them to actually be executed ever, just for static code parsing) is sufficient.
Comment #18
Crell commentedNitpick: It would probably look better with the numbers first, then the string, so that it aligns better. That's also how it is usually expressed in the HTTP response.
Comment #19
gábor hojtsyAgreed with Crell.
Comment #20
dawehnerThank you for your opinions, so here is a new version.
Comment #22
dawehner#20: drupal-1849356-20.patch queued for re-testing.
Comment #24
dawehner#20: drupal-1849356-20.patch queued for re-testing.
Comment #26
dawehnerWow wouldn't have thought that this error could have been caused by a test config file, which haven't been moved to test_views.
Comment #27
Crell commentedI think that takes care of everything except translation. It looks like currently it would always show the English version of the status text; whether or not that's acceptable I will defer to Gabor.
Comment #28
dawehnerWe discussed in IRC that this is not needed, see
Comment #29
Crell commentedCool. Then let's do that.
Comment #30
tim.plunkett#26: drupal-1849356-26.patch queued for re-testing.
Comment #31
dawehner#26: drupal-1849356-26.patch queued for re-testing.
Comment #32
damiankloip commentedcodes
I guess we should be doing this now anyway, nice.
This comment has the wrong status code, do we want a test for 403? Or should we just change this to 418?
Happy to rtbc this again when they are done..
Comment #33
dawehnerThank you very much!
Comment #34
damiankloip commentedLooks good!
Comment #35
tim.plunkett#33: drupal-1849356-33.patch queued for re-testing.
Comment #37
dawehnerRerolled
Comment #38
dawehnerback to rtbc
Comment #39
tim.plunkett#37: drupal-1849356-37.patch queued for re-testing.
Comment #40
webchickSo this patch doesn't seem to be working. Most likely it broke somewhere along the line between mid-January and now. I set my Views header to output a 500 error and nothing happens on view, neither did it on a 404 or 403. So needs work for that.
However, I'm not sure about this feature in general for core. While I see why it's wanted, it seems like a *very* advanced thing that wouldn't make sense to at least 80% of users. And heck, leave alone 80% of users. I'm a full-fledged geek, and even I don't know what about 90% of these HTTP status codes are and why I would ever use them:
"425 (Reserved for WebDAV advanced collections expired proposal)"? Really?
PS: We shouldn't be double-escaping "It's a teapot"; the test for that is GREAT though. :D
And unfortunately, thanks to the magical power of the alphabet, this exceptionally geeky option is the very first thing that shows up in the list of stuff to add to a header/footer. :\
If we want this feature for core, it seems like it'd be much better to be just a simple 403/404 selector on the empty text plugin. I dunno, thoughts?
Comment #41
damiankloip commentedHmm, I can see where you're coming from. I think I would prefer to keep the feature more as-is with the codes. Core does have some advanced features, but I also appreciate that alot of people will not use this anyway :) However, we would then have to re implement another handler that does exactly the same to include other status codes.
How about we put the 'popular' codes at the top of the list?
Comment #42
dawehnerYeah I think putting the common ones at the top would certainly help.
I'm wondering whether we might want to have a list for the common ones and just a textfield for all the others?
Comment #43
xjmLet's not forget 200. ;) That should be at the top of the list...
However, I'm thinking having both a text field and a select box would be odd. Maybe just a text field, and do validation against Symfony's allowed values. (We could also use Symfony to provide a label when a status code is set.)
Comment #44
dawehnerAren't you just not adding the area, if you want 200 as result?
Comment #45
Crell commentedPerhaps a case for http://caniuse.com/#search=datalist
Comment #46
dawehner80% usecase vs. restrict stuff for users. I personally think that only advanced users will care about this feature at all.
Comment #47
dawehnerOkay, let's move the important ones to the top.

Comment #48
olli commentedBack to rtbc per #40. I was able to change my front page response code to 500.
Comment #49
damiankloip commentedInstead of reassigning each time, we could just have one array that contains all 4 of these codes and then
+ $options. I know there was also talk of this above, but why do we want 200 in here?We could just do this on one line and not bother assigning the variable?
na ah
This only really makes sense for empty results, no? we could add
'sub_type' => 'empty',to the views area data?Comment #50
dawehnerI think we should not restrict users, if not really necessary. People come up with a lot of different usecases.
Comment #51
damiankloip commentedSorry, I guess 200 needs to go from here too.
The rest is looking great now. Just one thing...
The only thing is that I think we should just remove the 200 code form the list. It doesn't make any sense in there, as all responses we return will be 200 anyway. So really it is completely redundant. Removing it from the top of the list is a good start though :) This is not really blocking this patch (it's good).
Comment #52
dawehnerLet's not force something which might users expect.
Comment #53
olli commentedLet's remove/change these too.
The only thing I'd be missing with this is the ability to set Location header with certain status codes.
Comment #54
dawehnerOH good idea, maybe we could create a follow up. That would be powerful for SEO people (*shudder*).
Comment #55
olli commentedStill needs work for double-escaping "It's a teapot"...
About the select list, what about simple grouping like 1xx Informational, 2xx Success, ..?
Comment #56
dawehnerGood idea with the grouping.
Can we add the grouping in another followup? There will be discussions for ages around the way we order the informations. For example should the 200 group be in front of the 100 group,
or should just 200,403,404 be in front of the other groups etc.
Comment #58
dawehner#56: vdc-1849356-56.patch queued for re-testing.
Comment #59
olli commentedYou are right. Back to rtbc.
Comment #60
dawehnerThank you very much.
Comment #61
tim.plunkett#56: vdc-1849356-56.patch queued for re-testing.
Comment #62
alexpottI reviewed this an the code is code to go and from my side this should go in. @catch thinks that the use of an area handler is weird but this was discussed for the page title area handler and no better solution was found. Therefore...
Committed 5dba5f6 and pushed to 8.x. Thanks!
Comment #64
dwwDear folks who added this cool feature, RFC: #2959415: When a view uses the HTTPStatusCode handler to set a 404 or 403, throw the appropriate exception
Thanks,
-Derek