Skip to content

fix(httpclient): Do not send undefined headers#8009

Closed
krystofwoldrich wants to merge 2 commits intodevelopfrom
kw-fix-undefined-keys-httpclient
Closed

fix(httpclient): Do not send undefined headers#8009
krystofwoldrich wants to merge 2 commits intodevelopfrom
kw-fix-undefined-keys-httpclient

Conversation

@krystofwoldrich
Copy link
Copy Markdown
Contributor

Before submitting a pull request, please take a look at our
Contributing guidelines and verify:

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).

If sendDefaultPii: false normalized "[undefined]" headers should not be sent.

Screenshot 2023-05-02 at 11 19 01

@krystofwoldrich krystofwoldrich requested review from Lms24, lforst and mydea May 2, 2023 11:28
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented May 2, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 21.03 KB (0%)
@sentry/browser - ES5 CDN Bundle (minified) 65.66 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 19.56 KB (0%)
@sentry/browser - ES6 CDN Bundle (minified) 58.12 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 21.17 KB (0%)
@sentry/browser - Webpack (minified) 69.07 KB (0%)
@sentry/react - Webpack (gzipped + minified) 21.19 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 49.04 KB (+0.02% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 28.61 KB (+0.04% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 26.83 KB (+0.03% 🔺)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 46.87 KB (+0.15% 🔺)
@sentry/replay - Webpack (gzipped + minified) 40.67 KB (+0.19% 🔺)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 65.7 KB (+0.12% 🔺)
@sentry/browser + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 58.64 KB (+0.13% 🔺)

},
});
expect(eventData.request?.headers).toEqual({
'User-Agent': expect.any(String),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of interest, how would this test previously fail? meaning, what used to happen before this PR?

Copy link
Copy Markdown
Contributor Author

@krystofwoldrich krystofwoldrich May 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this toMatchObject ignores extra attributes, but toEqual requires values to be exactly the same.
I've updated the test to use toStrictEqual to catch also undefined keys, but the test looked the same with toEqual because the undefined keys were normalized to string.

Running 1 test using 1 worker

  ✘  1 …tpclient/fetch/simpleNoPii/test.ts:7:11 › should assign request and response context from a failed 500 fetch request without pii (1.7s)


  1) suites/integrations/httpclient/fetch/simpleNoPii/test.ts:7:11 › should assign request and response context from a failed 500 fetch request without pii

    Error: expect(received).toEqual(expected) // deep equality

    - Expected  - 0
    + Received  + 3

      Object {
    +   "body_size": "[undefined]",
    +   "cookies": "[undefined]",
    +   "headers": "[undefined]",
        "status_code": 500,
      }

      56 |       'User-Agent': expect.any(String),
      57 |     });
    > 58 |     expect(eventData.contexts?.response).toEqual({
         |                                          ^
      59 |       status_code: 500,
      60 |     });
      61 |   },

        at /Users/krystofwoldrich/repos/sentry-javascript/packages/browser-integration-tests/suites/integrations/httpclient/fetch/simpleNoPii/test.ts:58:42

  1 failed
    suites/integrations/httpclient/fetch/simpleNoPii/test.ts:7:11 › should assign request and response context from a failed 500 fetch request without pii
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@krystofwoldrich krystofwoldrich requested a review from mydea May 2, 2023 16:35
Copy link
Copy Markdown
Contributor

@lforst lforst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should instead change normalize to drop undefined values. Normalizing it to strings is weird.

@AbhiPrasad
Copy link
Copy Markdown
Contributor

Given we merged and released #8017, we can probably close this PR right?

@lforst lforst closed this May 24, 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.

4 participants