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

Header name is case insensitive in the schema definition #816

Merged
merged 4 commits into from Mar 1, 2018

Conversation

allevo
Copy link
Member

@allevo allevo commented Feb 27, 2018

As titled, the rfc https://tools.ietf.org/html/rfc2616#section-4.2 defines the header key as case insensitive.

const schema = {
  headers: {
    UppErCaSe: { type: 'number' }
  }
}
fastify.get('/', { schema }, myHandler)

The problem is when I curl with uppercase: 3 header because nodejs force to use to lower case.

I'm working on to fix this.

Checklist

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

@allevo
Copy link
Member Author

allevo commented Feb 27, 2018

Unfortunately the schema this fix only for jsonschema and only if the schema is a plain object.
A deeper check may be out of scope. For example this schema is not supported

{
  schema: {
    headers: {
      oneOf: [  ... ]
    }
  }
}

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -29,7 +29,15 @@ function build (context, compile, schemas) {
context.schema = schemas.resolveRefs(context.schema)

if (context.schema.headers) {
context[headersSchema] = compile(context.schema.headers)
// see https://github.com/fastify/fastify/pull/816
const headersSchemaLowerCase = {}
Copy link
Member

Choose a reason for hiding this comment

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

can you please link to the spec?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

// https://tools.ietf.org/html/rfc2616#section-4.2
const headersSchemaLowerCase = {}
for (const k in context.schema.headers) {
headersSchemaLowerCase[k] = context.schema.headers[k]
Copy link
Member

Choose a reason for hiding this comment

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

You should probably use hasOwnProperty here, or switch to Object.keys().

Copy link
Member

@delvedor delvedor left a comment

Choose a reason for hiding this comment

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

LGTM with @mcollina's suggestion.

}
if (context.schema.headers.properties) {
for (const k in context.schema.headers.properties) {
headersSchemaLowerCase.properties[k.toLowerCase()] = context.schema.headers.properties[k]
Copy link
Member

Choose a reason for hiding this comment

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

Here as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, thanks

Copy link
Member

@delvedor delvedor left a comment

Choose a reason for hiding this comment

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

LGTM

@jsumners jsumners merged commit 746e307 into master Mar 1, 2018
@jsumners jsumners deleted the header-key-are-case-insensitive branch March 1, 2018 13:40
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2022
@Eomm Eomm added the semver-minor Issue or PR that should land as semver minor label Apr 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
semver-minor Issue or PR that should land as semver minor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants