summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJannis R <mail@jannisr.de>2020-05-03 16:17:03 +0200
committerJannis R <mail@jannisr.de>2020-05-03 16:17:03 +0200
commit0e0eb67c7f43338bb2c28f4a354ef2ab95bae6ff (patch)
tree7c85610084df20faeb8cdacc730da73c5c758d69 /lib
parentffbab4a5cff16e6e0626b699b185580450b169fc (diff)
server: require ALPN, response convenience fns
Diffstat (limited to 'lib')
-rw-r--r--lib/response.js25
1 files changed, 21 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
}