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

fix: extend Node.js IncomingHttpHeaders in our Headers type #346

Merged
merged 2 commits into from
Oct 6, 2020

Conversation

lance
Copy link
Member

@lance lance commented Oct 1, 2020

Proposed Changes

  • extend Node.js IncomingHttpHeaders in our Headers type

Description

Changes the Headers type to make it more compatible with Node.js TypeScript projects.

Signed-off-by: Lance Ball lball@redhat.com

Fixes: cloudevents#340

Signed-off-by: Lance Ball <lball@redhat.com>
@lance lance added type/fix A change that fixes something that is broken module/lib Related to the main source code labels Oct 1, 2020
@lance lance requested a review from a team October 1, 2020 15:18
@lance lance self-assigned this Oct 1, 2020
@@ -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;
Copy link

@aldirrix aldirrix Oct 2, 2020

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", () => {
Copy link

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);
Copy link

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/lib Related to the main source code type/fix A change that fixes something that is broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typescript incompatible type in 3.1.0 and Express 4.x
3 participants