Is 418 “I'm a teapot” really an HTTP response

2020-05-20 05:35发布

问题:

Is 418 "I'm a teapot" really an HTTP response code?

There are various references to this on the internet, including in lists of response codes, but I can't figure out whether it's a weird joke.

回答1:

I use this code. I have nginx reverse-proxying requests to two separate HTTP servers. One handles requests for unauthenticated users, and the second handles requests for authenticated users. The problem in this particular case, is the first server is the one that determines if the user is authenticated. Please don't ask why.

So, if the first server determines the user is authenticated, it responds 418 I'm a teapot. NGINX then reroutes the traffic internally to the second server. As far as the browser is concerned, it was a single request.

This is in the spirit of HTCPCP code 418, because if you attempt to BREW with a teapot, the appropriate response is "I'm not the kind of thing that can handle that request, but there may be others." .. In other words, "I'm a teapot. Find a coffee maker." (the second server being the coffee maker).

Ultimately, while 418 is not explicitly defined in RFC 7231, it is still covered by the umbrella of 4xx (Client Error).

6. Response Status Codes

  • 4xx (Client Error): The request contains bad syntax or cannot be fulfilled

6.5. Client Error 4xx

  • The 4xx (Client Error) class of status code indicates that the client seems to have erred. Except when responding to a HEAD request, the server SHOULD send a representation containing an explanation of the error situation, and whether it is a temporary or permanent condition. These status codes are applicable to any request method. User agents SHOULD display any included representation to the user.


回答2:

HTTP response code 418 was originally defined in RFC 2324 ("Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0)") and RFC 7168 ("The Hyper Text Coffee Pot Control Protocol for Tea Efflux Appliances (HTCPCP-TEA)") protocols.

Per Wikipedia: List of HTTP status codes: #418

This code was defined in 1998 as one of the traditional IETF April Fools' jokes, in RFC 2324, Hyper Text Coffee Pot Control Protocol, and is not expected to be implemented by actual HTTP servers. The RFC specifies this code should be returned by teapots requested to brew coffee. This HTTP status is used as an Easter egg in some websites, including Google.com.



回答3:

Yes, I can confirm, that I've seen HTTP 418 coming back from a real production server. It does exist.



回答4:

I think it is safer to treat 418 as a reserved code that once had a half - official meaning but now officially "unassigned".

It not so stupid as it sounds, it is "Not implemented" (501). But it belongs to the wrong group and somehow was tied to a narrow group of kitchenware.

In other words, I would avoid using this code.



标签: http