postmanlabs / newman

Newman is a command-line collection runner for Postman
https://www.postman.com
Apache License 2.0
6.9k stars 1.17k forks source link

postman.getResponseHeader cant's get full content of Header value #1241

Open snk20501 opened 7 years ago

snk20501 commented 7 years ago
  1. Newman Version (can be found via newman -v): 3.8.3
  2. OS details (type, version, and architecture): Ubuntu 16.04.02 64bit LTS server
  3. Are you using Newman as a library, or via the CLI? CLI
  4. Did you encounter this recently, or has this bug always been there: always been there

    Please help to look into this issue Note. This issue can't reproduce in POSTMAN

kunagpal commented 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. 😄

snk20501 commented 7 years ago

@kunagpal The version I use is v5.3.0 and it works correctly. Thank you for looking into this problem. :)

LeonardoGonzales commented 7 years ago

I am also having the same issue.

kunagpal commented 7 years ago

@LeonardoGonzales Which version of Newman are you on? You can find this with newman -v.

LeonardoGonzales commented 7 years ago

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)

LeonardoGonzales commented 7 years ago

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.

ghost commented 6 years ago

The issue is reproducible in stand-alone Postman v.5.5.0

borodaalex commented 6 years ago

Google chrome application version 5.4.0 does not have this issue, reproducible in desktop version v.5.5.0

kunagpal commented 6 years ago

@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');
ekarpie commented 6 years ago

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

snk20501 commented 6 years ago

@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');

kdp88 commented 6 years ago

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?

LeonardoGonzales commented 6 years ago

@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

kdp88 commented 6 years ago

@LeonardoGonzales you are the man dude, that worked flawlessly how about extracting the TotalCount key and not the value.

LeonardoGonzales commented 6 years ago

for(var key in pageHeader){ console.log('Key'+key +' value: '+ pageHeader[key]) }

kdp88 commented 6 years ago

@LeonardoGonzales 2 for 2

I LIKE IT THANKS MAN!

shamasis commented 6 years ago

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