JSON configuration file with MIME type settings and HTTP headers

This example shows a $OMNIHOME/etc/libnhttpd/json configuration file, which is edited to define MIME type settings and HTTP headers in HTTP responses that are returned by the HTTP interface and OSLC interface. To enable MIME type settings and HTTP headers, enable the NHttpd.ConfigFile property.

The sections that enable MIME type settings and HTTP headers are as follows:

httpResponse
Defines the HTTP headers that are in the HTTP responses that are returned by the HTTP interface and OLSC interface. It has the following subsections:
corsHeaders
Overrides Cross-Origin Resource Sharing (CORS) HTTP headers. By default, the default headers are overridden to indicate that the Location HTTP header are be allowed and exposed. This setting is required for HTTP 201 Create responses messages.
httpHeaders
For user-defined HTTP headers. These headers are added to all HTTP responses. Use this section to add static values for clients. A sample header is provided in the example.
mimeTypes
This section assigns a file extension, for example .html, to a MIME type. When file-serving is enabled, these definitions are used to determine the MIME type for the file. They also set the Content-Type HTTP header so that browsers can handle the file correctly. The $OMNIHOME/etc/libnhttpd/json file has a default set of MIME type settings that you can add to.

Example

{
	"_comment" : "This file provides additional configuration data to the embedded HTTP socket library (libnhttpd).",
	"httpResponse" : {
		"_comment" : "This section defines a set of user defined static elements that should be returned in an HTTP response, such as HTTP headers.",
		"corsHeaders" : [
			{
				"name"  : "Access-Control-Allow-Headers",
				"value" : "Location"
			},
			{
				"name"  : "Access-Control-Expose-Headers",
				"value" : "Location"
			}
		],
		"httpHeaders" : [
		]
	},
	"mimeTypes" : {
		"_comment" : "This section maps MIME types to file extensions. It is used by libnhttpd to determine the MIME type for a file that is to be served from its file serving URI.",
		"application/json" : [
			"json"
		],
		"application/rdf+xml" : [
			"rdf"
		],
		"application/xslt+xml" : [
			"xsl", "xslt"
		],
		"image/jpeg" : [
			"jpg", "jpeg"
		],
		"image/gif" : [
			"gif"
		],
		"image/png" : [
			"png"
		],
		"text/css" : [
			"css"
		],
		"text/javascript" : [
			"js"
		],
		"text/HTML" : [
			"htm", "html"
		],
		"text/plain" : [
			"txt", "log"
		],
		"text/xml" : [
			"xml"
		]
	}
}