什么是语言过滤器失败的适当响应 header?
What is an appropriate response header for language filter fail?
我正在通过 http 请求检查粗俗语言。如果有问题的字符串结果包含一个坏词,我应该发回什么响应 Status-Code?我只考虑了 200
(以及 badWord
或其他内容)。
编辑:如果字符串包含错误词,则请求中不会发生其他工作。另一方面,如果没有坏词,那么它将完成工作。
2xx
状态码表示服务器收到、理解并接受了请求。不过好像不是这样。
在你的问题中,不清楚 bad word 是什么意思,但是如果你打算由于客户端错误而拒绝请求,你应该考虑 4xx
status codes. Assuming that the syntax of the message is correct but the semantic is not, you could return 422
表示服务器无法处理消息:
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.
我正在通过 http 请求检查粗俗语言。如果有问题的字符串结果包含一个坏词,我应该发回什么响应 Status-Code?我只考虑了 200
(以及 badWord
或其他内容)。
编辑:如果字符串包含错误词,则请求中不会发生其他工作。另一方面,如果没有坏词,那么它将完成工作。
2xx
状态码表示服务器收到、理解并接受了请求。不过好像不是这样。
在你的问题中,不清楚 bad word 是什么意思,但是如果你打算由于客户端错误而拒绝请求,你应该考虑 4xx
status codes. Assuming that the syntax of the message is correct but the semantic is not, you could return 422
表示服务器无法处理消息:
11.2. 422 Unprocessable Entity
The
422
(Unprocessable Entity) status code means the server understands the content type of the request entity (hence a415
(Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a400
(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.