Advertisement
mitrakov

Play: json headers

Aug 19th, 2018
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.02 KB | None | 0 0
  1. // Does Play Framework add Content-Type headers automatically?
  2. import javax.inject.Inject
  3. import play.api.libs.json.Json
  4. import play.api.mvc._
  5.  
  6. class TestController @Inject() (
  7.     cc: ControllerComponents,
  8.   ) extends AbstractController(cc) {
  9.  
  10.   // add to routes: GET    /test/json    controllers.TestController.simpleJson
  11.   def simpleJson = Action {
  12.     Ok(Json.obj("key" -> 5, "value" -> List(1, 2, 3)))
  13.   }
  14. }
  15.  
  16. // Call: http://localhost:9000/test/json
  17. // Output: {"key":5,"value":[1,2,3]}
  18. // Headers:
  19.     Content-Length                        25
  20.     Content-Security-Policy               default-src 'self'
  21.     Content-Type                          application/json
  22.     Date                                  Sun, 19 Aug 2018 19:17:51 GMT
  23.     Referrer-Policy                       origin-when-cross-origin, strict-origin-when-cross-origin
  24.     X-Content-Type-Options                nosniff
  25.     X-ExampleFilter                       foo
  26.     X-Frame-Options                       DENY
  27.     X-Permitted-Cross-Domain-Policies     master-only
  28.     X-XSS-Protection                      1; mode=block
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement