vlucas / frisby

Frisby is a REST API testing framework built on Jest that makes testing API endpoints easy, fast, and fun.
http://frisbyjs.com
1.52k stars 201 forks source link

Must not override content-type if supplied #259

Closed tiagolpadua closed 9 years ago

tiagolpadua commented 9 years ago

when we set json:true it overrides the content-type to application/json, in my case I need it to be application/json;charset=UTF-8

For example: frisby.create("POST client") .post( URL, { "name" : "Foo" } , {json: true, headers : {"content-type": "application/json;charset=UTF-8"}}) .expectStatus(201) .toss();

content-type will be overrided to application/json

sasikanth commented 9 years ago

when header 'content-type' is specified as 3rd argument to post(url, body, options) then the current implementation will over ride and default it to 'application/json'

So the below wont work.

var frisby=require('frisby');
frisby.create('test')
.post('http://httpbin.org/post',
    {
        "input": "data",
        "url": "http://httpbin.org/get"
    },
    {
        json:true,
        headers : {'content-type':'user-specific'}
       //when specified here, current implementation will over ride
       // and default it to 'application/json'
    }
)
.inspectRequest()
.toss();

Workaround

var frisby=require('frisby');
frisby.create('test')
.post('http://httpbin.org/post',
    {
        "input": "data",
        "url": "http://httpbin.org/get"
    },
    {
        json:true
    }
)
.addHeader('content-type', 'user-specific') //this will work.
.inspectRequest()
.toss();

Hope that helps..

~ Sasi

sasikanth commented 9 years ago

@vlucas

created PR #266. build passed https://travis-ci.org/vlucas/frisby/builds/81152914

please have a look and merge.

Thanks, Sasi

marcin-wosinek commented 9 years ago

@sasikanthnimmagadda, thanks a lot for the fix & PR.

@tiagolpadua, fix is on master, please reopen if if doesn't fix the issue.