HttpServerBoxed 0.0.11 alpha
A simple http server for C# and .NET
|
This class contains all the settings of the server. More...
Public Member Functions | |
Configuration () | |
Creates a default fail-safe configuration (still, the port could be in use) | |
Configuration (string content) | |
Instantiate configuration from a json file (content passed as string) | |
Configuration (string address, ushort port, string staticPath, Debugger? debugInfo=null, IPMode ipMode=IPMode.ANY, int requestMaxSize=KILOBYTE, ulong? defaultSessionExpirationTime=null, SslConfiguration? sslConfiguration=null) | |
Instantiate a configuration with the minimal settings. | |
void | SaveToJson (string path) |
Save the current configuration to a json file. | |
void | GET (string path, Delegate func) |
Map a function to a path that will reply with a GET response. | |
void | POST (string path, Delegate func) |
Map a function to a path that will reply with a POST response. | |
void | HEAD (string path, Delegate func) |
Map a function to a path that will reply with a HEAD response. | |
void | PUT (string path, Delegate func) |
Map a function to a path that will reply with a HEAD response. | |
void | DELETE (string path, Delegate func) |
Map a function to a path that will reply with a DELETE response. | |
void | PATCH (string path, Delegate func) |
Map a function to a path that will reply with a PATCH response. | |
void | TRACE (string path, Delegate func) |
Map a function to a path that will reply with a TRACE response. | |
void | OPTIONS (string path, Delegate func) |
Map a function to a path that will reply with a OPTIONS response. | |
void | CONNECT (string path, Delegate func) |
Map a function to a path that will reply with a CONNECT response. | |
void | AddSharedObject (string name, object o) |
Add an object shared between all servlet. | |
object | GetSharedObject (string name) |
Get an object shared between all servlet. | |
void | RemoveSharedObject (string name) |
Remove an object shared between all servlet. | |
void | AddCustomGlobalHeader (string name, string value) |
Add an HTTP Response header that will be added to ALL the responses. | |
void | RemoveCustomGlobalHeader (string name) |
Remove a global HTTP Response header previously added. | |
string | GetCustomGlobalHeader (string name) |
Gets the value of a global HTTP Response header previously added. | |
void | AddCustomGlobalCookie (Cookie cookie) |
Add (Or replaces) a cookie that will be added to ALL the responses. | |
void | RemoveCustomGlobalCookie (string name) |
Remove a global cookie previously added. | |
Cookie | GetCustomGlobalCookie (string name) |
Gets the value of a global cookie previously added. | |
List< string > | GetRawArguments () |
void | HideBrandingOnStartup () |
override string | ToString () |
String representing the configuration. | |
List< Tuple< string, string > > | GetAllRoutes () |
Static Public Member Functions | |
static Configuration | LoadFromJson (string path) |
Instantiate configuration from a json file passed as parameter. | |
Public Attributes | |
string | Address |
The server listening address, ex : "127.0.0.1" or "192.168.1.2" or "" (for any address) | |
ushort | Port |
The server listening port. | |
string | PublicURL = "" |
When this field is set, it will be used for Unsecure SSL requests upgrade. | |
string | StaticFolderPath |
Indicates the location where all static files will be searched and served from. | |
Debugger | Debug |
Holds all debug information and routines. | |
int | RequestMaxSize |
Specifies the size in bytes of the buffer that will contain the HTTP request. | |
bool | HideBranding = false |
Hide the HSB logo on startup. | |
ulong | DefaultSessionExpirationTime |
Sets the expiration time of the session. | |
string | CustomServerName = "" |
When set, the server will use this name instead of the default one (default is: HSB-#/assembly_version (os_version)) | |
bool | IPAutoblock = false |
If this is set, the server will block the IP of the client if they try to access unsafe paths. | |
BLOCK_MODE | BlockMode = BLOCK_MODE.NONE |
Setting this to BlockMode.WhiteList will make the server accept only requests from ip presents in ip_whitelist.txt if set to BlockMode.BlackList will ban requests from ip presents in ip_blacklist.txt. | |
List< string > | PermanentIPList = [] |
This list contains all the IP addresses that will be allowed/denied to access the server, it's behavior depends on the blockMode If BlockMode is set to BlockMode.OKLIST, only the IP addresses in this list will be allowed to access the server If BlockMode is set to BlockMode.BANLIST, the IP addresses in this list will be banned from accessing the server. | |
bool | ServeEmbeddedResource = false |
If set to true, the server will try to search for the requested resource in the assembly resources if fails to find it, the usual chain of execution will be followed. | |
string | EmbeddedResourcePrefix = "" |
If ServeEmbeddedResource is set to true, this will be prepended to the requested resource ex: if the requested resource is /index.html and the prefix is set to "www" the server will search for the resource in the assembly resources at www/index.html. | |
SslConfiguration | SslSettings |
Contains the SSL configuration properties. | |
Static Public Attributes | |
const int | KILOBYTE = 1024 |
Defines the size of a kilobyte in bytes, useful to set the requestMaxSize. | |
const int | MEGABYTE = KILOBYTE * KILOBYTE |
Defines the size of a megabyte in bytes, useful to set the requestMaxSize. | |
Protected Attributes | |
Dictionary< string, object > | sharedObjects = [] |
Useful to share objects between servlets without using the singleton technique. | |
Dictionary< string, string > | customGlobalHeaders = [] |
headers added to ANY response | |
Dictionary< string, Cookie > | customGlobalCookies = [] |
Cookies added to ANY response. | |
Properties | |
IPMode | ListeningMode [get, set] |
Set server listening mode to any, only ipv4 or only ipv6. This is valid only if the address is set to "". | |
Dictionary< string, string > | CustomGlobalHeaders [get] |
Gets all global HTTP Response headers. | |
Dictionary< string, Cookie > | CustomGlobalCookies [get] |
Gets all global cookies. | |
This class contains all the settings of the server.
Definition at line 11 of file Configuration.cs.
HSB.Configuration.Configuration | ( | ) |
Creates a default fail-safe configuration (still, the port could be in use)
Definition at line 122 of file Configuration.cs.
HSB.Configuration.Configuration | ( | string | content | ) |
Instantiate configuration from a json file (content passed as string)
jsonContent | The content of the JSON file |
Definition at line 139 of file Configuration.cs.
HSB.Configuration.Configuration | ( | string | address, |
ushort | port, | ||
string | staticPath, | ||
Debugger? | debugInfo = null , |
||
IPMode | ipMode = IPMode::ANY , |
||
int | requestMaxSize = KILOBYTE , |
||
ulong? | defaultSessionExpirationTime = null , |
||
SslConfiguration? | sslConfiguration = null |
||
) |
Instantiate a configuration with the minimal settings.
address | Listening address (es: "127.0.0.1" or "192.168.1.2" or "" for any) |
port | Listening port |
staticPath | Path of the static folder |
debugInfo | Class holding debugging information |
IPv4Only | Sets whether or not listen only to ipv6 addresses |
Definition at line 194 of file Configuration.cs.
void HSB.Configuration.AddCustomGlobalCookie | ( | Cookie | cookie | ) |
Add (Or replaces) a cookie that will be added to ALL the responses.
name | Name of the cookie |
value | Value of the cookie |
Definition at line 336 of file Configuration.cs.
void HSB.Configuration.AddCustomGlobalHeader | ( | string | name, |
string | value | ||
) |
Add an HTTP Response header that will be added to ALL the responses.
name | Name of the header |
value | Value of the header |
void HSB.Configuration.AddSharedObject | ( | string | name, |
object | o | ||
) |
Add an object shared between all servlet.
name | Name of the object |
o | Object to share |
void HSB.Configuration.CONNECT | ( | string | path, |
Delegate | func | ||
) |
Map a function to a path that will reply with a CONNECT response.
path | Mapping |
func | Function that will handle the request |
void HSB.Configuration.DELETE | ( | string | path, |
Delegate | func | ||
) |
Map a function to a path that will reply with a DELETE response.
path | Mapping |
func | Function that will handle the request |
void HSB.Configuration.GET | ( | string | path, |
Delegate | func | ||
) |
Map a function to a path that will reply with a GET response.
path | Mapping |
func | Function that will handle the request |
List< Tuple< string, string > > HSB.Configuration.GetAllRoutes | ( | ) |
Definition at line 389 of file Configuration.cs.
Cookie HSB.Configuration.GetCustomGlobalCookie | ( | string | name | ) |
Gets the value of a global cookie previously added.
name | Name of the cookie |
string HSB.Configuration.GetCustomGlobalHeader | ( | string | name | ) |
Gets the value of a global HTTP Response header previously added.
name | Name of the header |
object HSB.Configuration.GetSharedObject | ( | string | name | ) |
Get an object shared between all servlet.
name | Name of the shared object |
void HSB.Configuration.HEAD | ( | string | path, |
Delegate | func | ||
) |
Map a function to a path that will reply with a HEAD response.
path | Mapping |
func | Function that will handle the request |
|
static |
Instantiate configuration from a json file passed as parameter.
path |
Definition at line 214 of file Configuration.cs.
void HSB.Configuration.OPTIONS | ( | string | path, |
Delegate | func | ||
) |
Map a function to a path that will reply with a OPTIONS response.
path | Mapping |
func | Function that will handle the request |
void HSB.Configuration.PATCH | ( | string | path, |
Delegate | func | ||
) |
Map a function to a path that will reply with a PATCH response.
path | Mapping |
func | Function that will handle the request |
void HSB.Configuration.POST | ( | string | path, |
Delegate | func | ||
) |
Map a function to a path that will reply with a POST response.
path | Mapping |
func | Function that will handle the request |
void HSB.Configuration.PUT | ( | string | path, |
Delegate | func | ||
) |
Map a function to a path that will reply with a HEAD response.
path | Mapping |
func | Function that will handle the request |
void HSB.Configuration.RemoveCustomGlobalCookie | ( | string | name | ) |
Remove a global cookie previously added.
name | Name of the cookie |
void HSB.Configuration.RemoveCustomGlobalHeader | ( | string | name | ) |
Remove a global HTTP Response header previously added.
name | Name of the header |
void HSB.Configuration.RemoveSharedObject | ( | string | name | ) |
Remove an object shared between all servlet.
name | Name of the shared object |
void HSB.Configuration.SaveToJson | ( | string | path | ) |
Save the current configuration to a json file.
path |
Definition at line 223 of file Configuration.cs.
override string HSB.Configuration.ToString | ( | ) |
String representing the configuration.
Definition at line 365 of file Configuration.cs.
void HSB.Configuration.TRACE | ( | string | path, |
Delegate | func | ||
) |
Map a function to a path that will reply with a TRACE response.
path | Mapping |
func | Function that will handle the request |
string HSB.Configuration.Address |
The server listening address, ex : "127.0.0.1" or "192.168.1.2" or "" (for any address)
Definition at line 21 of file Configuration.cs.
BLOCK_MODE HSB.Configuration.BlockMode = BLOCK_MODE.NONE |
Setting this to BlockMode.WhiteList will make the server accept only requests from ip presents in ip_whitelist.txt if set to BlockMode.BlackList will ban requests from ip presents in ip_blacklist.txt.
Definition at line 90 of file Configuration.cs.
|
protected |
Cookies added to ANY response.
Definition at line 69 of file Configuration.cs.
|
protected |
headers added to ANY response
Definition at line 65 of file Configuration.cs.
string HSB.Configuration.CustomServerName = "" |
When set, the server will use this name instead of the default one (default is: HSB-#/assembly_version (os_version))
Definition at line 81 of file Configuration.cs.
Debugger HSB.Configuration.Debug |
Holds all debug information and routines.
Definition at line 41 of file Configuration.cs.
ulong HSB.Configuration.DefaultSessionExpirationTime |
Sets the expiration time of the session.
Definition at line 73 of file Configuration.cs.
string HSB.Configuration.EmbeddedResourcePrefix = "" |
If ServeEmbeddedResource is set to true, this will be prepended to the requested resource ex: if the requested resource is /index.html and the prefix is set to "www" the server will search for the resource in the assembly resources at www/index.html.
Definition at line 108 of file Configuration.cs.
bool HSB.Configuration.HideBranding = false |
Hide the HSB logo on startup.
Definition at line 57 of file Configuration.cs.
bool HSB.Configuration.IPAutoblock = false |
If this is set, the server will block the IP of the client if they try to access unsafe paths.
Definition at line 85 of file Configuration.cs.
|
static |
Defines the size of a kilobyte in bytes, useful to set the requestMaxSize.
Definition at line 49 of file Configuration.cs.
Defines the size of a megabyte in bytes, useful to set the requestMaxSize.
Definition at line 53 of file Configuration.cs.
List<string> HSB.Configuration.PermanentIPList = [] |
This list contains all the IP addresses that will be allowed/denied to access the server, it's behavior depends on the blockMode If BlockMode is set to BlockMode.OKLIST, only the IP addresses in this list will be allowed to access the server If BlockMode is set to BlockMode.BANLIST, the IP addresses in this list will be banned from accessing the server.
Note that IPv6 and IPv4 are considered different ips!
Definition at line 97 of file Configuration.cs.
ushort HSB.Configuration.Port |
The server listening port.
Definition at line 25 of file Configuration.cs.
string HSB.Configuration.PublicURL = "" |
When this field is set, it will be used for Unsecure SSL requests upgrade.
Definition at line 29 of file Configuration.cs.
int HSB.Configuration.RequestMaxSize |
Specifies the size in bytes of the buffer that will contain the HTTP request.
Definition at line 45 of file Configuration.cs.
bool HSB.Configuration.ServeEmbeddedResource = false |
If set to true, the server will try to search for the requested resource in the assembly resources if fails to find it, the usual chain of execution will be followed.
Definition at line 102 of file Configuration.cs.
|
protected |
Useful to share objects between servlets without using the singleton technique.
Definition at line 61 of file Configuration.cs.
SslConfiguration HSB.Configuration.SslSettings |
Contains the SSL configuration properties.
Definition at line 117 of file Configuration.cs.
string HSB.Configuration.StaticFolderPath |
Indicates the location where all static files will be searched and served from.
Definition at line 37 of file Configuration.cs.
|
get |
Gets all global cookies.
Definition at line 355 of file Configuration.cs.
|
get |
Gets all global HTTP Response headers.
Definition at line 328 of file Configuration.cs.
|
getset |
Set server listening mode to any, only ipv4 or only ipv6. This is valid only if the address is set to "".
Definition at line 33 of file Configuration.cs.