-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
std/http: add serveTLS and listenAndServeTLS #3257
Conversation
std/http/server_test.ts
Outdated
) | ||
.catch((_): void => {}); // Ignores the error when closing the process. | ||
|
||
await delay(100); |
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.
Is this necessary given you wait for "server listening" on stdout above?
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.
Without this delay we get Connection refused
error on client side.
const nread = assertNotEOF(await conn.read(res)); | ||
conn.close(); | ||
const resStr = new TextDecoder().decode(res.subarray(0, nread)); | ||
assert(resStr.includes("Hello HTTPS")); |
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 test.
@@ -401,6 +401,28 @@ export async function listenAndServe( | |||
} | |||
} | |||
|
|||
export type HTTPSOptions = Omit<Deno.ListenTLSOptions, "transport">; | |||
|
|||
export function serveTLS(options: HTTPSOptions): Server { |
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.
Can you add a jsdoc with a little example?
We have a documentation viewer now - so it will be visible at https://deno.land/std/http/server.ts?doc
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.
Added.
41ce8e7
to
d9389d4
Compare
certFile: "./http/testdata/tls/localhost.crt", | ||
keyFile: "./http/testdata/tls/localhost.key", | ||
}; | ||
console.log(`Simple HTTPS server listening on ${tlsOptions.hostname}:${tlsOptions.port}`); |
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.
Can you try printing this after serveTLS is called? That might allow removing the delay
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.
LGTM
Created
serveTLS
usinglistenTLS
for HTTPS instead oflisten
for HTTP.Example:
There seems to be still some issue when plain HTTP payload is submitted to the
serveTLS
that yieldsInvalidData
error. We need to investigate how to gracefully handle the error in potentially another PR.