Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ProxyResource.cs
1using System.Collections.Generic;
2using System.Text;
3using System.Threading.Tasks;
6using Waher.Things;
9
11{
16 {
21 : base(null, null)
22 {
23 this.LocalResource = string.Empty;
24 this.RemoteDomain = string.Empty;
25 this.RemoteFolder = string.Empty;
26 this.RemotePort = 0;
27 this.Encrypted = false;
28 this.UseSession = false;
29 this.TimeoutMs = 30000;
30 }
31
45 int RemotePort, bool Encrypted, bool UseSession, int TimeoutMs)
46 : base(Source, Parent)
47 {
48 this.LocalResource = LocalResource;
49 this.RemoteDomain = RemoteDomain;
50 this.RemoteFolder = RemoteFolder;
51 this.RemotePort = RemotePort;
52 this.Encrypted = Encrypted;
53 this.UseSession = UseSession;
54 this.TimeoutMs = TimeoutMs;
55 }
56
60 [Page(7, "Configuration")]
61 [Header(85, "Local Resource:")]
62 [ToolTip(86, "Local Resource that will act as a reverse proxy.")]
63 [Required]
64 public string LocalResource { get; set; }
65
69 [Page(7, "Configuration")]
70 [Header(87, "Remote Domain:")]
71 [ToolTip(88, "Domain of web server to forward requests to.")]
72 [Required]
73 public string RemoteDomain { get; set; }
74
78 [Page(7, "Configuration")]
79 [Header(89, "Remote Folder:")]
80 [ToolTip(90, "Base folder on remote domain that requests will be forwarded to.")]
81 public string RemoteFolder { get; set; }
82
86 [Page(7, "Configuration")]
87 [Header(91, "Remote Port:")]
88 [ToolTip(92, "Port number of remote domain that requests will be forwarded to.")]
89 [Range(1, 65535)]
90 [Required]
91 public int RemotePort { get; set; }
92
96 [Page(7, "Configuration")]
97 [Header(93, "Use encryption.")]
98 [ToolTip(94, "If forwarded requests are encrypted (HTTPS) or not (HTTP).")]
99 [Required]
100 public bool Encrypted { get; set; }
101
105 [Page(7, "Configuration")]
106 [Header(95, "Use proxy-session.")]
107 [ToolTip(96, "If the proxy uses a session itself.")]
108 [Text(TextPosition.AfterField, 97, "Note: By making the proxy use a proxy-session itself, the broker can add SSO token information in forwarded requests, making underlying services aware of the currently logged in user identity.")]
109 public bool UseSession { get; set; }
110
114 [Page(7, "Configuration")]
115 [Header(34, "Timeout (ms):")]
116 [ToolTip(98, "Timeout afforded to forwarded requests, in milliseconds, before they are assumed to have failed.")]
117 [Range(1, 120 * 1000)]
118 [Text(TextPosition.AfterField, 63, "Note: Changes will take effect after broker has been restarted.")]
119 public int TimeoutMs { get; set; }
120
124 public override string NodeId => this.LocalResource;
125
130 public override Task<string> GetTypeNameAsync(Language Language) => Language.GetStringAsync(typeof(GatewayConfigSource), 99, "Reverse Proxy");
131
137 public override Task<bool> AcceptsParentAsync(INode Parent)
138 {
139 return Task.FromResult(Parent is WebServer);
140 }
141
148 public override async Task<IEnumerable<Parameter>> GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
149 {
150 LinkedList<Parameter> Parameters = new LinkedList<Parameter>();
152
153 StringBuilder sb = new StringBuilder();
154
155 sb.Append("http");
156 if (this.Encrypted)
157 sb.Append('s');
158
159 sb.Append("://");
160 sb.Append(this.RemoteDomain);
161
163 {
164 sb.Append(':');
165 sb.Append(this.RemotePort.ToString());
166 }
167
168 sb.Append(this.RemoteFolder);
169
170 Parameters.AddLast(new StringParameter("Location", await Namespace.GetStringAsync(82, "Location"), sb.ToString()));
171 Parameters.AddLast(new BooleanParameter("UseSession", await Namespace.GetStringAsync(53, "Session"), this.UseSession));
172 Parameters.AddLast(new Int32Parameter("TimeoutMs", await Namespace.GetStringAsync(54, "Timeout (ms)"), this.TimeoutMs));
173
174 return Parameters;
175 }
176 }
177}
Implements an HTTP server.
Definition: HttpServer.cs:36
const int DefaultHttpPort
Default HTTP Port (80).
Definition: HttpServer.cs:40
const int DefaultHttpsPort
Default HTTPS port (443).
Definition: HttpServer.cs:45
Contains information about a language.
Definition: Language.cs:17
Task< string > GetStringAsync(Type Type, int Id, string Default)
Gets the string value of a string ID. If no such string exists, a string is created with the default ...
Definition: Language.cs:209
async Task< Namespace > GetNamespaceAsync(string Name)
Gets the namespace object, given its name, if available.
Definition: Language.cs:99
Contains information about a namespace in a language.
Definition: Namespace.cs:17
Task< LanguageString > GetStringAsync(int Id)
Gets the string object, given its ID, if available.
Definition: Namespace.cs:65
Abstract base class for gateway configuration nodes.
virtual INode Parent
Parent Node, or null if a root node.
GatewayConfigSource Source
Source hosting the node.
Defines a proxy resource to act as a reverse proxy.
bool Encrypted
If forwarded requests are encrypted (HTTPS) or not (HTTP).
string RemoteDomain
Location client is redirected to.
bool UseSession
If forwarded requests are encrypted (HTTPS) or not (HTTP).
string RemoteFolder
If sub-paths should be included in the redirection.
ProxyResource()
Defines a proxy resource to act as a reverse proxy.
override async Task< IEnumerable< Parameter > > GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
Gets displayable parameters.
override Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
int TimeoutMs
If redirection is permanent (true) or temporary (false).
ProxyResource(GatewayConfigSource Source, WebServer Parent, string LocalResource, string RemoteDomain, string RemoteFolder, int RemotePort, bool Encrypted, bool UseSession, int TimeoutMs)
Defines a proxy resource to act as a reverse proxy.
override Task< bool > AcceptsParentAsync(INode Parent)
If the node accepts a presumptive parent, i.e. can be added to that parent (if that parent accepts th...
int RemotePort
If redirection is permanent (true) or temporary (false).
Tokens available in request.
Definition: RequestOrigin.cs:9
Interface for nodes that are published through the concentrator interface.
Definition: INode.cs:49
TextPosition
Where the instructions are to be place.
Definition: TextAttribute.cs:9