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

[Http] Make HTTP resource routes respond without the versioned header #195940

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

jloleysens
Copy link
Contributor

@jloleysens jloleysens commented Oct 11, 2024

Summary

Adds the internal route registrar option isHTTPResource to distinguish API routes from routes intended to be used for loading resources, for ex.

This enables us to avoid returning the version header elastic-api-version for these routes.

It's still possible for API authors to use the versioned router for things that should be HTTP resources, but it's assumed that all routes registered through HTTP resources services are:

  1. Public
  2. Not versioned
  3. Not documented (done in [HTTP/OAS] Ability to exclude routes from introspection #192675)

This PR addresses the second point.

Checklist

@jloleysens jloleysens added Feature:http Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc release_note:skip Skip the PR/issue when compiling release notes v9.0.0 v8.16.0 backport:version Backport to applied version labels labels Oct 11, 2024
@elasticmachine
Copy link
Contributor

🤖 Jobs for this PR can be triggered through checkboxes. 🚧

ℹ️ To trigger the CI, please tick the checkbox below 👇

  • Click to trigger kibana-pull-request for this PR!
  • Click to trigger kibana-deploy-project-from-pr for this PR!

@@ -84,7 +85,7 @@ export class HttpResourcesService implements CoreService<InternalHttpResourcesSe
route: RouteConfig<P, Q, B, 'get'>,
handler: HttpResourcesRequestHandler<P, Q, B, Context>
) => {
return router.get<P, Q, B>(
return (router as unknown as Router<RequestHandlerContext>).get<P, Q, B>(
Copy link
Contributor Author

@jloleysens jloleysens Oct 11, 2024

Choose a reason for hiding this comment

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

This was the simplest way to get this working end-to-end without a larger refactor to pass Router in directly.

IMO it's OK for the internal http resources to have privileged knowledge of Router types (i.e. the internal options). Just didn't want to make this too big of a refactor for now.

Happy to take other ideas.

@jloleysens
Copy link
Contributor Author

/ci


await root.start();
const { header } = await request.get(root, '/render-html').expect(200);
expect(header).not.toMatchObject({ 'elastic-api-version': expect.any(String) });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Making this test work is the main focus of the PR.

@jloleysens jloleysens self-assigned this Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:version Backport to applied version labels Feature:http release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v8.16.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants