Th 00 mÄ s
Th 00 mÄ s

Reputation: 3826

How to access request body in scala play via asText if header is missing content type

An incoming request in my play application does not have the content-type headers attribute set. This makes accessing the body via

request.body.asText

problematic, as it seems the automatic parsing only provides the body via

request.body.asRaw

How can I handle the missing content-type attribute, to still be able to access the body (assuming it is parse able) via ".asText"

Upvotes: 1

Views: 367

Answers (1)

johanandren
johanandren

Reputation: 11479

The tolerantText body parser will ignore the content type headers:

object MyController extends Controller {

  def action = Action(parse.tolerantText) { req => 
    val text = req.body
    ...
  }
}

Upvotes: 4

Related Questions