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!: bring dev server headers to parity with production #5490

Merged
merged 6 commits into from
Feb 21, 2023

Conversation

eduardoboucas
Copy link
Member

Summary

Some of the headers returned by the CLI's dev server are different from what we return in production. This PR attempts to bring them closer.

@github-actions
Copy link

github-actions bot commented Feb 19, 2023

📊 Benchmark results

Comparing with 171a14a

Package size: 263 MB

⬆️ 0.02% increase vs. 171a14a

^                                                  270 MB  270 MB                                         
│  263 MB  263 MB  263 MB  263 MB  263 MB  263 MB   ┌──┐    ┌──┐   263 MB  263 MB  263 MB  263 MB  263 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

@@ -133,7 +132,6 @@ export const initializeProxy = async ({
[headers.Functions]: functionNames.join(','),
[headers.ForwardedHost]: `localhost:${passthroughPort}`,
[headers.Passthrough]: 'passthrough',
[headers.RequestID]: generateUUID(),
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to the proxy so that all requests have it.

@eduardoboucas eduardoboucas marked this pull request as ready for review February 20, 2023 09:53
@eduardoboucas eduardoboucas requested a review from a team February 20, 2023 09:53
khendrikse
khendrikse previously approved these changes Feb 20, 2023
@eduardoboucas
Copy link
Member Author

@khendrikse I added and updated some tests so your review got stale. Could you give it another look, please?

khendrikse
khendrikse previously approved these changes Feb 20, 2023
Skn0tt
Skn0tt previously approved these changes Feb 20, 2023
Copy link
Member

@Skn0tt Skn0tt left a comment

Choose a reason for hiding this comment

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

looks good, left two minor non-blocking comments.


// Transform a v4 UUID to match the format used in production — alphanumeric
// characters, all uppercase, 26 characters.
export const generateRequestID = () => generateUUID().replace(/-/g, '').toUpperCase().slice(0, 26)
Copy link
Member

Choose a reason for hiding this comment

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

if we wanted, we could use https://github.com/ulid/javascript to get the very same format as is being used in production, so if any of our users rely on the characteristics of ULIDs (e.g. the embedded timestamp), that'd make it easier to test in dev. I don't think anybody does that, nor that anybody should, so it's probably right to use UUID here. And it sames some NPM dead weight.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I was torn on this myself. But if the idea is to bring parity with production as closely as possible, we might as well use the same format. Updated in d0227f7.

@@ -21,7 +21,8 @@ export const startStaticServer = async ({ settings }) => {
})

server.addHook('onRequest', (req, reply, done) => {
reply.header('X-Powered-by', 'netlify-dev')
Copy link
Member

Choose a reason for hiding this comment

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

should we add the Server: Netlify header? or Server: Netlify Dev, as we call it in https://docs.netlify.com/cli/get-started/#get-started-with-netlify-dev?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unless there's a reason to differentiate them, I'd rather use the same value in both environments.

Copy link
Member

@Skn0tt Skn0tt Feb 20, 2023

Choose a reason for hiding this comment

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

makes sense. right now we're not setting Server anywhere, right? should we?

Copy link
Member Author

Choose a reason for hiding this comment

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

We're not. Production gives you server: Netlify and CLI gives you x-powered-by: netlify-dev.

Copy link
Member

Choose a reason for hiding this comment

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

that's what I figured. This PR is about moving the CLI closer to prod together, so let's add reply.header("Server", "Netlify")

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm confused. That's what we're doing here, except we're doing it for all responses and not just the ones served by the static server.

Copy link
Member

Choose a reason for hiding this comment

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

I was confused. Didn't see that, sorry.

@eduardoboucas eduardoboucas dismissed stale reviews from Skn0tt and khendrikse via d0227f7 February 20, 2023 11:50
@eduardoboucas eduardoboucas changed the title feat: bring dev server headers to parity with production feat!: bring dev server headers to parity with production Feb 20, 2023
@eduardoboucas
Copy link
Member Author

Changed to feat! as this is technically a breaking change.

@eduardoboucas eduardoboucas merged commit edad634 into main Feb 21, 2023
@eduardoboucas eduardoboucas deleted the feat/headers-parity branch February 21, 2023 13:37
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

3 participants