Skip to main content

http-utils

deno land GitHub release (latest by date) codecov GitHub

test NPM

HTTP utility collection.

Compliant with RFC 9110.

Utilities for HTTP header field.

isMessageMetadataHeader

Whether the input is MessageMetadataHeader or not.

import { isMessageMetadataHeader } from "https://deno.land/x/http_utils@$VERSION/header.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isMessageMetadataHeader("date"));
assert(!isMessageMetadataHeader("<others>"));

isMessageForwardingHeader

Whether the input is MessageForwardingHeader or not.

import { isMessageForwardingHeader } from "https://deno.land/x/http_utils@$VERSION/header.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isMessageForwardingHeader("connection"));
assert(!isMessageForwardingHeader("<others>"));

isRepresentationHeader

Whether the input is RepresentationHeader or not.

import { isRepresentationHeader } from "https://deno.land/x/http_utils@$VERSION/header.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isRepresentationHeader("content-type"));
assert(!isRepresentationHeader("<others>"));

isAuthenticationHeader

Whether the input is AuthenticationHeader or not.

import { isAuthenticationHeader } from "https://deno.land/x/http_utils@$VERSION/header.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isAuthenticationHeader("authorization"));
assert(!isAuthenticationHeader("<others>"));

isContentNegotiationHeader

Whether the input is ContentNegotiationHeader or not.

import { isContentNegotiationHeader } from "https://deno.land/x/http_utils@$VERSION/header.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isContentNegotiationHeader("accept"));
assert(!isContentNegotiationHeader("<others>"));

isConditionalHeader

Whether the input is ConditionalHeader or not.

import { isConditionalHeader } from "https://deno.land/x/http_utils@$VERSION/header.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isConditionalHeader("if-match"));
assert(!isConditionalHeader("<others>"));

isRangeHeader

Whether the input is RangeHeader or not.

import { isRangeHeader } from "https://deno.land/x/http_utils@$VERSION/header.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isRangeHeader("range"));
assert(!isRangeHeader("<others>"));

isCachingHeader

Whether the input is CachingHeader or not.

import { isCachingHeader } from "https://deno.land/x/http_utils@$VERSION/header.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isCachingHeader("age"));
assert(!isCachingHeader("<others>"));

MessageMetadataHeader

HTTP Message Metadata header fields.

Compliant with RFC 9110, 6.6. Message Metadata.

  • Date
  • Trailer
import { MessageMetadataHeader } from "https://deno.land/x/http_utils@$VERSION/header.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(MessageMetadataHeader.Date, "date");

MessageForwardingHeader

HTTP Message Forwarding header fields.

Compliant with RFC 9110, 7.6. Message Forwarding.

  • Connection
  • Max-Forwards
  • Via
import { MessageForwardingHeader } from "https://deno.land/x/http_utils@$VERSION/header.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(MessageForwardingHeader.Via, "via");

RepresentationHeader

HTTP representation data and metadata header fields.

Compliant with RFC 9110, 8. Representations.

  • Content-Type
  • Content-Encoding
  • Content-Language
  • Content-Length
  • Content-Location
  • Last-Modified
  • ETag
import { RepresentationHeader } from "https://deno.land/x/http_utils@$VERSION/header.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(RepresentationHeader.ContentType, "content-type");

AuthenticationHeader

HTTP Authentication header fields.

Compliant with RFC 9110, 11. HTTP Authentication.

  • WWW-Authenticate
  • Authorization
  • Authentication-Info
  • Proxy-Authenticate
  • Proxy-Authorization
  • Proxy-Authentication-Info
import { AuthenticationHeader } from "https://deno.land/x/http_utils@$VERSION/header.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(AuthenticationHeader.Authorization, "authorization");

ContentNegotiationHeader

HTTP content negotiation header fields.

Compliant with RFC 9110, 12. Content Negotiation.

  • Accept
  • Accept-Charset
  • Accept-Encoding
  • Accept-Language
  • Vary
import { ContentNegotiationHeader } from "https://deno.land/x/http_utils@$VERSION/header.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(ContentNegotiationHeader.Accept, "accept");

ConditionalHeader

HTTP conditional requests header fields.

Compliant with RFC 9110, 13. Conditional Requests.

  • If-Match
  • If-None-Match
  • If-Modified-Since
  • If-Unmodified-Since
  • If-Range
import { ConditionalHeader } from "https://deno.land/x/http_utils@$VERSION/header.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(ConditionalHeader.IfNoneMatch, "if-none-match");

RangeHeader

HTTP range requests header fields.

Compliant with RFC 9110, 14. Range Requests.

  • Range
  • Accept-Ranges
  • Content-Range
import { RangeHeader } from "https://deno.land/x/http_utils@$VERSION/header.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(RangeHeader.Range, "range");

CachingHeader

HTTP Caching header fields.

Compliant with RFC 9111, HTTP Caching.

  • Age
  • Cache-Control
  • Expires
import { CachingHeader } from "https://deno.land/x/http_utils@$VERSION/header.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(CachingHeader.CacheControl, "cache-control");

Method

Utilities for HTTP method.

isSafeMethod

Whether the method is safe method or not.

Defined in RFC 9110, 9.2.1. Safe Methods.

import { isSafeMethod } from "https://deno.land/x/http_utils@$VERSION/method.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isSafeMethod("GET"));
assert(isSafeMethod("HEAD"));
assert(isSafeMethod("OPTIONS"));
assert(isSafeMethod("TRACE"));

isIdempotentMethod

Whether the method is idempotent method or not.

Defined in RFC 9110, 9.2.2 Idempotent Methods.

import { isIdempotentMethod } from "https://deno.land/x/http_utils@$VERSION/method.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isIdempotentMethod("GET"));
assert(isIdempotentMethod("PUT"));
assert(isIdempotentMethod("DELETE"));

isRetrieveMethod

Whether the method is retrieve method or not.

Retrieve method is following:

  • GET
  • HEAD
import { isRetrieveMethod } from "https://deno.land/x/http_utils@$VERSION/method.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isRetrieveMethod("GET"));
assert(isRetrieveMethod("HEAD"));
assert(!isRetrieveMethod("POST"));

Lists

Compliant with RFC 9110, 5.6.1. Lists.

parseListFields

Parse list-based fields into array.

Strings enclosed in double quotes are safely handled.

import { parseListFields } from "https://deno.land/x/http_utils@$VERSION/list.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(parseListFields("foo , ,bar,charlie"), [
  "foo",
  "bar",
  "charlie",
]);
assertEquals(parseListFields(`"Sat, 04 May 1996", "Wed, 14 Sep 2005"`), [
  `"Sat, 04 May 1996"`,
  `"Wed, 14 Sep 2005"`,
]);

Tokens

Compliant with RFC 9110, 5.6.2. Tokens.

isTchar

Whether the input is tchar or not.

import { isTchar } from "https://deno.land/x/http_utils@$VERSION/token.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";

assert(isTchar("!"));
assert(isTchar("a"));
assert(isTchar("Z"));
assertFalse(isTchar(""));

isToken

Whether the input is token or not.

import { isToken } from "https://deno.land/x/http_utils@$VERSION/token.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";

assert(isToken("token"));
assert(isToken("*!~"));
assertFalse(isToken(""));

Quoted Strings

Compliant with RFC 9110, 5.6.4. Quoted Strings.

isQdtext

Whether the input is qdtext or not.

import { isQdtext } from "https://deno.land/x/http_utils@$VERSION/quoted_string.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";

assert(isQdtext("\t"));
assert(isQdtext("\xFF"));
assertFalse(isQdtext(`"`));

isQuotedPair

Whether the input is quoted-pair or not.

import { isQuotedPair } from "https://deno.land/x/http_utils@$VERSION/quoted_string.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";

assert(isQuotedPair("\\\t"));
assert(isQuotedPair("\\\xFF"));
assertFalse(isQuotedPair("\\"));

isQuotedString

Whether the input is quoted-string or not.

import { isQuotedString } from "https://deno.land/x/http_utils@$VERSION/quoted_string.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";

assert(isQuotedString(`""`));
assert(isQuotedString(`"qdtext"`));
assert(isQuotedString(`"quoted-pair"`));
assertFalse(isQuotedString(""));

HTTP Status code

Compliant with RFC 9110, 15. Status Codes

InformationalStatus

An HTTP status that is a informational (1XX).

Compliant with RFC 9110, 15.2. Informational 1xx

SuccessfulStatus

An HTTP status that is a success (2XX).

Compliant with RFC 9110, 15.3. Successful 2xx

RedirectionStatus

An HTTP status that is a redirect (3XX).

Compliant with RFC 9110, 15.4. Redirection 3xx

ClientErrorStatus

An HTTP status that is a client error (4XX).

Compliant with RFC 9110, 15.5. Client Error 4xx

ServerErrorStatus

An HTTP status that is a server error (5XX).

Compliant with RFC 9110, 15.6. Server Error 5xx

ErrorStatus

An HTTP status that is an error (4XX and 5XX).

Status

Standard HTTP status codes.

isInformationalStatus

Whether the input is InformationalStatus or not.

import { isInformationalStatus } from "https://deno.land/x/http_utils@$VERSION/status.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isInformationalStatus(100));
assert(isInformationalStatus(101));

isSuccessfulStatus

Whether the input is SuccessfulStatus or not.

import { isSuccessfulStatus } from "https://deno.land/x/http_utils@$VERSION/status.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isSuccessfulStatus(200));
assert(isSuccessfulStatus(201));

isRedirectionStatus

Whether the input is RedirectionStatus or not.

import { isRedirectionStatus } from "https://deno.land/x/http_utils@$VERSION/status.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isRedirectionStatus(300));
assert(isRedirectionStatus(301));

isClientErrorStatus

Whether the input is ClientErrorStatus or not.

import { isClientErrorStatus } from "https://deno.land/x/http_utils@$VERSION/status.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isClientErrorStatus(400));
assert(isClientErrorStatus(401));

isServerErrorStatus

Whether the input is ServerErrorStatus or not.

import { isServerErrorStatus } from "https://deno.land/x/http_utils@$VERSION/status.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isServerErrorStatus(500));
assert(isServerErrorStatus(501));

isErrorStatus

Whether the input is ClientErrorStatus or ServerErrorStatus or not.

import { isErrorStatus } from "https://deno.land/x/http_utils@$VERSION/status.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";

assert(isErrorStatus(400));
assert(isErrorStatus(500));

License

Copyright © 2023-present httpland.

Released under the MIT license