-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
fix: extend Node.js IncomingHttpHeaders in our Headers type #346
Conversation
Fixes: cloudevents#340 Signed-off-by: Lance Ball <lball@redhat.com>
src/message/http/index.ts
Outdated
@@ -71,7 +71,7 @@ export function deserialize(message: Message): CloudEvent { | |||
* @returns {Mode} the transport mode | |||
*/ | |||
function getMode(headers: Headers): Mode { | |||
const contentType = headers[CONSTANTS.HEADER_CONTENT_TYPE]; | |||
const contentType = headers[CONSTANTS.HEADER_CONTENT_TYPE] as string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you can add as const to the actual constants file instead of in every usage of this.
Ref: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions
in sdk-javascript/src/constants.ts
const CONSTANTS = Object.freeze({
CHARSET_DEFAULT: "utf-8",
...
} as const);
export default CONSTANTS;
@@ -85,6 +86,25 @@ describe("HTTP transport", () => { | |||
}).to.throw; | |||
}); | |||
|
|||
it("Can be created with Node's IncomingHttpHeaders", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
@@ -48,7 +48,7 @@ function superagentEmitter(message: Message, options?: Options): Promise<unknown | |||
} | |||
// set headers | |||
for (const key of Object.getOwnPropertyNames(message.headers)) { | |||
post.set(key, message.headers[key]); | |||
post.set(key, message.headers[key] as string); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess we also have to submit an issue to superagent 😂
Signed-off-by: Lance Ball <lball@redhat.com>
Proposed Changes
IncomingHttpHeaders
in ourHeaders
typeDescription
Changes the
Headers
type to make it more compatible with Node.js TypeScript projects.Signed-off-by: Lance Ball lball@redhat.com