Cory Klein
Cory Klein

Reputation: 55690

HTTP response code for request that is too complicated or difficult to compute

Say I have a server that calculates factorials:

> GET localhost:8080/factorial/10

200 3628800

In my analytics 99% of my users ask for factorials that are computationally cheap to calculate, but most of my CPU time goes towards the 1% of users that want to know factorial(100+).

Now, I know how to calculate factorial(100), I just don't want to, so I'm not going to fulfill these requests. What HTTP code should I respond with?

Note: factorial is just an example - in reality there is no hard and fast way for me to determine ahead of time which request will be too expensive and which won't, I have to decide on a case-by-case basis for each request and some will get an HTTP 200 back with their result, and others will get rejected.

Upvotes: 1

Views: 395

Answers (1)

Aaron
Aaron

Reputation: 7145

Seems to me that if your server doesn't want to respond to such a request and its not the client's fault then perhaps a 5xx error makes sense? Maybe a 501 based on wikipedia's definition makes sense?

I would return a 500 with an error message to indicate the server's intention to explicitly not respond to such requests, but that's me.

Upvotes: 1

Related Questions