HttpFileDispatcher

Overview

The HttpFileDispatcher class provides allows to serve HTTP resource requests. In other words this class allows to turn a Http or SuperHttp channel into a web server.

The priority of serving HTTP requests by this class is:

Try to retrieve requested data via the Request event handler

Try to find requested file in the Folder folder (this step is skipped if the ServeFilesFromFolder property is set to false)

Try to find requested resource in the assembly resources

If requested data is still not acquired then send back the HTTP 404: NotFound error code.

Descendants of this class are used to serve Remoting SDK for JavaScript and Data Abstract requests.

See the IHttpDispatcher interface description for more details.

Location


 

constructor

Creates new instance of the HttpFileDispatcher class.

 

constructor

 

HttpFileDispatcher()

 

Sub New()

Activate    (declared in ExtendedHttpDispatcher)

 

method Activate

 

void Activate()

 

Sub Activate()

CanHandlePath    (declared in ExtendedHttpDispatcher)

Checks if the provided relative HTTP request path can be processed by this dispatcher.

 

method CanHandlePath(path: String): Boolean

 

Boolean CanHandlePath(String path)

 

Function CanHandlePath(path As String) As Boolean

Parameters:

  • path:

Deactivate    (declared in ExtendedHttpDispatcher)

 

method Deactivate

 

void Deactivate()

 

Sub Deactivate()

DefaultFile

Gets or sets a name(resource) of the file that will be sent back by default whenever a request comes in that doesn't specify a filename.

The default value is index.html.

 

property DefaultFile: String read write;

 

String DefaultFile { get; set; }

 

Property DefaultFile() As String

Dispose  protected    (declared in ExtendedHttpDispatcher)

If the disposing parameter is set to true, this method unregisters this dispatcher instance from the server.

 

method Dispose(disposing: Boolean)

 

void Dispose(Boolean disposing)

 

Sub Dispose(disposing As Boolean)

Parameters:

  • disposing: If set to true, the current dispatcher instance will be unregistered from the server.

Folder

Gets or sets a path to the folder where server will try to find the requested file.

The default value is html.

 

property Folder: String read write;

 

String Folder { get; set; }

 

Property Folder() As String

IsFileContainedInResource  protected

Returns true if requested resource can be found in the resources section of any assembly from the ResourceAssemblies assembly list.

 

method IsFileContainedInResource(fileName: String): Boolean

 

Boolean IsFileContainedInResource(String fileName)

 

Function IsFileContainedInResource(fileName As String) As Boolean

Parameters:

  • fileName: A resource name to check.

MESSAGE_FORBIDDEN  protected

 

const MESSAGE_FORBIDDEN: String = "Forbidden";

 

const String MESSAGE_FORBIDDEN = "Forbidden"

 

Dim MESSAGE_FORBIDDEN As String = "Forbidden"

MESSAGE_INTERNAL_ERROR  protected

 

const MESSAGE_INTERNAL_ERROR: String = "Server Error<br/>";

 

const String MESSAGE_INTERNAL_ERROR = "Server Error<br/>"

 

Dim MESSAGE_INTERNAL_ERROR As String = "Server Error<br/>"

MESSAGE_NOT_FOUND  protected

 

const MESSAGE_NOT_FOUND: String = "Requested Resource not Found";

 

const String MESSAGE_NOT_FOUND = "Requested Resource not Found"

 

Dim MESSAGE_NOT_FOUND As String = "Requested Resource not Found"

MESSAGE_READ_ERROR  protected

 

const MESSAGE_READ_ERROR: String = "Resource could not be read:<br/>";

 

const String MESSAGE_READ_ERROR = "Resource could not be read:<br/>"

 

Dim MESSAGE_READ_ERROR As String = "Resource could not be read:<br/>"

NotifyDispose    (declared in ExtendedHttpDispatcher)

This method is called when the ExtendedDispatcherList instance where the current instance is registered is disposed.

 

method NotifyDispose

 

void NotifyDispose()

 

Sub NotifyDispose()

OnRequest  protected

Triggers the Request event.

 

method OnRequest(e: RequestEventArgs)

 

void OnRequest(RequestEventArgs e)

 

Sub OnRequest(e As RequestEventArgs)

Parameters:

  • e: Request arguments that will be provided to the Request event handler.

Path    (declared in ExtendedHttpDispatcher)

Gets or sets the relative HTTP path requests that will be processed by the current HttpDispatcher instance.

Path should begin with "/".

 

property Path: String read write;

 

String Path { get; set; }

 

Property Path() As String

Process (IServerChannelInfo, IHttpRequest, IHttpResponse, Stream, Stream)    (declared in ExtendedHttpDispatcher)

 

method Process(context: IServerChannelInfo; request: IHttpRequest; response: IHttpResponse; requestData: Stream; responseData: Stream)

 

void Process(IServerChannelInfo context, IHttpRequest request, IHttpResponse response, Stream requestData, Stream responseData)

 

Sub Process(context As IServerChannelInfo, request As IHttpRequest, response As IHttpResponse, requestData As Stream, responseData As Stream)

Parameters:

  • context:
  • request:
  • response:
  • requestData:
  • responseData:

Process (IServerChannelInfo, IHttpRequest, IHttpResponse, Stream, Stream)

 

method Process(context: IServerChannelInfo; request: IHttpRequest; responseHeader: IHttpResponse; requestData: Stream; responseData: Stream)

 

void Process(IServerChannelInfo context, IHttpRequest request, IHttpResponse responseHeader, Stream requestData, Stream responseData)

 

Sub Process(context As IServerChannelInfo, request As IHttpRequest, responseHeader As IHttpResponse, requestData As Stream, responseData As Stream)

Parameters:

  • context:
  • request:
  • responseHeader:
  • requestData:
  • responseData:

Request

This event allows custom processing of incoming resource requests. It is raised prior to file-system access and resources collection traverse.

Main purpose of this event is to allow to serve HTTP requests to data that cannot be stored in the filesystem or server app's assemblies (like server workload info page).

 

event Request: RequestEventHandler;
delegate: method Request(sender: Object; e: RequestEventArgs)

 

delegate RequestEventHandler Request()
delegate: void Request(Object sender, RequestEventArgs e)

 

Event Request As RequestEventHandler
delegate: Sub Request(sender As Object, e As RequestEventArgs)

ResolveContentType  protected

Determines MIME content type according to the provided file extension.

This method extensively uses the extensions cache unitialized by the InitializeExtensionsCache method.

In case of cache miss this method tries to read content type from the Windows Registry and to add it to the extensions cache.

 

method ResolveContentType(fileName: String): String

 

String ResolveContentType(String fileName)

 

Function ResolveContentType(fileName As String) As String

Parameters:

  • fileName: A file name for which the content type should be resolved.

ResourceAssemblies  protected

Gets a set of assemblies where component will try to find a requested resource if it wasn't provided by the Request event handler or found in the Folder folder.

The devault value is the RemObjects.SDK.Server assemble, however this property is usually overriden in the HttpFileDispatcher descendants

 

property ResourceAssemblies: array of Assembly read;

 

Assembly[] ResourceAssemblies { get; }

 

ReadOnly Property ResourceAssemblies() As Assembly()

ServeFilesFromFolder

Gets or sets a flag indicating whether the current instance will try to find requested resource in the Folder folder.

Setting this property to false can significantly speed-up the request processing by avoiding direct file-system access.

The defaul value is true.

 

property ServeFilesFromFolder: Boolean read write;

 

Boolean ServeFilesFromFolder { get; set; }

 

Property ServeFilesFromFolder() As Boolean

Server    (declared in ExtendedHttpDispatcher)

The IHttpServer instance this dispatcher is registered in.

The ExtendedHttpDispatcher instance is automatically registered in the provided IHttpServer instance's extended dispatchers list when this property is set.

 

property Server: IHttpServer read write;

 

IHttpServer Server { get; set; }

 

Property Server() As IHttpServer

 

MESSAGE_FORBIDDEN  protected

 

const MESSAGE_FORBIDDEN: String = "Forbidden";

 

const String MESSAGE_FORBIDDEN = "Forbidden"

 

Dim MESSAGE_FORBIDDEN As String = "Forbidden"

MESSAGE_INTERNAL_ERROR  protected

 

const MESSAGE_INTERNAL_ERROR: String = "Server Error<br/>";

 

const String MESSAGE_INTERNAL_ERROR = "Server Error<br/>"

 

Dim MESSAGE_INTERNAL_ERROR As String = "Server Error<br/>"

MESSAGE_NOT_FOUND  protected

 

const MESSAGE_NOT_FOUND: String = "Requested Resource not Found";

 

const String MESSAGE_NOT_FOUND = "Requested Resource not Found"

 

Dim MESSAGE_NOT_FOUND As String = "Requested Resource not Found"

MESSAGE_READ_ERROR  protected

 

const MESSAGE_READ_ERROR: String = "Resource could not be read:<br/>";

 

const String MESSAGE_READ_ERROR = "Resource could not be read:<br/>"

 

Dim MESSAGE_READ_ERROR As String = "Resource could not be read:<br/>"

 

DefaultFile

Gets or sets a name(resource) of the file that will be sent back by default whenever a request comes in that doesn't specify a filename.

The default value is index.html.

 

property DefaultFile: String read write;

 

String DefaultFile { get; set; }

 

Property DefaultFile() As String

Folder

Gets or sets a path to the folder where server will try to find the requested file.

The default value is html.

 

property Folder: String read write;

 

String Folder { get; set; }

 

Property Folder() As String

Path    (declared in ExtendedHttpDispatcher)

Gets or sets the relative HTTP path requests that will be processed by the current HttpDispatcher instance.

Path should begin with "/".

 

property Path: String read write;

 

String Path { get; set; }

 

Property Path() As String

ResourceAssemblies  protected

Gets a set of assemblies where component will try to find a requested resource if it wasn't provided by the Request event handler or found in the Folder folder.

The devault value is the RemObjects.SDK.Server assemble, however this property is usually overriden in the HttpFileDispatcher descendants

 

property ResourceAssemblies: array of Assembly read;

 

Assembly[] ResourceAssemblies { get; }

 

ReadOnly Property ResourceAssemblies() As Assembly()

ServeFilesFromFolder

Gets or sets a flag indicating whether the current instance will try to find requested resource in the Folder folder.

Setting this property to false can significantly speed-up the request processing by avoiding direct file-system access.

The defaul value is true.

 

property ServeFilesFromFolder: Boolean read write;

 

Boolean ServeFilesFromFolder { get; set; }

 

Property ServeFilesFromFolder() As Boolean

Server    (declared in ExtendedHttpDispatcher)

The IHttpServer instance this dispatcher is registered in.

The ExtendedHttpDispatcher instance is automatically registered in the provided IHttpServer instance's extended dispatchers list when this property is set.

 

property Server: IHttpServer read write;

 

IHttpServer Server { get; set; }

 

Property Server() As IHttpServer

 

constructor

Creates new instance of the HttpFileDispatcher class.

 

constructor

 

HttpFileDispatcher()

 

Sub New()

Activate    (declared in ExtendedHttpDispatcher)

 

method Activate

 

void Activate()

 

Sub Activate()

CanHandlePath    (declared in ExtendedHttpDispatcher)

Checks if the provided relative HTTP request path can be processed by this dispatcher.

 

method CanHandlePath(path: String): Boolean

 

Boolean CanHandlePath(String path)

 

Function CanHandlePath(path As String) As Boolean

Parameters:

  • path:

Deactivate    (declared in ExtendedHttpDispatcher)

 

method Deactivate

 

void Deactivate()

 

Sub Deactivate()

Dispose  protected    (declared in ExtendedHttpDispatcher)

If the disposing parameter is set to true, this method unregisters this dispatcher instance from the server.

 

method Dispose(disposing: Boolean)

 

void Dispose(Boolean disposing)

 

Sub Dispose(disposing As Boolean)

Parameters:

  • disposing: If set to true, the current dispatcher instance will be unregistered from the server.

IsFileContainedInResource  protected

Returns true if requested resource can be found in the resources section of any assembly from the ResourceAssemblies assembly list.

 

method IsFileContainedInResource(fileName: String): Boolean

 

Boolean IsFileContainedInResource(String fileName)

 

Function IsFileContainedInResource(fileName As String) As Boolean

Parameters:

  • fileName: A resource name to check.

NotifyDispose    (declared in ExtendedHttpDispatcher)

This method is called when the ExtendedDispatcherList instance where the current instance is registered is disposed.

 

method NotifyDispose

 

void NotifyDispose()

 

Sub NotifyDispose()

OnRequest  protected

Triggers the Request event.

 

method OnRequest(e: RequestEventArgs)

 

void OnRequest(RequestEventArgs e)

 

Sub OnRequest(e As RequestEventArgs)

Parameters:

  • e: Request arguments that will be provided to the Request event handler.

Process (IServerChannelInfo, IHttpRequest, IHttpResponse, Stream, Stream)    (declared in ExtendedHttpDispatcher)

 

method Process(context: IServerChannelInfo; request: IHttpRequest; response: IHttpResponse; requestData: Stream; responseData: Stream)

 

void Process(IServerChannelInfo context, IHttpRequest request, IHttpResponse response, Stream requestData, Stream responseData)

 

Sub Process(context As IServerChannelInfo, request As IHttpRequest, response As IHttpResponse, requestData As Stream, responseData As Stream)

Parameters:

  • context:
  • request:
  • response:
  • requestData:
  • responseData:

Process (IServerChannelInfo, IHttpRequest, IHttpResponse, Stream, Stream)

 

method Process(context: IServerChannelInfo; request: IHttpRequest; responseHeader: IHttpResponse; requestData: Stream; responseData: Stream)

 

void Process(IServerChannelInfo context, IHttpRequest request, IHttpResponse responseHeader, Stream requestData, Stream responseData)

 

Sub Process(context As IServerChannelInfo, request As IHttpRequest, responseHeader As IHttpResponse, requestData As Stream, responseData As Stream)

Parameters:

  • context:
  • request:
  • responseHeader:
  • requestData:
  • responseData:

ResolveContentType  protected

Determines MIME content type according to the provided file extension.

This method extensively uses the extensions cache unitialized by the InitializeExtensionsCache method.

In case of cache miss this method tries to read content type from the Windows Registry and to add it to the extensions cache.

 

method ResolveContentType(fileName: String): String

 

String ResolveContentType(String fileName)

 

Function ResolveContentType(fileName As String) As String

Parameters:

  • fileName: A file name for which the content type should be resolved.

 

Request

This event allows custom processing of incoming resource requests. It is raised prior to file-system access and resources collection traverse.

Main purpose of this event is to allow to serve HTTP requests to data that cannot be stored in the filesystem or server app's assemblies (like server workload info page).

 

event Request: RequestEventHandler;
delegate: method Request(sender: Object; e: RequestEventArgs)

 

delegate RequestEventHandler Request()
delegate: void Request(Object sender, RequestEventArgs e)

 

Event Request As RequestEventHandler
delegate: Sub Request(sender As Object, e As RequestEventArgs)