Load Performance Testing with Gatling and Content-Type

I use gatling to test load performance on a completely new API. This seems pretty easy and well documented, but I ran into the problem as simple as a POST request with the Content-Type set to "application / vnd.api + json" in the header. Everything works fine when you do a GET, but when I run the POST test, I get

HTTP response: status= 415 Unsupported Media Type headers= cache-control: [no-cache] Content-Type: [application/vnd.api+json; charset=utf-8] Date: [Fri, 08 Sep 2017 12:57:10 GMT] Server: [nginx] Vary: [Origin] x-content-type-options: [nosniff] x-frame-options: [SAMEORIGIN] X-Request-Id: [ff993645-8e01-4689-82a8-2f0920e4f2a9] x-runtime: [0.040662] x-xss-protection: [1; mode=block] Content-Length: [218] Connection: [keep-alive] body= {"errors":[{"title":"Unsupported media type","detail":"All requests that create or update must use the 'application/vnd.api+json' Content-Type. This request specified 'application/json'.","code":"415","status":"415"}]} 

Here is the scala code that I use for the http request:

 object PostTokenGcm { val token = exec { http("TestAPI POST /tokens") .post("/tokens") .headers(Map("Authorization" -> testApiToken, "Content-Type" -> "application/vnd.api+json", "Accept" -> "application/vnd.api+json" )) .body(StringBody(gcmTokenRequestBody)).asJSON .check(status.is(201)) .check(bodyString.exists) }} 

Doesn't it seem to set Content-Type?

Thanks for the lead!

+5
source share
1 answer

In the POST definition, you are using asJSON . According to the notes in the documentation of the request headers :

http ("foo"). get ("bar"). asJSON is equivalent to:

  http ("foo"). get ("bar")
   .header (HttpHeaderNames.ContentType, HttpHeaderValues.ApplicationJson)
   .header (HttpHeaderNames.Accept, HttpHeaderValues.ApplicationJson) 

... therefore, the headers are set to:

  .headers (Map ("Authorization" -> testApiToken,
        "Content-Type" -> "application / vnd.api + json",
         "Accept" -> "application / vnd.api + json")) 

... overwrite asJSON to "application/json" (which is the value of HttpHeaderValues.ApplicationJson ).

+6
source

Source: https://habr.com/ru/post/1271644/


All Articles