Search code examples
http-status-codes

What is an appropriate response header for language filter fail?


I'm checking for vulgar language via an http request. If the string in question turns out to contain a bad word, what response Status-Code should I send back? I considered just 200 (along with badWord, or something).

Edit: There's other work that will not occur in the request if the string contains a bad word(s). On the other hand if there is not a bad word(s) then it will complete the work.


Solution

  • 2xx status code indicate that the server received, understood and accepted the request. It doesn't seem to be the case though.

    In your question, it's not clear what bad word means, but if you intend to refuse the request due to a client error, you should consider 4xx status codes. Assuming that the syntax of the message is correct but the semantic is not, you could return 422 to indicate that the message cannot be processed by the server:

    11.2. 422 Unprocessable Entity

    The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415 (Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions. For example, this error condition may occur if an XML request body contains well-formed (i.e., syntactically correct), but semantically erroneous, XML instructions.