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: Add version headers to all responses #23

Merged
merged 1 commit into from
Apr 15, 2023

Conversation

ShibireX
Copy link
Contributor

The version header is dynamically updated via npm_package_version, and appended to all other existing headers. By using a Fastify hook, we ensure that the version header gets featured in every proxy response.

@ShibireX ShibireX linked an issue Apr 10, 2023 that may be closed by this pull request
@ShibireX ShibireX requested a review from birme April 10, 2023 14:43
Copy link
Contributor

@birme birme left a comment

Choose a reason for hiding this comment

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

In general looks good. Just add a unit test for this and we are good.
Look at fastify.inject() for that

@ShibireX ShibireX requested a review from birme April 12, 2023 00:14
registerRoutes(app);

// Adding version header
app.addHook('onSend', async (request, reply, payload) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The intention with the unit test is to test the implementation in server.ts. I don't really see that this does that?

src/server.ts Outdated
@@ -9,6 +10,9 @@ const INTERFACE: string = process.env.INTERFACE || '0.0.0.0';
const app = fastify();
app.register(FastifyCors, {});

// Add version header
addCustomVersionHeader(app);
Copy link
Contributor

@birme birme Apr 13, 2023

Choose a reason for hiding this comment

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

I'd prefer that you add the hook in the registerRoutes() function because then in the unit test it would be just a matter of doing something like:

describe('Chaos Stream Proxy server', () => {
  let app;
  beforeEach(() => {
    app = fastify();
    registerRoutes(app);
  });

  it.each([HLS_PROXY_MASTER, HLS_PROXY_MEDIA, SEGMENTS_PROXY_SEGMENT])('route %p contains x-version header', (route) => {
    const response = await app.inject(route);
    expect(response.headers).objectContaining(...)
  });
});

@ShibireX ShibireX requested a review from birme April 13, 2023 23:15
Copy link
Contributor

@birme birme 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 now. Squash (using rebase) this PR into one single commit and I will merge it to main

@ShibireX ShibireX force-pushed the feat/custom-version-header-in-response branch from 82c93a5 to a86eaf5 Compare April 15, 2023 00:58
@birme birme merged commit ccbc10a into main Apr 15, 2023
@birme birme deleted the feat/custom-version-header-in-response branch April 15, 2023 02:02
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.

Custom version header in responses
3 participants