Skip to main content

Validate HTTP messages in xml2rfc and kramdown-rfc documents

Project description

rfc-http-validate

This is a simple script to validate HTTP messages (possibly containing Structured Fields) in xml2rfcv3 documents and kramdown-rfc documents.

It checks that the content of an HTTP message:

  • Optionally, starts with a valid HTTP/1.1 request or status line
  • Has one or more HTTP/1.1 header field lines, possibly with line folding (so that long lines can be formatted within the constraints of the RFC format)
  • Optionally, has a response body, separated from the header fields with a single empty line

The start line will be checked that the method or status code is reasonable, and that the version identifier HTTP/1.1 is correct. The URL in requests will not be validated, however.

Header fields will be validated for general syntax. Additionally, header field names that are configured with structured type information (see below) will be validated according to that type.

The body, if present, is currently ignored (i.e., the Content-Length is not checked).

If an RFC8792 \\ wrapping header is present, lines will be unwrapped first (i.e., before unfolding, as per above). This is useful for long lines with binary content (which cannot contain whitespace); e.g.,

<sourcecode type="http-message">
# NOTE: '\' line wrapping per RFC 8792

Signature: sig1=:K2qGT5srn2OGbOIDzQ6kYT+ruaycnDAAUpKv+ePFfD0RAxn/1BUe\
    Zx/Kdrq32DrfakQ6bPsvB9aqZqognNT6be4olHROIkeV879RrsrObury8L9SCEibe\
    oHyqU/yCjphSmEdd7WD+zrchK57quskKwRefy2iEC5S2uAH0EPyOZKWlvbKmKu5q4\
    CaB8X/I5/+HLZLGvDiezqi6/7p2Gngf5hwZ0lSdy39vyNMaaAT0tKo6nuVw0S1MVg\
    1Q7MpWYZs0soHjttq0uLIA3DIbQfLiIvK6/l0BdWTU7+2uQj7lBkQAsFZHoA96ZZg\
    FquQrXRlmYOh+Hx5D9fJkXcXe5tmAg==:
</sourcecode>

Installation

pipx is recommended:

pipx install rfc-http-validate

Validating HTTP Messages in Markdown

In Markdown, all you need to do is adorn your messages with http-messsage; for example:

~~~ http-message
HTTP/1.1 200 OK
Foo: bar, baz
~~~

Then, run:

rfc-http-validate my-draft.md

Validating HTTP Messages in RFC XML

In XML, this script examines all sourcecode and artwork elements; when one has a type of http-message.

For example,

<sourcecode type="http-message">
Foo: bar; baz
Foo: one,
     two
</sourcecode>

Then, run:

rfc-http-validate my-draft.xml

Note that in your XML, there must not be any whitespace at the start of lines, unless they're continuation of previous lines (folding, as seen above).

Configuring Structured Type Information for Fields

By default, the types of existing Structured Fields (including those that are compatible with Structured Fields; see Retrofit Structured Fields for HTTP) are known. Type information for other fields can be added on the command line or through a file.

To pass a type on the command line, use the --list, --dictionary or --item arguments as appropriate, followed by the field name. For example:

rfc-http-validate --list Foo --list Bar --item Baz my_draft.xml

Here, Foo and Bar will be validated as Structured Lists, while Baz will be validated as a Structured Item.

Alternatively, you can collect this information in a JSON file, with the top-level object keys being field names, and their values being list, dict or item as appropriate. Thus, the configuration in the example above could be expressed in a JSON file sf.json as:

{
  "Foo": "list",
  "Bar": "list",
  "Baz": "item"
}

... and passed to the script like this:

rfc-http-validate --map sf.json my_draft.xml

Use with I-D-Template

To automatically lint files with MT's I-D-Template:

  1. Add rfc-http-validate to requirements.txt (creating it if necessary)
  2. Add a sf.json file containing the field(s) your draft uses mapped to one of item, list, or dict
  3. Add the following to Makefile:
lint:: http-lint

rfc-http-validate ?= rfc-http-validate
.SECONDARY: $(drafts_xml)
.PHONY: http-lint
http-lint: $(addsuffix .http-lint.txt,$(addprefix .,$(drafts)))
.PHONY: .%.http-lint.txt
.%.http-lint.txt: %.xml $(DEPS_FILES)
	$(trace) $< -s http-lint $(rfc-http-validate) -q -m sf.json $<
	@touch $@

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rfc_http_validate-0.3.6.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rfc_http_validate-0.3.6-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file rfc_http_validate-0.3.6.tar.gz.

File metadata

  • Download URL: rfc_http_validate-0.3.6.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rfc_http_validate-0.3.6.tar.gz
Algorithm Hash digest
SHA256 51b8b874b50a432f26d23954792bae3b2388128c6f3607ae29c867a9c64bae6b
MD5 3aa81ba2e9e26e96535b169e40151d26
BLAKE2b-256 b29c0faee8d1d6ed5dead57e3ac6a625cfd9426733738447578aba3f457234d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for rfc_http_validate-0.3.6.tar.gz:

Publisher: publish.yml on mnot/rfc-http-validate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rfc_http_validate-0.3.6-py3-none-any.whl.

File metadata

File hashes

Hashes for rfc_http_validate-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c7028991f21deab9bdd91ec0912a04f056d6c2044fe947b34170f0dc8d2d3011
MD5 3ec4da9b7f41679a333949a14ad10436
BLAKE2b-256 fda60d23e71d419c1a509a576d2adb56d29f4eeaa10e7b26f9f03d1f11be4538

See more details on using hashes here.

Provenance

The following attestation bundles were made for rfc_http_validate-0.3.6-py3-none-any.whl:

Publisher: publish.yml on mnot/rfc-http-validate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page