Skip to content

api.service.Responder ​

This service implements kind of a counterpart to the Router service. It is nearly as crucial as the router to Hitchy's core on processing incoming requests at runtime. Every such request is associated with a response manager. Both are combined in a request context.

Hitchy's core is using this service to normalize a provided response manager so that it is exposing the API any request handler may expect.

Glossary ​

This documentation refers to a response or a response manager. Both describe the same thing in context of Hitchy and commonly refer to an instance of ServerResponse with an augmented API.

Static methods ​

disableResponse() ​

This helper method is accepting a response manager in first argument and adjusts it by replacing methods suitable for producing (further) content to be sent back to the client.

After invocation, the provided response

  • accepts change of response headers except for Content-Type.
  • does not process any additional content to be sent on using response's methods write(), json(), send() or end().
javascript
api.service.Responder.disableResponse( response );

It is invoked on normalizing a response manager while preparing to dispatch a request with HTTP method CONNECT or HEAD which are not expected to deliver any content in response.

normalize() ​

This method is invoked early on dispatching a received request. A partially prepared request context is provided in first argument. The method is adjusting the response property of that request context using polyfills as necessary.

javascript
api.service.Responder.normalize( requestContext );

A dedicated service implements the polyfills this method is applying on a response's API.