Neokernel API

WebServer Class

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:

socket_linger_time
The number of millisecs to wait after an http request is completed before closing the socket used for that request. Default value is 2000
bind_port
The port that the webserver will bind to. Default value is 80
max_connections
The maximum number of concurrent connections to allow. Default value is 20
index_agent
The agent that gets called when the default page is requested. Default value is HTTPFileServerAgent
bind_ip
The IP address to service HTTP requests on (on mulithoming machines.) To service requests on any IP interfaces, use 0.0.0.0 as the value. Default value is 0.0.0.0
log_requests
If this is set to true, the server will create HTTP access logs. Default value is true
log_file_dir
Specifies the directory where the server will create the HTTP access logs. Default value is ./logs
mime_types_file
The path to a file specifying mime types to use with various file extensions. If this file is missing, the server uses common default mappings. Default value is ./mime_types
max_uri_length
The maximum length (in bytes) of URIs that the server will accept before a request is ignored. The default value is 4096
max_multipart_length
The maximum size of a POST request that the server will accept (in bytes) before the request is ignored. Default value is 4194304 (4MB)
refuse_requests
This prop specifies a list of strings that will result in a request being refused if a client passes them in the request URI. By default this prop is not set.
multihome
If this prop is set to false, multihome functionality is disabled. By default this prop is set to
true
redirect_agent
If this prop is set to true, the server will use the HTTPRedirectAgent to redirect incoming requests. This prop is not set to a default value.
proxy_agent
If this prop is set to true, the server will use the HTTPProxyAgent to proxy incoming requests. This prop is not set to a default value.
authentication_agent
If this prop is set to true, the server will use the HTTPAuthenticationAgent to demand passwords for certain URLs specified in the http.authentication file. This prop is not set to a default value.

For a list of all members of this type, see WebServer Members .

System.Object
   Props
      Agent
         WebServer
            SecureWebServer

public class WebServer : Agent, IThreadRunnable

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Requirements

Namespace: com.neokernel.httpd

Assembly: Neokernel (in Neokernel.exe)

See Also

WebServer Members | com.neokernel.httpd Namespace