POST method without body for testing


(Aditya Athalye) #1

Currently using Play 2.6.13 (play-test_2.12-2.6.13)
Using the following API

final FakeRequest request =
                        new FakeRequest(POST, "<somurl>").withHeader("<myheader>", "headervalue");

final Result result = Helpers.route(fakeApplication, request);

This the above FakeRequest is a POST without body.
This seems to throw an NPE in Helpers.scala as it expects a non null body

// Java compatibility
  def jRoute[T](app: Application, r: RequestHeader, body: RequestBody): Option[Future[Result]] = {
    route(app, r, body.asBytes())
  }

As per my understanding, POST need not have a body. http://lists.w3.org/Archives/Public/ietf-http-wg/2010JulSep/0276.html

If so, is the above behaviour a bug, or I am missing something?


(Marcos Pereira) #2

Hi @aditya,

Yes, I agree this looks like a bug.

A current workaround would be to set an empty body explicitly:

Http.Request request = Helpers.fakeRequest().bodyRaw(ByteString.empty()).build();
Helpers.route(app, request);

I appreciate if you can open an issue on Github so that we can add it to our todo list. :slight_smile:

Thanks!


(Aditya Athalye) #3

Hi @marcospereira

Sure. I will open an issue on github and attach it here too.

Thanks
Aditya


(Aditya Athalye) #4

@marcospereira Here is the github issue.