TROJavaScriptHttpDispatcher

Overview

This is the special version of TROHTTPFileDispatcher HTTP file dispatcher designed to use for serving Remoting SDK for JavaScript supporting script. While inheriting all functionality of the base class the TROJavaScriptHttpDispatcher is able to serve the script either from the application resources or from the disk folder. Notice the following:

  • the Path property is set to '/js/' by default
  • the name of the script to be served is RemObjectsSDK.js, this can not be changed (must correspond to Remoting SDK for JavaScript design), so the default URL of the script will look like http://example.org/js/RemObjectsSDK.js
  • the script is stored and served from resources in the packed form, this reduces the traffic and provides a bit of obfuscation.
  • in case of Remoting SDK for JavaScript upgrade there is no need to recompile the server application, just put the new file into the disk folder specified by Folder property, serving from the folder takes precedence over the resource.

Use this component if it is necessary to create a server usable with Remoting SDK for JavaScript clients.

Location

 

constructor Create  override

Standard component constructor

constructor Create(AOwner: TComponent)

Parameters:

  • AOwner: Owner

Activate  virtual    (declared in TROExtendedHttpDispatcher)

procedure Activate

Assign  override

Copies the contents of another, similar object.

procedure Assign(Source: TPersistent)

Parameters:

  • Source: Instance whose properties will be copied

CanHandlePath    (declared in TROExtendedHttpDispatcher)

Return true if the given path can be handled by the dispatcher. The function compares the Path property content with the given path and chacks if the given path starts with the Path subpath.

function CanHandlePath(aPath: string): Boolean

Parameters:

  • aPath: The request path to check.

Deactivate  virtual    (declared in TROExtendedHttpDispatcher)

procedure Deactivate

DefaultFile    (declared in TROHTTPFileDispatcher)

The name of the file that will be served for directory request.
Example: assume we have configured the server to serve for /js/ virtual folder. The request to get http://example.org/js will serve the file specified with this property. Note: the request without trailing slash (http://example.org/js) will be redirected to the location with the trailing slash (http://example.org/js/) using 302 HTTP response code. The user's browser will get the new location and display it to the user seamlessly.
The default value is index.html

property DefaultFile: string read write

FireOnRequest  protected virtual    (declared in TROHTTPFileDispatcher)

Fires the OnRequest event.

procedure FireOnRequest(Path: string; Data: TStream; out ContentType: string; out ResultCode: Integer; out Status: string)

Parameters:

  • Path: The request path.
  • Data: The response data - output parameter.
  • ContentType: The response content type - output parameter.
  • ResultCode: The response HTTP result code - output parameter.
  • Status: The response HTTP status message - output parameter.

Folder    (declared in TROHTTPFileDispatcher)

The local path that will correspond to the virtual folder from the Path property. If relative path is specified then the path to the program main module will be used as base path.

property Folder: string read write

Notification  protected override    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure Notification(aComponent: TComponent; Operation: TOperation)

Parameters:

  • aComponent: component
  • Operation: operation

NotifyDispose    (declared in TROExtendedHttpDispatcher)

This procedure is called when the server HTTP channel is about to be freed.

procedure NotifyDispose

OnRequest    (declared in TROHTTPFileDispatcher)

Allows full customization of serving files by the user.
NOTICE: when this event is handled user's code takes full responsibility of the request processing, no other processing actions are performed except request validity check before the event is fired.

property OnRequest: TROHTTPFileDispatcherEvent read write
delegate: procedure OnRequest(Sender: TObject; Path: string; Data: TStream; out ContentType: string; out ResultCode: Integer; out Status: string)

Path    (declared in TROExtendedHttpDispatcher)

The request path the dispatcher will be activated for. For example, if this property contains /js then the dispatcher will be activated by the server channel to process such requests as http://example.org:8099/js/* (the asterisk means zero or more characters to continue the request path).

property Path: string read write

Process  override    (declared in TROHTTPFileDispatcher)

The main method to perform the request processing ant to form the response. Called every time to process incoming requests if the dispatcher is suitable to process it (determined by CanHandlePath result).

procedure Process(aTransport: IROHTTPTransport; aRequest: IROHTTPRequest; aResponse: IROHTTPResponse; aRequestData: TStream; aResponseData: TStream)

Parameters:

  • aTransport: Http transport.
  • aRequest: Contains object implementing IROHTTPRequest interface that describes the request.
  • aResponse: Contains initialized object implementing IROHTTPResponse interface that should describe the response.
  • aRequestData: The data stream (TStream) that contains the raw HTTP request data except the header part.
  • aResponseData: Contais initialized and empty data stream (TStream) that shpuld be filled with the raw reponse data except the header part.

ReplyWithMessage  protected    (declared in TROHTTPFileDispatcher)

Internal utility method - prepares response with specified parameters and puts it into the response object and response stream.

procedure ReplyWithMessage(aCode: Integer; aStatus: string; aMessage: string; aResponse: IROHTTPResponse; aResponseData: TStream)

Parameters:

  • aCode: The HTTP response code.
  • aStatus: The HTTP response status message.
  • aMessage: The user understandable response message.
  • aResponse: The reference to the object describing the HTTP response.
  • aResponseData: The stream that will contain the response data.

ResolveContentType    (declared in TROHTTPFileDispatcher)

Resolves and returns content type based on the file extension. Contains the content type table for the most often used extensions, others are resolved using registry (Windows platforms only).

function ResolveContentType(aExtension: string): string

Parameters:

  • aExtension: The file extension to resolve.

ROFreeNotification    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure ROFreeNotification(aComponent: TComponent)

Parameters:

  • aComponent: component

RORemoveFreeNotification    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure RORemoveFreeNotification(aComponent: TComponent)

Parameters:

  • aComponent: component

SendRemoveNotification  protected    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure SendRemoveNotification(aComponent: TComponent)

Parameters:

  • aComponent: component

ServeCustom  protected override

Allows further customization of the serving process.

procedure ServeCustom(aFilePath: string; aRequest: IROHTTPRequest; aResponse: IROHTTPResponse; aResponseData: TStream)

Parameters:

  • aFilePath: The requested file path.
  • aRequest: The reference to the object describing the HTTP request.
  • aResponse: The reference to the object describing the HTTP response.
  • aResponseData: The stream that will contain the response data.

ServeFilesFromFolder    (declared in TROHTTPFileDispatcher)

Enables or disables serving files from the Folder. When this property has false value then the only option to serve files remains the OnRequest event handler. The default is true.

property ServeFilesFromFolder: Boolean read write

ServeFromFolder  protected virtual    (declared in TROHTTPFileDispatcher)

Locates file in the disk folder and forms the proper response.

procedure ServeFromFolder(aFilePath: string; aResponse: IROHTTPResponse; aResponseData: TStream)

Parameters:

  • aFilePath: The requested file path.
  • aResponse: The reference to the object describing the HTTP response.
  • aResponseData: The stream that will contain the response data.

Server    (declared in TROExtendedHttpDispatcher)

Points to the HTTP server channel which the dispatcher works with.

property Server: IROHTTPServer read write

ServeROJavaScript

Enables or disables RemObjectsSDK.js script serving. If set to false the component will function exactly like it's superclass TROHTTPFileDispatcher.

property ServeROJavaScript: Boolean read write

ServeWithEvent  protected virtual    (declared in TROHTTPFileDispatcher)

Performs event based serving, fires OnRequest event.

procedure ServeWithEvent(aRequest: IROHTTPRequest; aResponse: IROHTTPResponse; aResponseData: TStream)

Parameters:

  • aRequest: The reference to the object describing the HTTP request.
  • aResponse: The reference to the object describing the HTTP response.
  • aResponseData: The stream that will contain the response data.

 

DefaultFile    (declared in TROHTTPFileDispatcher)

The name of the file that will be served for directory request.
Example: assume we have configured the server to serve for /js/ virtual folder. The request to get http://example.org/js will serve the file specified with this property. Note: the request without trailing slash (http://example.org/js) will be redirected to the location with the trailing slash (http://example.org/js/) using 302 HTTP response code. The user's browser will get the new location and display it to the user seamlessly.
The default value is index.html

property DefaultFile: string read write

Folder    (declared in TROHTTPFileDispatcher)

The local path that will correspond to the virtual folder from the Path property. If relative path is specified then the path to the program main module will be used as base path.

property Folder: string read write

Path    (declared in TROExtendedHttpDispatcher)

The request path the dispatcher will be activated for. For example, if this property contains /js then the dispatcher will be activated by the server channel to process such requests as http://example.org:8099/js/* (the asterisk means zero or more characters to continue the request path).

property Path: string read write

ServeFilesFromFolder    (declared in TROHTTPFileDispatcher)

Enables or disables serving files from the Folder. When this property has false value then the only option to serve files remains the OnRequest event handler. The default is true.

property ServeFilesFromFolder: Boolean read write

Server    (declared in TROExtendedHttpDispatcher)

Points to the HTTP server channel which the dispatcher works with.

property Server: IROHTTPServer read write

ServeROJavaScript

Enables or disables RemObjectsSDK.js script serving. If set to false the component will function exactly like it's superclass TROHTTPFileDispatcher.

property ServeROJavaScript: Boolean read write

 

constructor Create  override

Standard component constructor

constructor Create(AOwner: TComponent)

Parameters:

  • AOwner: Owner

Activate  virtual    (declared in TROExtendedHttpDispatcher)

procedure Activate

Assign  override

Copies the contents of another, similar object.

procedure Assign(Source: TPersistent)

Parameters:

  • Source: Instance whose properties will be copied

CanHandlePath    (declared in TROExtendedHttpDispatcher)

Return true if the given path can be handled by the dispatcher. The function compares the Path property content with the given path and chacks if the given path starts with the Path subpath.

function CanHandlePath(aPath: string): Boolean

Parameters:

  • aPath: The request path to check.

Deactivate  virtual    (declared in TROExtendedHttpDispatcher)

procedure Deactivate

FireOnRequest  protected virtual    (declared in TROHTTPFileDispatcher)

Fires the OnRequest event.

procedure FireOnRequest(Path: string; Data: TStream; out ContentType: string; out ResultCode: Integer; out Status: string)

Parameters:

  • Path: The request path.
  • Data: The response data - output parameter.
  • ContentType: The response content type - output parameter.
  • ResultCode: The response HTTP result code - output parameter.
  • Status: The response HTTP status message - output parameter.

Notification  protected override    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure Notification(aComponent: TComponent; Operation: TOperation)

Parameters:

  • aComponent: component
  • Operation: operation

NotifyDispose    (declared in TROExtendedHttpDispatcher)

This procedure is called when the server HTTP channel is about to be freed.

procedure NotifyDispose

Process  override    (declared in TROHTTPFileDispatcher)

The main method to perform the request processing ant to form the response. Called every time to process incoming requests if the dispatcher is suitable to process it (determined by CanHandlePath result).

procedure Process(aTransport: IROHTTPTransport; aRequest: IROHTTPRequest; aResponse: IROHTTPResponse; aRequestData: TStream; aResponseData: TStream)

Parameters:

  • aTransport: Http transport.
  • aRequest: Contains object implementing IROHTTPRequest interface that describes the request.
  • aResponse: Contains initialized object implementing IROHTTPResponse interface that should describe the response.
  • aRequestData: The data stream (TStream) that contains the raw HTTP request data except the header part.
  • aResponseData: Contais initialized and empty data stream (TStream) that shpuld be filled with the raw reponse data except the header part.

ReplyWithMessage  protected    (declared in TROHTTPFileDispatcher)

Internal utility method - prepares response with specified parameters and puts it into the response object and response stream.

procedure ReplyWithMessage(aCode: Integer; aStatus: string; aMessage: string; aResponse: IROHTTPResponse; aResponseData: TStream)

Parameters:

  • aCode: The HTTP response code.
  • aStatus: The HTTP response status message.
  • aMessage: The user understandable response message.
  • aResponse: The reference to the object describing the HTTP response.
  • aResponseData: The stream that will contain the response data.

ResolveContentType    (declared in TROHTTPFileDispatcher)

Resolves and returns content type based on the file extension. Contains the content type table for the most often used extensions, others are resolved using registry (Windows platforms only).

function ResolveContentType(aExtension: string): string

Parameters:

  • aExtension: The file extension to resolve.

ROFreeNotification    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure ROFreeNotification(aComponent: TComponent)

Parameters:

  • aComponent: component

RORemoveFreeNotification    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure RORemoveFreeNotification(aComponent: TComponent)

Parameters:

  • aComponent: component

SendRemoveNotification  protected    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure SendRemoveNotification(aComponent: TComponent)

Parameters:

  • aComponent: component

ServeCustom  protected override

Allows further customization of the serving process.

procedure ServeCustom(aFilePath: string; aRequest: IROHTTPRequest; aResponse: IROHTTPResponse; aResponseData: TStream)

Parameters:

  • aFilePath: The requested file path.
  • aRequest: The reference to the object describing the HTTP request.
  • aResponse: The reference to the object describing the HTTP response.
  • aResponseData: The stream that will contain the response data.

ServeFromFolder  protected virtual    (declared in TROHTTPFileDispatcher)

Locates file in the disk folder and forms the proper response.

procedure ServeFromFolder(aFilePath: string; aResponse: IROHTTPResponse; aResponseData: TStream)

Parameters:

  • aFilePath: The requested file path.
  • aResponse: The reference to the object describing the HTTP response.
  • aResponseData: The stream that will contain the response data.

ServeWithEvent  protected virtual    (declared in TROHTTPFileDispatcher)

Performs event based serving, fires OnRequest event.

procedure ServeWithEvent(aRequest: IROHTTPRequest; aResponse: IROHTTPResponse; aResponseData: TStream)

Parameters:

  • aRequest: The reference to the object describing the HTTP request.
  • aResponse: The reference to the object describing the HTTP response.
  • aResponseData: The stream that will contain the response data.

 

OnRequest    (declared in TROHTTPFileDispatcher)

Allows full customization of serving files by the user.
NOTICE: when this event is handled user's code takes full responsibility of the request processing, no other processing actions are performed except request validity check before the event is fired.

property OnRequest: TROHTTPFileDispatcherEvent read write
delegate: procedure OnRequest(Sender: TObject; Path: string; Data: TStream; out ContentType: string; out ResultCode: Integer; out Status: string)