I am learning Play Framework in Java.
I cannot get a clear understanding of the difference between a Response and a Result. I mean, what is actually sent back, Result or both? Is Response part of Result?
I've been trying to look at the source code. Response contains Cookies and a Map as headers. Result contains Cookies and ResponseHeader, and more stuff like body and session. So there is some overlap.
What confuses me more is code like this:
public Result index() {
response().setHeader(CACHE_CONTROL, "max-age=3600");
response().setHeader(ETAG, "xxx");
return ok("<h1>Hello World!</h1>").as("text/html");
}
I traced the ok() function calling in source code to constructor functions of Result, and it seems not using any data from the Response object in Context that is returned by response() function.
So my questions are:
So the cookies and headers in Response will be finally combined with cookies and headers in Result by the Framework before sent back?
And, if so, What's the rationale of making 2 classes rather than one, and put cookies/headers in 2 places?
If not, does Result includes Response data in someway I have not discovered?