cn-http is a CNP-to-HTTP translating gateway that can also act as a ContNet browser.
It listens on HTTP, translating incoming requests into CNP and forwarding them to the specified CNP server. The response is then converted into HTTP and, if it contained a text/cnm
document, the document is converted into HTML.
It supports all current CNP 0.3 features except requests with data. modified
cache parameters are fully functional and translate to the corresponding If-Modified
HTTP headers. It supports CNP 0.4 cnm:
selectors with the ?select=
GET parameter, but lacks proper support for using them. CNM section selectors are supported as page anchors.
Installation¶
cn-http requires Go 1.8 or later.
Install it with:
go install contnet.org/util/cn-http@latest
Or directly run it with:
git clone https://git.clsr.net/contnet/cn-http
cd cn-http
go run cnhttp.go [OPTIONS]
Usage¶
To use it as a gateway, run it with cn-http -listen HOST:PORT -cnp-host UPSTREAM
.
The -listen
parameter defaults to localhost:8080
. If the -cnp-host
parameter is not specified, cn-http runs in browser mode, where it prepends the hostname to every path and provides a URL input box on top of the page, which allows requesting CNP pages from arbitrary hosts.
The cn-http
binary needs to be run in the folder containing the templates
and static
folders found in its source code repository.
By default, cn-http serves requests under the path /static/
from the local ./static/
folder. This can be disabled with the flag -no-static
, in which case any static files should be provided via the CNP upstream server (this will also break browser mode and shouldn't be used there).
For raw
block syntax highlighting to work, the highlight.js JavaScript library needs to be available. The default paths (specified in templates/page.html
) are /static/highlight/highlight.pack.js
for the script and /static/highlight/style.css
for the stylesheet. If JavaScript-based syntax highlighting is undesirable, the -no-highlight
command-line flag can be used.
Gateway example: cd src/cn-http && cn-http -listen 0.0.0.0:80
Browser example: cd src/cn-http && cn-http
, then open http://localhost:8080 in a web browser
A sample systemd service unit file is also provided with the source code.
Source¶
The cn-http source code is available on https://git.clsr.net/contnet/cn-http