0

I saw there are several related posts, but none really answered my questions.

To be specific, let's say there are some middle layers in front of the request handlers (e.g. web server, Spring framework, Jersey framework, etc). The request handler explicitly announced that it expects a JSON request.

Question 1 - if the client sends a valid JSON request, but set the content-type to be text/plain, is it valid situation for the middle layers NOT to deliver the request to the request handler because of the content-type?

Question 2 - if the client sends a valid JSON request and using content-type application/json, and the request handler announces that it will parse the JSON request by itself. Can I assume some real world implementations of the middle layers will still verify the request before passing it to the request handler? (in other words - is it valid to assume that application/json may cause performance loss?)

1 Answer 1

1
  1. All application/json content is also valid text/plain, so I don't see how a middle layer validation could catch that. It doesn't make sense for it to reject the request, unless it knows the request semantics which is supposed to be the responsibility of the request handler. The opposite case would make sense, with a failure when sending plain text payload that's an invalid JSON document with application/json.

  2. The middle layer may validate if the payload with application/json is valid, but to worry about performance loss at this point is pointless. If after profiling your application you realize that this validation is a bottleneck, then it's valid to worry about it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.