Open snk20501 opened 7 years ago
@snk20501 Could you confirm that this still works correctly with v5.3.1 of the Postman app? I'll dig deeper into the header fetch issue in the meantime. 😄
@kunagpal The version I use is v5.3.0 and it works correctly. Thank you for looking into this problem. :)
I am also having the same issue.
@LeonardoGonzales Which version of Newman are you on? You can find this with newman -v
.
Hello @kunagpal, Thank you for the quick feedback. I am using version 3.8.3 as well. I installed it using npm (npm install -g newman)
Hello @kunagpal, postman.getResponseHeader is having the same issue in postman application for linux as well. I downloaded Postman-linux-x64-5.3.2.tar.gz, installed my machine and faced the same error. Google chrome application version 5.3.0 works for me.
The issue is reproducible in stand-alone Postman v.5.5.0
Google chrome application version 5.4.0 does not have this issue, reproducible in desktop version v.5.5.0
@snk20501 @LeonardoGonzales @zhak @borodaalex Could you try the following snippet out and let me know if it works for you?
pm.response.headers.one('my_header_name');
Hi guys, I have same issue,
response has following headers (pretty view):
Server →xxxxxxxx-xxxxx
Set-Cookie →APSCOOKIE_9539865665021864916="0%260"; path=/; expires=Tue, 06-Feb-1968 18:34:11 GMT
Set-Cookie →VDOM_9539865665021864916="0%260"; path=/; expires=Tue, 06-Feb-1968 18:34:11 GMT
Set-Cookie →log_filters="0%260"; path=/log/; expires=Tue, 06-Feb-1968 18:34:11 GMT
Set-Cookie →log_type="0%260"; path=/log/; expires=Tue, 06-Feb-1968 18:34:11 GMT
Set-Cookie →CENTRAL_MGMT_OVERRIDE_9539865665021864916="0%260"; path=/; expires=Tue, 06-Feb-1968 18:34:11 GMT
Set-Cookie →EDIT_HISTORY_9539865665021864916="0%260"; path=/; expires=Tue, 06-Feb-1968 18:34:11 GMT
Set-Cookie →FILE_DOWNLOADING_9539865665021864916="0%260"; path=/; expires=Tue, 06-Feb-1968 18:34:11 GMT
Set-Cookie →csrftoken_9539865665021864916="0%260"; path=/; expires=Tue, 06-Feb-1968 18:34:11 GMT
Set-Cookie →ccsrftoken_9539865665021864916="0%260"; path=/; expires=Tue, 06-Feb-1968 18:34:11 GMT
Set-Cookie →ccsrftoken="0%260"; path=/; expires=Tue, 06-Feb-1968 18:34:11 GMT
for single value header all looks good: postman.getResponseHeader('server') ----> "xxxxxxxx-xxxxx"
but for multi-value header like set-cookie we are receiving last element of array, at index 9: postman.getResponseHeader('Set-Cookie') ----> "ccsrftoken="0%260"; path=/; expires=Tue, 06-Feb-1968 18:30:59 GMT"
also
pm.response.headers.one('Set-Cookie').value;----> "ccsrftoken="0%260"; path=/; expires=Tue, 06-Feb-1968 19:36:57 GMT"
So the clue is that getResponseHeader works incorrect and return last value of multivalue header This function should return an array of all values for given header name
My workaround for a moment is to use
// print all Set-Cookie header values
pm.response.headers.all()
.filter(headerObj => { return headerObj.key == "Set-Cookie";})
.forEach(headerObj => {
console.log(headerObj.key +": "+headerObj.value)
})
BR, Karol
@kunagpal I try following script but still get the same result. The POSTMan version is the latest v5.5.2.
pm.response.headers.one('my_header_name');
My question is sort of related to this: Is there a way to actually parse out 1 value inside a given header example: postman gives me this response header
X-Pagination →{"TotalCount":6,"PageSize":5,"CurrentPage":1,"TotalPages":2,"PreviousPageLink":null,"NextPageLink":"http://localhost/v1/accounts?searchQuery=nam&pageNumber=2&pageSize=5"}
How do I extract TotalCount and its value?
@kdp88 did you try it: var pageHeader = JSON.parse(postman.getResponseHeader('X-Pagination') ); console.log(pageHeader.TotalCount);
thank @ekarpie, your "work around" worked very well for me
Best Regards
Leo
@LeonardoGonzales you are the man dude, that worked flawlessly how about extracting the TotalCount key and not the value.
for(var key in pageHeader){ console.log('Key'+key +' value: '+ pageHeader[key]) }
@LeonardoGonzales 2 for 2
I LIKE IT THANKS MAN!
So the debate is ... should we have a polymorphic function return signature for headers? i.e. return string for single and array for multiple. That may break many current use cases across Postman and Newman.
Or find a way to add another function that takes care of this / extra param to indicate allowing multi-value (and make all returns array when that param is set to true -> including for single value)?
So, what happens with query string duplication? @kamalaknn
Refer: https://github.com/postmanlabs/postman-app-support/issues/6143
newman -v
): 3.8.3Please help to look into this issue Note. This issue can't reproduce in POSTMAN