ninenines / cowboy

Small, fast, modern HTTP server for Erlang/OTP.
https://ninenines.eu
ISC License
7.25k stars 1.16k forks source link

Implement RFC 7725 HTTP 451 Error Code #965

Open jcspencer opened 8 years ago

jcspencer commented 8 years ago

Recently, RFC #7725 was published and approved by the IESG. This RFC outlines the use of a new HTTP status code: "451 Unavailable For Legal Reasons".

The 451 status code could be described as a more descriptive variant of 403 Forbidden, as it can displayed to inform a user when they request an illegal resource, such as a web page censored by a government.

Originally proposed in 2013 by Tim Bray, it was approved by the IESG on December 18, 2015. It was published as RFC 7725 this Feburary.

If the response to the implementation of this is positive, I'll happily open a PR.

_Implementation Details_

Section 3 (451 Unavailable For Legal Reasons) source

For example:

HTTP/1.1 451 Unavailable For Legal Reasons
Link: <https://spqr.example.org/legislatione>; rel="blocked-by"
Content-Type: text/html

<html>
 <head>
   <title>Unavailable For Legal Reasons</title>
 </head>
 <body>
   <h1>Unavailable For Legal Reasons</h1>
   <p>
    This request may not be serviced in the Roman Province
    of Judea due to the Lex Julia Majestatis, which disallows
    access to resources hosted on servers deemed to be
    operated by the People's Front of Judea.
   </p>
  </body>
</html>
essen commented 8 years ago

As far as Cowboy is concerned, it should be little more than adding the code to the list of status codes. REST could also be improved but discussion is needed as to how exactly (probably extending the forbidden/2 call, but how?)

Gazler commented 6 years ago

Can't this be closed via https://github.com/ninenines/cowlib/blob/11e07d3c2b164d06ad35188d83ad70e7501396db/src/cow_http.erl#L324 ?

essen commented 6 years ago

That's the status code, but cowboy_rest has no interface for it. Should it? That's the question.