http-status-codes

Correct http status code for resource which requires authorization

对着背影说爱祢 提交于 2019-12-20 08:04:14
问题 There seems to be a lot of confusion about the correct http status code to return if the user tries to access a page which requires the user to login. So basically what status code will be send when I show the login page? I'm pretty sure we need to use a status code in the 4xx range. I'm not talking about HTTP authentication here, so that's at least 1 status code we aren't going to use ( 401 Unauthorized ). Now what should we use? The answers (also here on SO) seem to vary: According to the

How to undo a 301 redirect?

百般思念 提交于 2019-12-19 06:26:08
问题 Now, I don't have any problems with 301 redirects, but one person asked me for the way to undo cached 301 redirects for browsers and search engines, so I replied "by doing a 301 redirect back to the original url", at least thats what I thought was the solution, until I saw people mentioning that you can't do a 301 redirect back http://getluky.net/2010/12/14/301-redirects-cannot-be-undon/ http://www.velocityreviews.com/forums/t500058-undo-301-redirect.html this was a surprise and I don't know

Specify supported media types when sending “415 unsupported media type”

南楼画角 提交于 2019-12-19 05:16:08
问题 If a clients sends data in an unsupported media type to a HTTP server, the server answers with status "415 unsupported media type". But how to tell the client what media types are supported? Is there a standard or at least a recommended way to do so? Or would it just be written to the response body as text? 回答1: There is no specification at all for what to do in this case, so expect implementations to be all over the place. (What would be sensible would be if the server's response included

Specify supported media types when sending “415 unsupported media type”

故事扮演 提交于 2019-12-19 05:16:08
问题 If a clients sends data in an unsupported media type to a HTTP server, the server answers with status "415 unsupported media type". But how to tell the client what media types are supported? Is there a standard or at least a recommended way to do so? Or would it just be written to the response body as text? 回答1: There is no specification at all for what to do in this case, so expect implementations to be all over the place. (What would be sensible would be if the server's response included

HTTP status code for “success with errors”?

时光总嘲笑我的痴心妄想 提交于 2019-12-18 21:54:33
问题 I've poked around a bit, but I don't see an HTTP status code for when a request's succeeds, but there is an error after the "point of no return". e.g., Say you process a request, its committed to the database, but while returning the result you run of memory, or encounter a NPE, or what have you. It would have been a 200 response, but now, internally, you aren't able to return the proper, well-formed response. 202 Accepted doesn't seem to fit since we've already processed the request. What

Correct HTTP status code for existent resource, but non-existent entity?

徘徊边缘 提交于 2019-12-18 18:57:36
问题 Say the client is requesting the following URL: /user-details?user=123 If /user-details was a non-existing resource, the correct status code would obviously be 404 . However if /user-details does exist, but no user with id 123 exists: I've so far returned a 404 Not Found , but experience has told me that it makes it confusing to not know whether it is the resource , or the entity that was not found; I've considered using 400 Bad Request , but I find it confusing as well, as the request is

Which HTTP code to use for an empty subresource in a REST API?

自作多情 提交于 2019-12-18 12:59:10
问题 Let's say I've a resource articles at /articles . These articles may have related articles, so I fetch them by GETting /articles/{id}/related . What should I return is there is no related articles? I can think of: 404 Not Found , maybe with an empty collection 204 No Content 200 Found with an empty collection Any advices? (please give arguments) By the way, it may applies to pagination. If I request page 3 of 2, then the page 3 will return an empty set, should It be a 404 ? 回答1: 404 is not

Make PHP page return “304 Not Modified” if it hasn't been modified

独自空忆成欢 提交于 2019-12-18 04:18:07
问题 I have a PHP file that will return the same thing with the same $_GET parameters every time -- it's deterministic. Unfortunately for efficiency (this file is requested very often), Apache defaults to a "200 OK" response whenever a PHP page is requested, making the user download the file again. Is there any way to send a 304 Not Modified header if and only if the parameters are the same? Bonus : Can I set an expiry time on it, so that if the cached page is more than, say, three days old, it

After a POST, should I do a 302 or a 303 redirect?

元气小坏坏 提交于 2019-12-17 22:17:30
问题 A common scenario for a web app is to redirect after a POST that modifies the database. Like redirecting to the newly created database object after the user creates it. It seems like most web apps use 302 redirects, but 303 seems to be the correct thing to do according to the specification if you want the url specified in the redirect to be fetched with GET. Technically, with a 302, the browser is supposed to fetch the specified url with the same method that the original url was fetched with,

Python CGI returning an http status code, such as 403?

本秂侑毒 提交于 2019-12-17 20:35:00
问题 How can my python cgi return a specific http status code, such as 403 or 418? I tried the obvious (print "Status:403 Forbidden") but it doesn't work. 回答1: print 'Status: 403 Forbidden' print Works for me. You do need the second print though, as you need a double-newline to end the HTTP response headers. Otherwise your web server may complain you aren't sending it a complete set of headers. sys.stdout('Status: 403 Forbidden\r\n\r\n') may be technically more correct, according to RFC (assuming