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

feat: use netlify-headers-parser #3189

Merged
merged 1 commit into from
Aug 16, 2021
Merged

Conversation

ehmicky
Copy link
Contributor

@ehmicky ehmicky commented Aug 16, 2021

Part of netlify/build#2890

This uses netlify-headers-parser inside Netlify CLI in order to:

  • Prevent code duplication between @netlify/config and netlify dev
  • Be consistent with how redirects are parsed in netlify dev (with netlify-redirects-parser)
  • Isolate the headers parsing logic so it's easier to make it use the back-end parsing logic in the future
  • Benefit from the several bug fixes and minor improvements added by netlify-headers-parser

I have updated the automated tests and also tested it manually.

@ehmicky ehmicky added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Aug 16, 2021
@ehmicky ehmicky self-assigned this Aug 16, 2021
@github-actions
Copy link

github-actions bot commented Aug 16, 2021

📊 Benchmark results

Comparing with fa064f1

Package size: 330 MB

(no change)

^  330 MB  330 MB  331 MB  331 MB  331 MB  331 MB  331 MB  330 MB  330 MB  331 MB  331 MB  331 MB  330 MB 
│   ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

'/': {
'X-Frame-Options': ['SAMEORIGIN'],
test('_headers: validate rules', async (t) => {
const rules = await parseHeaders({ headersFiles: [path.resolve(t.context.builder.directory, '_headers')] })
Copy link
Contributor Author

Choose a reason for hiding this comment

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

parseHeaders() now returns an array instead of an object.
The source code and tests were updated to take it into account.

'X-Frame-Options': ['SAMEORIGIN'],
'X-Frame-Thing': ['SAMEORIGIN'],
'X-Frame-Options': 'SAMEORIGIN',
'X-Frame-Thing': 'SAMEORIGIN',
Copy link
Contributor Author

@ehmicky ehmicky Aug 16, 2021

Choose a reason for hiding this comment

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

Multiple headers with the same name are now joined into a single one with , which is the production behavior.
The current netlify dev behavior is to set several HTTP headers instead.
So this fixes a difference between production and local experience.

@ehmicky ehmicky added the automerge Add to Kodiak auto merge queue label Aug 16, 2021
@ehmicky ehmicky force-pushed the feat/use-netlify-headers-parser branch from e37bae7 to d62c747 Compare August 16, 2021 16:32
@kodiakhq kodiakhq bot merged commit 8d77d49 into main Aug 16, 2021
@kodiakhq kodiakhq bot deleted the feat/use-netlify-headers-parser branch August 16, 2021 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Add to Kodiak auto merge queue type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants