diff options
| -rw-r--r-- | lib/response.js | 25 | ||||
| -rw-r--r-- | server.js | 5 |
2 files changed, 26 insertions, 4 deletions
diff --git a/lib/response.js b/lib/response.js index 442cea0..25187af 100644 --- a/lib/response.js +++ b/lib/response.js @@ -51,14 +51,32 @@ const createResponse = () => { // convenience API res.prompt = (promptMsg) => { - if (typeof promptMsg !== 'string') { - throw new Error('invalid promptMsg') - } + if (typeof promptMsg !== 'string') throw new Error('invalid promptMsg') sendHeader(CODES.INPUT, promptMsg) } + res.redirect = (url, permanent = false) => { + sendHeader(permanent ? CODES.REDIRECT_PERMANENT : CODES.REDIRECT_TEMPORARY, url) + } + res.proxyError = (msg) => { + if (typeof msg !== 'string') throw new Error('invalid msg') + sendHeader(CODES.PROXY_ERROR, msg) + } + res.slowDown = (waitForSeconds) => { + if (!Number.isInteger(waitForSeconds)) { + throw new Error('invalid waitForSeconds') + } + sendHeader(CODES.SLOW_DOWN, waitForSeconds + '') + } + res.notFound = () => { + sendHeader(CODES.NOT_FOUND) + } res.gone = () => { sendHeader(CODES.GONE) } + res.badRequest = (msg) => { + if (typeof msg !== 'string') throw new Error('invalid msg') + sendHeader(CODES.BAD_REQUEST, msg) + } res.requestTransientClientCert = (reason) => { if (typeof reason !== 'string') throw new Error('invalid reason') sendHeader(CODES.TRANSIENT_CERT_REQUESTED, reason) @@ -67,7 +85,6 @@ const createResponse = () => { if (typeof reason !== 'string') throw new Error('invalid reason') sendHeader(CODES.AUTHORISED_CERT_REQUIRED, reason) } - // todo: redirect(), serverUnavailable(), slowDown(), badRequest() return res } @@ -22,6 +22,11 @@ const createGeminiServer = (opt = {}, onRequest) => { } const onConnection = (socket) => { + // todo: clarify if this is desired behavior + if (socket.alpnProtocol !== ALPN_ID) { + socket.destroy() + return; + } if ( socket.authorizationError && // allow self-signed certs |
