KC = kneecap
How it works
A KC instance only allows separate endpoints per http request/response. A single callback can be attached to each endpoint, which must return a promise.
- You should make sure
headers['content-length']is valid (or removed) when changing the request's (or response's) body, otherwise the data may end up truncated.
- Getting the preview is a lot faster than getting the full body. Use
Change request headers
Change request body
Don't change anything
Set request options
Accepts the same params as node.js's
server.listen, except for the final callback.
Returns a promise which resolves when listening.
const kneecap = ;const kc = ;kc;
Stops the server from accepting new connections. Resolves when remaining connections have been closed.
Events are emitted on this emitter.
Adds a REQMOD handler.
server.requestHandler(path[, options], callback)
path must be a string where icap REQMOD requests will be listened to.
options object, when included, will specify the OPTIONS response for the
path endpoint. Supported options:
transferobject, which must contain at least one child with the all
completearray, will be sent as
ignorearray, will be sent as
['jpg', 'jpeg', 'swf', 'mp4']
previewarray, will be sent as
previewBytesinteger, how long should the preview be (where available), in bytes.
Adds a RESPMOD handler. Same usage as
IcapRequest passed to
Synchronous, returns a boolean whether the icap request has request headers.
Returns a promise which resolves to the request headers as a String, most likely separated by
Returns a promise which resolves to the request headers as a Buffer.
Synchronous, returns a boolean whether the icap request has response headers.
Returns a promise which resolves to the response headers as a String, most likely separated by
Returns a promise which resolves to the response headers as a Buffer.
Synchronous, returns a boolean whether the icap request has a request or response body (depends on REQMOD/RESPMOD handler type).
Returns a promise which resolves to a boolean whether the request has a body preview.
Returns a promise which resolves to the request/response body preview as a buffer (depends on REQMOD/RESPMOD handler type). The promise may be resolved synchronously, so call
Promise.resolve(request.getPreview()) as a best practice.
Returns a promise which resolves to the request/response body as a buffer (depends on REQMOD/RESPMOD handler type).
Returns a promise which resolves to an
To respond to an icap
Request, the request handler must return a promise which resolves to either:
- falsey value (
false), which will not modify the request, forwarding it as is. If
Allow: 204is sent by the icap client, then
204 No Contentwill be returned. Otherwise, the request data will be sent back unchanged.
- object containing any combination of
responseBody:Buffer. You must only include one body in the response.
Copyright 2016 Universal Basket
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.