Class: MimeHandling

Contractual.MimeHandling()

MimeHandling provides a collection of methods that serve an API made for retrieving assets which have some mime type, usually related to data stored in a file.

The methods access either the static or the dynamic data providers. Usually, these providers are understood as those that provide static data, premaid and perhaps cached in memory, or they provide dynamically generated data (i.e. they use some processing power and time in order to generate the data to be transmitted on behalf of the request.)

The methods call out to the session handler for authorization for delivery. In some cases, the methods make use of token sequencing to build the case for releasing data to the requester. These types of delivery rely on the fetcher method revealed by the static or dynamic provider. In the case of sequencing, provided data may be produced in a first step and then retrieved after some match condition (secret sharing) passes in a second step, where each step corresponds to a request.

Note: none of these methods handle streaming. Data is sent back to the requested in JSON object, where the useful part of the object will be in a string or sub-object.

The methods return a status code as part of the tupple returned. These codes are HTTP status codes.

Constructor

new MimeHandling()

Source:

Methods

(async) guarded_dynamic_asset_handler(asset, body, transmision_headers) → {Array}

This method calls the method guarded_kindof_asset_handler with the reference to the GeneralDynamic instance in the member variable dynamics.

Parameters:
Name Type Description
asset string
body object
transmision_headers object
Source:
Returns:
  • a tupple really, that has: 1) the status code, 2) the JSON response, 3) possibly data or boolean (false for not in use)
Type
Array

(async) guarded_kindof_asset_handler(asset, body, transmision_headers, fetcher) → {Array}

This method provide the same logic for both dynamic and static data. The only difference between a request for dynamic and static data, is that the fetcher method is on the static or dynamic instance. So, this method takes the fetcher as a paremeter.

For both dynamic and static mime data, the session managers' guard is called. And, if the request passes the guard, then the asset can be processed in the sense that a token object will be made for it by the session manager. The transition object will specify whether or not the mime data will be cached and sent after a seconday transaction or if it will be sent right away.

If the secondary action is used, the transition object components that are to be used by the requester (client) are sent along with the repsonse object.

Parameters:
Name Type Description
asset string
body object
transmision_headers object
fetcher function
Source:
Returns:
  • a tupple really, that has: 1) the status code, 2) the JSON response, 3) possibly data or boolean (false for not in use)
Type
Array

(async) guarded_secondary_asset_handler(body) → {Array}

When the transition object returned from the session manager's process_asset method requires the secondary_action, it sets up the transition object in cache with the anticipation that this method will be called in response to another request from the client tied to the current session and the transition token set on the transition object by process_asset.

This method will only operation if the request's body object has a recognizable token field. Given the token, the cached transition object can be retrieved from the cache. Once it is in hand, the data from the body object and the cached can transtion are passed to the application's matching methods to see if the body data passed tests allowing the request to gain access to previously produced data.

For the mime type handlers, key_mime_type_transition can be used to see if the requested mime type is supported by the application.

Given the tests pass, the data field of the cached transition is accessed to get the data that will be provided to the requesting client.

Parameters:
Name Type Description
body object
Source:
Returns:
  • a tupple really, that has: 1) the status code, 2) the JSON response, 3) possibly data or boolean (false for not in use)
Type
Array

(async) guarded_static_asset_handler(asset, body, transmision_headers) → {Array}

This method calls the method guarded_kindof_asset_handler with the reference to the GeneralStatic instance in the member variable statics.

Parameters:
Name Type Description
asset string
body object
transmision_headers object
Source:
Returns:
  • a tupple really, that has: 1) the status code, 2) the JSON response, 3) possibly data or boolean (false for not in use)
Type
Array

(async) static_asset_handler(asset, body, transmision_headers) → {Array}

This method sends the request body into session manager's guard_static to check access. Then, if access is allowed, this method calls upon the statics module to get the object.

The statics module returns an object that should mention the mime type of the data along with the data. The object returned must have two fields:

  • mime_type - the kind of media being returned
  • string - the media being returned in string format

The application must understand the relationship between the client and the server in how data delivered as a string should be processed for use.

Parameters:
Name Type Description
asset string

an identifier of the asset requested

body object

data relating to the user session and other data useful in finding the asset and establishing access

transmision_headers object
Source:
Returns:
  • a tupple really, that has: 1) the status code, 2) the JSON response, 3) possibly data or boolean (false for not in use)
Type
Array