| Class | Description |
|---|---|
| ConnectionKMethod | This class is a KMethod with all the code for dealing with an incoming HTTP connection. The WebServer creates one of these ConnectionKMethods for each client that connects to the server. Notes on Keep-Alive connections: There are 2 fields in the AgentRequest that pertain to keep-alive connections: KEEP_ALIVE and KEEP_ALIVE_FIELD. The KEEP_ALIVE_FIELD property is set by the ConnectionKMethod, if this property is NOT set, a Keep-Alive connection cannot be used. The KEEP_ALIVE property is set by the agent that handles the request, if this property is set, the ConnectionKMethod will keep the connection alive. The agent (for instance, a HTTPFileServerAgent) that handles the request is responsible for the following: It must return a content-length header in the response, this usually means the agent must return its own HTTP response. If a keep alive is allowed, and the client wants a keep-alive, the agent must return the Connection: Keep-Alive field as well as the contents of the KEEP_ALIVE_FIELD property. If a keep alive is allowed, and the client wants a keep-alive, the agent must set the KEEP_ALIVE property in the AgentRequest. If a keep alive is allowed, and the client wants a keep-alive, the agent must NOT close the Socket or the Socket streams. |
| ConnectionKMethod.BackInputStream | Provides functionality to read and unread from a Stream. |
| HTMLFormWriter | HTMLFormWriter is a tool for writing simple HTML-based forms to a StringBuilder or AgentRequest output stream. This class makes it easier to create generic forms without dealing with lots of HTML. |
| HTMLStringTools | This class has a collection of static methods for HTML/HTTP related string manipulation. |
| HTTPAgentRequest | This file is an extension of the AgentRequest class with specialty fields and methods for handling HTTP requests. It prints the HTTP headers to the response stream if the agent responding to the request doesn't print correct HTTP/1.1 response headers before writing other content to the output stream. HTTPAgentRequest also has methods for using cookies and for managing sessions with a SessionManager. HTTPAgentRequest implements the Props interface, and the following props are usually set by the server:
|
| HTTPAuthenticationAgent | This agent is used by the WebServer to handle authorization of password protected resources. The authentication file defines the realms and the usernames and passwords which are used to authenticate clients to the paths associated with each realm. The authentication file is delimited by newlines and must end with a newline. Each realm is declared with a PATH and the REALM name separated by spaces, followed by usernames and passwords on new lines, separated by a space. PATHs must begin with a slash and end with a slash. The HOSTNAME field at the beginning of the file indicates to the HTTPAuthentication agent what hostname the realms should be mapped to. In Virtual Host (multihoming) configurations, use multiple authentication files with different HOSTNAME values for each file. The default hostname is default. Here is an example authentication file:HOSTNAME PATH0 REALM0 username0 password0 username1 password1 username2 password2 username3 password3 PATH1 REALM2 username0 password0 username1 password1 The following example shows an example of an authentication file with two realms, 'My realm' and 'Main Realm'. If any access is made to files or directories in /private/, this agent will ask for the username jonlin with the password mainpassword, except for accesses to /private/mine/, which is under the /private/ path but is its own realm and requires its own usernames and passwords. If default is used as the hostname then the authentication map will apply to all virtual hosts on this server. default /private/mine/ My realm john johnpassword santos halper /private/ Main Realm john mainpasswordThis agent supports the following Props settings:
|
| HTTPCheckKMethod | This KMethod checks if a web server is available by sending it a request for a URL. After the KMethod has been executed, the connection, request, and request latency are recorded in public fields. This method requires a host, port and request as arguments to the constructor. An optional timeout field can be set if needed. |
| HTTPDecoderStream | This extension of Stream allows only a fixed number of bytes to be read from the stream before behaving as if the Stream is empty. The bytes that are read from this stream are automatically decoded using HTTP parameter decoding. |
| HTTPFileServerAgent |
This agent is used by the WebServer and SecureWebServer to handle requests for files from the file system. If the file is an ASP.NET file, it will be executed using the ASP.NET environment on the server and the output will be sent to the requestor. If the ASP.NET code references other assemblies or .dlls, include copies of these .dlls in the same folder as your ASP.NET file. The HTTPFileServerAgent supports the following Props:
For virtual hosts (serving different websites with unique domain names a.k.a. multihoming), start multiple HTTPFileServerAgent instances and give each one unique service_name and html_directory prop values. Include the domain name (or the protocol, http:// or https://) with the URI in the agent's service_name. Here are some examples of valid service_names:
http://www.server.org/
http://www.server.org:8080/
https://www.server.org/
www.server.org/
www.server.org:8080/
/
|
| HTTPProxyAgent |
HTTPProxyAgent handles proxies to other web servers. It can provide complete http proxy services to browsers and other clients connecting on the addresses and ports specified in the listeners property, and it can proxy specific URLs from the http.proxy file while the WebServer handles other requests normally. The http.proxy file lists full URLs or URIs to proxy and where they should be proxied to if the WebServer is running. It consists of name/value pairs separated by newlines. Lines beginning with the # character are ignored as comments. The value of each name/value pair must be a complete URL. Here are some valid name/value pairs that might be used in the http.proxy file: http://myserver/proxy_me=http://proxy:1099 http://myserver/proxy_me2=http://proxy1:9000 http://myserver/proxy_me2=http://proxy2:9000 http://myserver/proxy_me2=http://proxy3:9000When a browser requests /proxy_me, the HTTPProxyAgent contacts the web server at proxy on port 1099 and proxies the request to that server. When a browser requests /proxy_me_too, the HTTPProxyAgent cycles through the 3 web servers indicated, so that the first time the URL is accessed, the connection is proxied to proxy1:9000. The second time, the request is proxied to proxy2:9000, the third request goes to proxy3:9000, the fourth request goes to proxy1:9000, and so on. Both the name and the value of each name/value pair are assumed to be literal, so they will only match the exact path/hostname of the http request. The servers listed in the http.proxy file are periodically checked to ensure that they are up and responding. The HTTPProxyAgent will not proxy requests to hosts from the http.proxy file that aren't responding. HTTPProxyAgent also supports listeners, which operate independently of the WebServer to proxy traffic for browsers configured to use a proxy server. Any number of listeners can be started to provide proxy services on specific ports or IPs. Listeners are specified using the listeners prop of the HTTPProxyAgent. This agent supports the following Props entries:
|
| HTTPPutAgent | This agent can be loaded to support traditional HTTP Put functionality, saving uploaded files to the directory specified in the html_directory prop. To run this agent, the WebServer must have a prop called http_put.agent that matches the HTTPPutAgent's service_name.
|
| HTTPRedirectAgent |
This Request Agent is used by the WebServer to determine whether a web request should be redirected and to actually redirect the request by returning the proper redirect code to the client. If an HTTPRedirectAgent is running and the WebServer's redirect_agent prop is the same as the HTTPRedirectAgent's service_name, the agent will redirect requests for URLs in the http.redirect file. This file lists where to redirect to; URIs with multiple redirects listed in the file will be cycled between the listed redirects, providing a round-robin load distribution scheme. The file format is name/value pairs delimited by newlines; lines starting with '#' are ignored. Complete URLs must be used to specify redirected URLs and the redirect targets. Here is an example of a redirect file: http://myserver/redir1/file.htm=http://yahoo.com/ http://myserver/redir2/=http://redirect1:9000/ http://myserver/redir2/==http://redirect2:9000/ http://myserver/redir2/==http://redirect3:9000/When a browser requests /redir1/file.html, it is redirected to http://yahoo.com. When it requests /redir2, it is redirected to http://redirect1:9000/. The next request for /redir2 is redirected to http://redirect2:9000/. The third incoming request is redirected to http://redirect3:9000/. The fourth request is redirected to http://redirect1:9000/, and the cycle is started again. In this way, the HTTPRedirectAgent can be used for round-robin style load balancing. There are 2 kinds of name/value pairs used in the redirect configuration file. The first is a direct mapping in the format NAME=VALUE. This mapping tells the redirect agent to redirect PATH NAME to PATH VALUE. A directly mapped NAME that contains a hostname must have a host in its VALUE. A direct mapping will not recurse subdirectories in a path and each path is regarded as literal. Directly mapped names can by mapped to multiple values if the values are separated by commas. The agent will cycle through each of the different paths given as the value. The second kind of mapping maps only hosts to hosts, and passes the requested URL along with the redirected request for the mapped host to handle. This is an example of host-to-host mapping syntax: http://myhost.com>http://www.myhost.comNo path information is included in the syntax of this mapping, only the host names. Any path intended for myhost.com will be mapped to the host www.myhost.com. Note: Cyclical references in the redirect mappings are not checked, if the redirect file has cyclical references, clients can be put into an infinite loop of redirects.
|
| HTTPRequest | This class is used as a data object which stores the HTTP/1.0 request. It will provide the HTTP/1.0 request in String form. |
| HTTPResponse | This class is a data object which stores a HTTP/1.1 response. |
| KTcpClient | This class extends TcpClient to provide access to the underlying socket and IP Address of the remote machine. |
| SecureWebServer | SecureWebServer extends WebServer with SSL security features. You must provide a certificate suitable for server authentication, and any passwords or key files needed to access the certificate. SSL3 and TLS3 are the only supported protocols. This agent supports the following Props entries:
|
| WebServer |
The Neokernel web server services http requests. If an incoming request is for a static file like an HTML file, the web server delivers it. If the request URI ends in .agent, the web server uses a custom C# or Visual Basic object to generate the response. Objects that generate responses in this way implement the RequestAgent interface. If the server can't find a file or a RequestAgent to match the client's request, a 404 (file not found) error is returned. Typically, an HTTPFileServerAgent is used to serve static files like images or HTML. The HTTPFileServerAgent also handles ASP.NET pages if the file ends with the .aspx extension. Custom RequestAgents are commonly used in conjunction with the WebServer and SecureWebServer classes to handle HTTP requests dynamically. Here's an example of a simple RequestAgent written in Visual Basic: Imports com.neokernel.nk
Imports com.neokernel.util
Public Class SimpleVBPage
Inherits RequestAgent
Overrides Sub handleRequest(ByVal Request As AgentRequest)
Dim title, body As String
body = getString("body")
Request.println(body)
End Sub
Overrides Sub initProps()
setDefault("service_name", "/simple.agent")
setDefault("body", "This is output from the SimplePage agent!")
End Sub
End Class
If a browser requests http://localhost/simple.agent from a server that has started the above SimpleAgent, the browser will display the text This is output from the SimplePage agent! Here is the exact same agent written using C#: using System;
using com.neokernel.nk;
public class SimplePage : RequestAgent
{
public override void initProps()
{
setDefault("service_name", "/simple.agent");
setDefault("body", "This is output from the SimplePage agent!");
}
public override void handleRequest(HTTPAgentRequest request)
{
String body = getString("body");
request.println( body );
}
}
WebServer supports the following Props entries:
|
| XHTMLFormWriter | XHTMLFormWriter is a tool for writing simple XHTML-based forms to a StringBuilder or AgentRequest output stream without worrying about the XHTML code. |
| Interface | Description |
|---|---|
| HTMLResponseInterface | This interface defines an Object that can return the full HTTP response header and body (as HTML), based off of the constants in com.neokernel.httpd.WebServer |