Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pre-request scripts to mitigate concurrent modification issue while removing blank headers #61

Merged
merged 1 commit into from
Jan 22, 2023

Conversation

dlh3
Copy link
Contributor

@dlh3 dlh3 commented Jan 12, 2023

Description

In Postman 10.7.1 for MacOS, pm.request.headers.each() fails when removing headers while iterating over them:

TypeError: Cannot read properties of undefined (reading 'value')

Using Request.forEachHeader() avoids that pitfall. Other options would be operating on pm.request.headers.members, or calling all() or map() before each(), since either would result in an independent list of headers.

For reference, Request.forEachHeader() internally calls pm.request.headers.all().each(callback).

Related Issue

#62

Motivation and Context

Fixes a TypeError that breaks this collection.

How Has This Been Tested?

Manually and exhaustively with Postman.

Screenshots (if appropriate):

image

image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

…while removing blank headers

In Postman 10.7.1 for MacOS, `pm.request.headers.each()` fails when removing headers while iterating over them:
> TypeError: Cannot read properties of undefined (reading 'value')

Using `pm.request.forEachHeader()` avoids that pitfall.  Other options would be operating on `pm.request.headers.members`, or calling `all()` or `map()` before `each()`, since either would result in an independent list of headers.

Reference: https://www.postmanlabs.com/postman-collection/Request.html#forEachHeader
@dlh3 dlh3 changed the title Update Query Service API pre-request script Update pre-request scripts to mitigate concurrent modification issue while removing blank headers Jan 13, 2023
@tsilver tsilver merged commit 39e2d0b into adobe:master Jan 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants