summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorclsr <clsr@clsr.net>2017-09-04 13:11:45 +0200
committerclsr <clsr@clsr.net>2017-09-04 13:11:45 +0200
commita4da42c85b789fa9bdb1822b598abe814b0301cd (patch)
tree50bf49d79caf05f945d8c191007daf302abbca4e
parentb4df108cc17524a7710bdbc3425af33a527a0f32 (diff)
downloadcnp0.4.tar.gz
cnp0.4.zip
Reformat text, add the select parametercnp0.4
This commit represents the CNP 0.4 specification.
-rw-r--r--cnp-specification.cnm134
1 files changed, 107 insertions, 27 deletions
diff --git a/cnp-specification.cnm b/cnp-specification.cnm
index 67c4368..066c277 100644
--- a/cnp-specification.cnm
+++ b/cnp-specification.cnm
@@ -1,5 +1,5 @@
title
- ContNet Protocol specification, version 0.3 (2017-08-18)
+ ContNet Protocol specification, version 0.4 (2017-09-04)
content
section Overview
@@ -22,7 +22,7 @@ content
The header field delimiter is a single space byte (``0x20``). Multiple successive spaces in the header are a syntax error. A space cannot appear as itself in any header value; it must be escaped into a specific byte sequence. This makes splitting a valid header by spaces safe and correct.
- The CNP version part of the header is the string ``"cnp/"`` followed by a tuple of the major and minor version numbers without leading zeroes on non-zero versions, separated by a period (e.g. ``"cnp/0.3"``). Even if the specification and implementation use a patch version, it is not provided in the message header and must have no impact on protocol compatibility. CNP implementations within the same major version should be generally compatible with other minor versions for basic requests, excluding some noncritical feature discrepancy; unknown parameters are ignored. An exception to this are all versions in the major version ``0``; since it's the development version, the protocol may be completely rewritten between two minor versions.
+ The CNP version part of the header is the string ``cnp/`` followed by a tuple of the major and minor version numbers without leading zeroes on non-zero versions, separated by a period (e.g. ``cnp/0.4``). Even if the specification and implementation use a patch version, it is not provided in the message header and must have no impact on protocol compatibility. CNP implementations within the same major version should be generally compatible with other minor versions for basic requests, excluding some noncritical feature discrepancy; unknown parameters are ignored. An exception to this are all versions in the major version ``0``; since it's the development version, the protocol may be completely rewritten between two minor versions.
The intent is a string that defines the type of the message. Valid values depend on whether the message is request or response.
@@ -32,6 +32,8 @@ content
The message body is a blob of arbitrary binary data. There is no body delimiter or terminator; if the body ends with a newline, it is considered a part of the body data.
+ Example: ``cnp/0.4 msg_intent param1=value1 param2=value2``
+
section Escaping
text fmt
@@ -78,7 +80,7 @@ content
The hostname may be a domain name or an IP address, optionally with a port number, and it may not contain any slash (``0x2f``) bytes. In general, it should be the address that the client sends the request to. The format of the hostname is the same as in URLs.
- The path is a Unix-style absolute filepath with an optional trailing slash. It may (and probably should) be cleaned up by CNP implementations before being processed by collapsing multiple consecutive slashes into single ones, removing path entries that consist of a single dot and resolving double-dot parent directories, while leaving a trailing slash if one was present (for example, the path ``"/../../.\/\/\/foo/bar/.."`` becomes ``"/foo"`` and ``"\/\/foo/bar/../"`` becomes ``"/foo/"``). If possible, implementations should avoid sending filepaths that need to be cleaned. The minimal path is ``"/"``; blank path is an error.
+ The path is a Unix-style absolute filepath with an optional trailing slash. It may (and probably should) be cleaned up by CNP implementations before being processed by collapsing multiple consecutive slashes into single ones, removing path entries that consist of a single dot and resolving double-dot parent directories, while leaving a trailing slash if one was present (for example, the path ``/../../.\/\/\/foo/bar/..`` becomes ``/foo`` and ``\/\/foo/bar/../`` becomes ``/foo/``). If possible, implementations should avoid sending filepaths that need to be cleaned. The minimal path is ``/``; blank path is an error.
The hostname is case-insensitive, while the path is case-sensitive. Hostname may be normalized by clients and servers, but a specific path (after cleanup) represents one specific resource.
@@ -97,9 +99,9 @@ content
text fmt
The length of the request body data in bytes.
- This field is required if any data will be sent to the server.
+ This field is required if any data will be sent to the server. If it's absent or zero, the request must not contain any body data. Otherwise, the byte size of the request body data must be provided in this parameter.
- Default value: ``"0"`` (empty body)
+ Default value: ``0`` (empty body)
section name
@@ -111,7 +113,7 @@ content
Can be used to provide filename metadata. If the original filename was a Unicode filename instead of a bytestring, UTF-8 should be used to encode it.
- Default value: ``""`` (no name provided)
+ Default value: empty (no name provided)
section type
@@ -121,7 +123,7 @@ content
text fmt
MIME type of the content being sent in the request body.
- Default value: ``"application/octet-stream"``
+ Default value: ``application/octet-stream``
section if_modified
@@ -129,13 +131,67 @@ content
if_modified={timestamp}
text fmt
- Only send the resource in the response if it has been modified since the RFC 3339 UTC timestamp provided, according to the server's time. Otherwise, reply with a ``"not_modified"`` response and no body data.
+ Only send the resource in the response if it has been modified since the RFC 3339 UTC timestamp provided, according to the server's time. Otherwise, reply with a ``not_modified`` response and no body data.
The RFC 3339 timestamp format should be the following, as a strftime format string format: ``%Y-%m-%dT%H:%M:%SZ``, for example: ``1970-12-31T23:59:30Z``.
- The timestamp should usually be either the server's ``"modified"`` parameter value from the time the cached resource was requested or the ``"time"`` parameter value from that request if the former was not provided. If neither was present in the previous response for the current request's intent, the client should not use an ``if_modified`` parameter.
+ The timestamp should usually be either the server's ``modified`` parameter value from the time the cached resource was requested or the ``time`` parameter value from that request if the former was not provided. If neither was present in the previous response for the current request's intent, the client should not use an ``if_modified`` parameter.
+
+ An ``if_modified`` parameter may only be set on a request for a cached page when all of the host, path and selector are equivalent to the previously cached copy.
+
+ Default value: empty (do not perform this check, just send the resource)
+
+
+ section select
+ raw
+ select={identifier}:{identifier}
+ select={identifier}:
+
+ text fmt
+ Request the server to apply a filter on the contents of the requested path before sending it.
+
+ The parameter value consists of a selector name (that may not contain a colon), a colon byte (``0x3A``) and an optional selector query. The functionality of the selector depends on which selector is requested.
+
+ The following selectors are defined in this specification:
+
+ section byte
+ raw
+ select=byte:{number}-{number}
+ select=byte:{number}-
+ select=byte:-{number}
+ select=byte:-
+
+ text fmt
+ The ``byte`` selector selects a subset of the content bytes. The ``{from}`` value represents the index of the first included byte; it defaults to ``0``, the first byte in the contents, when absent. The ``{to}`` represents the index of the last included byte; it defaults to the last byte in the contents when absent. An end byte lesser than the start byte is invalid in a request. If the start byte index is greater than the content length, the response contents should be empty (``length=0``).
+
+ If possible, implementations should support this selector.
+
+ section info
+ raw
+ select=info:
+
+ text fmt
+ The ``info`` selector selects the response header of a request to this path. It takes no query string; if one is provided, the selector is invalid.
+
+ The response body (**not** header) should contain the CNP header line that would have been used to answer this request if it didn't contain the ``info`` selector. It should contain all parameters that an actual response header would, especially a potential ``length`` parameter.
+
+ If possible, implementations should support this selector.
- Default value: ``""`` (do not perform this check, just send the resource)
+ section cnm
+ raw
+ select=cnm:{identifier}
+
+ text fmt
+ The ``cnm`` selector selects content based on CNM content selector. See the CNM specification for more information.
+
+ text fmt
+ Implementations may choose to support custom selectors. More selectors may be defined in the future.
+
+ If an unknown selector is requested, it should be ignored and the request responded to as if there was no selector.
+
+ If a known selector is requested for an unsupported path, the response should be an ``error`` with ``reason=not_supported``.
+
+ If the selector query was invalid, the response should be an ``error`` with ``reason=invalid``.
section Response
@@ -155,12 +211,12 @@ content
section not_modified
text fmt
- The resource has not been modified since the time in the request's ``"if_modified"`` parameter. The response body is blank and the client should use the cached resource.
+ The resource has not been modified since the time in the request's ``if_modified`` parameter. The response body is blank and the client should use the cached resource.
section redirect
text fmt
- The client should make a new request to the location provided in the ``"location"`` parameter. The response body may contain a page as if it was an ``"ok"`` response.
+ The client should make a new request to the location provided in the ``location`` parameter. The response body may contain a page as if it was an ``ok`` response.
The new request should be blank (contain no body data, as if that path was just entered anew by the user).
@@ -171,7 +227,7 @@ content
section error
text fmt
- There was an error answering the request. The server must also provide the ``"reason"`` response parameter. The body data may contain a page as if it was an ``"ok"`` response.
+ There was an error answering the request. The server must also provide the ``reason`` response parameter. The body data may contain a page as if it was an ``ok`` response.
User agents do not have to display the provided page and may just inform the user of the error reason. If a page is provided, it should be used to inform the user of the details of the error.
@@ -188,11 +244,15 @@ content
text fmt
The length of the response body data in bytes.
- If this parameter is not provided or is blank, the client should read all data until the connection is closed, end of file is reached or equivalent. Despite that, the length parameter should be sent whenever possible.
+ If present, it must contain the length of the response body in bytes. The client should use that to delimit reading the response.
+
+ If this parameter is not provided or is blank, the client should read all data until the connection is closed, end of file is reached or equivalent. Despite that, the length parameter should be sent whenever possible. If the transport does not support an equivalent to an end-of-message signal, then the ``length`` parameter is required for responses.
+
+ A zero response ``length``, which is not the default, means that the response has no body data.
Valid in all response types.
- Default value: ``""`` (read until EOF)
+ Default value: empty (read until EOF)
section name
@@ -206,7 +266,7 @@ content
Valid in response types where the body data can be file (``ok``, ``redirect``, ``error``).
- Default value: ``""`` (no name provided)
+ Default value: empty (no name provided)
section type
@@ -218,7 +278,7 @@ content
Valid in response types where the body data can be file (``ok``, ``redirect``, ``error``).
- Default value: ``"application/octet-stream"``
+ Default value: ``application/octet-stream``
section time
@@ -228,9 +288,9 @@ content
text fmt
The current time on the server as an RFC 3339 UTC timestamp.
- May be sent with any response type, but most useful in the ``"ok"`` response, where it may be used by the client in an ``"if_modified"`` request parameter later.
+ May be sent with any response type, but most useful in the ``ok`` response, where it may be used by the client in an ``if_modified`` request parameter later.
- Default value: ``""`` (no timestamp provided)
+ Default value: empty (no timestamp provided)
section modified
@@ -240,9 +300,9 @@ content
text fmt
RFC 3339 UTC timestamp representing the time the requested file was last modified.
- Valid in ``"ok"`` and ``"not_modified"`` responses, where it may be used by the client in an ``"if_modified"`` request parameter later.
+ Valid in ``ok`` and ``not_modified`` responses, where it may be used by the client in an ``if_modified`` request parameter later.
- Default value: ``""`` (no timestamp provided)
+ Default value: empty (no timestamp provided)
section location
@@ -252,13 +312,13 @@ content
text fmt
The location to redirect to in the format of a CNP request intent.
- If the host part of the intent in the value is empty, the current host should be reused. If the host is ``"."``, the current host should be reused and the path should be appended to the current path, excluding the last filename after the final slash in the current path (if any). Otherwise, the new request should be sent to the provided host, which has to be resolved to a server address (instead of just sending a request with the new host to the current server).
+ If the host part of the intent in the value is empty, the current host should be reused. If the host is ``.``, the current host should be reused and the path should be appended to the current path, excluding the last filename after the final slash in the current path (if any). Otherwise, the new request should be sent to the provided host, which has to be resolved to a server address (instead of just sending a request with the new host to the current server).
- For example, if the request was sent to ``"example.com/foo/bar"`` and the redirect location was ``"/baz"``, the new request's intent is ``"example.com/baz"``, but if the location parameter was ``"./baz"``, the new intent is ``"example.com/foo/baz"``.
+ For example, if the request was sent to ``example.com/foo/bar`` and the redirect location was ``/baz``, the new request's intent is ``example.com/baz``, but if the location parameter was ``./baz``, the new intent is ``example.com/foo/baz``.
- Valid in ``"redirect"`` response type.
+ Valid in ``redirect`` response type.
- Default value: ``""`` (not providing this parameter in a redirect response is an error, no redirect happens)
+ Default value: empty (not providing this parameter in a redirect response is an error, no redirect happens)
section reason
@@ -299,6 +359,26 @@ content
``server_error``: internal server error
text fmt
- Valid in ``"error"`` response type.
+ Valid in ``error`` response type.
+
+ Default value: ``server_error`` (servers should provide this parameter in the ``reason`` response if possible)
+
+
+ section select
+ raw
+ select={identifier}:{identifier}
+ select={identifier}:
+
+ text fmt
+ May be present only on responses to requests containing ``select`` parameters. If a selector was used, this parameter must be present and contain a selector that was executed on the contents. This may be the same selector that was provided in the request or one equivalent to it (e.g. a ``byte`` selector with a missing last index replaced with the index of the last byte in the contents).
+
+
+ section CNP on Internet
+ text fmt
+ The default transport for CNP 0.4 is a plain TCP connection with the server listening on port ``25454`` by default (though an alternative port may be provided in the URL or request intent).
+
+ The default file type for pages requested over CNP should usually be CNM documents with ``type=text/cnm``. However, any file types may be transferred over CNP.
+
+ Clients should write exactly as much data as specified by their request ``length`` parameter; excess data may result in an ``error`` response or a blocking write, while insufficient data will likely result in the server waiting for more input instead of responding. Servers using ``length`` parameters in responses should send exactly as much data as they specified, since clients might otherwise wait for more response data or read too much data when ignoring the ``length`` and reading until the end of connection instead.
- Default value: ``"server_error"`` (servers should provide this parameter in the ``"reason"`` response if possible)
+ Note that this may change in the future versions. Likely changes are the requirement of TLS for connections and a different default port.