// Copyright 2018-2026 the Deno authors. MIT license.

// HTTP/2 constants inlined from nghttp2 headers. These are all compile-time
// constants that never change, so there's no reason to fetch them from Rust.

// Header categories
(function () {
const NGHTTP2_HCAT_REQUEST = 0;
const NGHTTP2_HCAT_RESPONSE = 1;
const NGHTTP2_HCAT_PUSH_RESPONSE = 2;
const NGHTTP2_HCAT_HEADERS = 3;

// NV flags
const NGHTTP2_NV_FLAG_NONE = 0;
const NGHTTP2_NV_FLAG_NO_INDEX = 1;

// Session types
const NGHTTP2_SESSION_SERVER = 0;
const NGHTTP2_SESSION_CLIENT = 1;

// Error codes (negative)
const NGHTTP2_ERR_DEFERRED = -508;
const NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE = -509;
const NGHTTP2_ERR_INVALID_ARGUMENT = -501;
const NGHTTP2_ERR_STREAM_CLOSED = -510;
const NGHTTP2_ERR_NOMEM = -901;
const NGHTTP2_ERR_FRAME_SIZE_ERROR = -522;

// Stream states
const NGHTTP2_STREAM_STATE_IDLE = 1;
const NGHTTP2_STREAM_STATE_OPEN = 2;
const NGHTTP2_STREAM_STATE_RESERVED_LOCAL = 3;
const NGHTTP2_STREAM_STATE_RESERVED_REMOTE = 4;
const NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL = 5;
const NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE = 6;
const NGHTTP2_STREAM_STATE_CLOSED = 7;

// Frame flags
const NGHTTP2_FLAG_NONE = 0;
const NGHTTP2_FLAG_END_STREAM = 1;
const NGHTTP2_FLAG_END_HEADERS = 4;
const NGHTTP2_FLAG_ACK = 1;
const NGHTTP2_FLAG_PADDED = 8;
const NGHTTP2_FLAG_PRIORITY = 32;

// Settings IDs
const NGHTTP2_SETTINGS_HEADER_TABLE_SIZE = 1;
const NGHTTP2_SETTINGS_ENABLE_PUSH = 2;
const NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS = 3;
const NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE = 4;
const NGHTTP2_SETTINGS_MAX_FRAME_SIZE = 5;
const NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE = 6;
const NGHTTP2_SETTINGS_ENABLE_CONNECT_PROTOCOL = 8;

// Default settings (RFC 7540)
const DEFAULT_SETTINGS_HEADER_TABLE_SIZE = 4096;
const DEFAULT_SETTINGS_ENABLE_PUSH = 1;
const DEFAULT_SETTINGS_MAX_CONCURRENT_STREAMS = 0xffffffff;
const DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE = 65535;
const DEFAULT_SETTINGS_MAX_FRAME_SIZE = 16384;
const DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE = 65535;
const DEFAULT_SETTINGS_ENABLE_CONNECT_PROTOCOL = 0;

// Frame size limits
const MAX_MAX_FRAME_SIZE = 16777215;
const MIN_MAX_FRAME_SIZE = 16384;
const MAX_INITIAL_WINDOW_SIZE = 2147483647;

// Padding strategies
const PADDING_STRATEGY_NONE = 0;
const PADDING_STRATEGY_ALIGNED = 1;
const PADDING_STRATEGY_MAX = 2;
// PADDING_STRATEGY_CALLBACK has been aliased to PADDING_STRATEGY_ALIGNED
// since the per-frame `selectPadding` JS callback was removed; mirror
// Node's lib/internal/http2/constants.js so user code referencing the
// old name keeps working.
const PADDING_STRATEGY_CALLBACK = PADDING_STRATEGY_ALIGNED;

// HTTP/2 error codes (for RST_STREAM/GOAWAY)
const NGHTTP2_NO_ERROR = 0;
const NGHTTP2_PROTOCOL_ERROR = 1;
const NGHTTP2_INTERNAL_ERROR = 2;
const NGHTTP2_FLOW_CONTROL_ERROR = 3;
const NGHTTP2_SETTINGS_TIMEOUT = 4;
const NGHTTP2_STREAM_CLOSED = 5;
const NGHTTP2_FRAME_SIZE_ERROR = 6;
const NGHTTP2_REFUSED_STREAM = 7;
const NGHTTP2_CANCEL = 8;
const NGHTTP2_COMPRESSION_ERROR = 9;
const NGHTTP2_CONNECT_ERROR = 10;
const NGHTTP2_ENHANCE_YOUR_CALM = 11;
const NGHTTP2_INADEQUATE_SECURITY = 12;
const NGHTTP2_HTTP_1_1_REQUIRED = 13;

// Settings field IDs (aliases used in updateSettingsBuffer)
const HEADER_TABLE_SIZE = 1;
const ENABLE_PUSH = 2;
const MAX_CONCURRENT_STREAMS = 3;
const INITIAL_WINDOW_SIZE = 4;
const MAX_FRAME_SIZE = 5;
const MAX_HEADER_LIST_SIZE = 6;
const ENABLE_CONNECT_PROTOCOL = 8;

// Stream options
const STREAM_OPTION_EMPTY_PAYLOAD = 0x1;
const STREAM_OPTION_GET_TRAILERS = 0x2;

// Default weight
const NGHTTP2_DEFAULT_WEIGHT = 16;

// HTTP/2 header names
const HTTP2_HEADER_STATUS = ":status";
const HTTP2_HEADER_METHOD = ":method";
const HTTP2_HEADER_AUTHORITY = ":authority";
const HTTP2_HEADER_SCHEME = ":scheme";
const HTTP2_HEADER_PATH = ":path";
const HTTP2_HEADER_PROTOCOL = ":protocol";
const HTTP2_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS =
  "access-control-allow-credentials";
const HTTP2_HEADER_ACCESS_CONTROL_MAX_AGE = "access-control-max-age";
const HTTP2_HEADER_ACCESS_CONTROL_REQUEST_METHOD =
  "access-control-request-method";
const HTTP2_HEADER_AGE = "age";
const HTTP2_HEADER_AUTHORIZATION = "authorization";
const HTTP2_HEADER_CONTENT_ENCODING = "content-encoding";
const HTTP2_HEADER_CONTENT_LANGUAGE = "content-language";
const HTTP2_HEADER_CONTENT_LENGTH = "content-length";
const HTTP2_HEADER_CONTENT_LOCATION = "content-location";
const HTTP2_HEADER_CONTENT_MD5 = "content-md5";
const HTTP2_HEADER_CONTENT_RANGE = "content-range";
const HTTP2_HEADER_CONTENT_TYPE = "content-type";
const HTTP2_HEADER_COOKIE = "cookie";
const HTTP2_HEADER_DATE = "date";
const HTTP2_HEADER_DNT = "dnt";
const HTTP2_HEADER_ETAG = "etag";
const HTTP2_HEADER_EXPIRES = "expires";
const HTTP2_HEADER_FROM = "from";
const HTTP2_HEADER_HOST = "host";
const HTTP2_HEADER_IF_MATCH = "if-match";
const HTTP2_HEADER_IF_NONE_MATCH = "if-none-match";
const HTTP2_HEADER_IF_MODIFIED_SINCE = "if-modified-since";
const HTTP2_HEADER_IF_RANGE = "if-range";
const HTTP2_HEADER_IF_UNMODIFIED_SINCE = "if-unmodified-since";
const HTTP2_HEADER_LAST_MODIFIED = "last-modified";
const HTTP2_HEADER_LOCATION = "location";
const HTTP2_HEADER_MAX_FORWARDS = "max-forwards";
const HTTP2_HEADER_PROXY_AUTHORIZATION = "proxy-authorization";
const HTTP2_HEADER_RANGE = "range";
const HTTP2_HEADER_REFERER = "referer";
const HTTP2_HEADER_RETRY_AFTER = "retry-after";
const HTTP2_HEADER_SET_COOKIE = "set-cookie";
const HTTP2_HEADER_TK = "tk";
const HTTP2_HEADER_UPGRADE_INSECURE_REQUESTS = "upgrade-insecure-requests";
const HTTP2_HEADER_USER_AGENT = "user-agent";
const HTTP2_HEADER_X_CONTENT_TYPE_OPTIONS = "x-content-type-options";
const HTTP2_HEADER_CONNECTION = "connection";
const HTTP2_HEADER_UPGRADE = "upgrade";
const HTTP2_HEADER_HTTP2_SETTINGS = "http2-settings";
const HTTP2_HEADER_TE = "te";
const HTTP2_HEADER_TRANSFER_ENCODING = "transfer-encoding";
const HTTP2_HEADER_KEEP_ALIVE = "keep-alive";
const HTTP2_HEADER_PROXY_CONNECTION = "proxy-connection";
const HTTP2_HEADER_ACCEPT = "accept";
const HTTP2_HEADER_ACCEPT_CHARSET = "accept-charset";
const HTTP2_HEADER_ACCEPT_ENCODING = "accept-encoding";
const HTTP2_HEADER_ACCEPT_LANGUAGE = "accept-language";
const HTTP2_HEADER_ACCEPT_RANGES = "accept-ranges";
const HTTP2_HEADER_ACCESS_CONTROL_ALLOW_HEADERS =
  "access-control-allow-headers";
const HTTP2_HEADER_ACCESS_CONTROL_ALLOW_METHODS =
  "access-control-allow-methods";
const HTTP2_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN = "access-control-allow-origin";
const HTTP2_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS =
  "access-control-expose-headers";
const HTTP2_HEADER_ACCESS_CONTROL_REQUEST_HEADERS =
  "access-control-request-headers";
const HTTP2_HEADER_ALLOW = "allow";
const HTTP2_HEADER_ALT_SVC = "alt-svc";
const HTTP2_HEADER_CACHE_CONTROL = "cache-control";
const HTTP2_HEADER_CONTENT_DISPOSITION = "content-disposition";
const HTTP2_HEADER_CONTENT_SECURITY_POLICY = "content-security-policy";
const HTTP2_HEADER_EARLY_DATA = "early-data";
const HTTP2_HEADER_EXPECT = "expect";
const HTTP2_HEADER_EXPECT_CT = "expect-ct";
const HTTP2_HEADER_FORWARDED = "forwarded";
const HTTP2_HEADER_LINK = "link";
const HTTP2_HEADER_ORIGIN = "origin";
const HTTP2_HEADER_PREFER = "prefer";
const HTTP2_HEADER_PRIORITY = "priority";
const HTTP2_HEADER_PROXY_AUTHENTICATE = "proxy-authenticate";
const HTTP2_HEADER_PURPOSE = "purpose";
const HTTP2_HEADER_REFRESH = "refresh";
const HTTP2_HEADER_SERVER = "server";
const HTTP2_HEADER_STRICT_TRANSPORT_SECURITY = "strict-transport-security";
const HTTP2_HEADER_TIMING_ALLOW_ORIGIN = "timing-allow-origin";
const HTTP2_HEADER_TRAILER = "trailer";
const HTTP2_HEADER_VARY = "vary";
const HTTP2_HEADER_VIA = "via";
const HTTP2_HEADER_WARNING = "warning";
const HTTP2_HEADER_WWW_AUTHENTICATE = "www-authenticate";
const HTTP2_HEADER_X_FORWARDED_FOR = "x-forwarded-for";
const HTTP2_HEADER_X_FRAME_OPTIONS = "x-frame-options";
const HTTP2_HEADER_X_XSS_PROTECTION = "x-xss-protection";

// HTTP methods
const HTTP2_METHOD_CONNECT = "CONNECT";
const HTTP2_METHOD_DELETE = "DELETE";
const HTTP2_METHOD_GET = "GET";
const HTTP2_METHOD_HEAD = "HEAD";

// HTTP status codes
const HTTP_STATUS_CONTINUE = 100;
const HTTP_STATUS_SWITCHING_PROTOCOLS = 101;
const HTTP_STATUS_EARLY_HINTS = 103;
const HTTP_STATUS_OK = 200;
const HTTP_STATUS_NO_CONTENT = 204;
const HTTP_STATUS_RESET_CONTENT = 205;
const HTTP_STATUS_NOT_MODIFIED = 304;
const HTTP_STATUS_METHOD_NOT_ALLOWED = 405;
const HTTP_STATUS_EXPECTATION_FAILED = 417;
const HTTP_STATUS_MISDIRECTED_REQUEST = 421;

return {
  NGHTTP2_HCAT_REQUEST,
  NGHTTP2_HCAT_RESPONSE,
  NGHTTP2_HCAT_PUSH_RESPONSE,
  NGHTTP2_HCAT_HEADERS,
  NGHTTP2_NV_FLAG_NONE,
  NGHTTP2_NV_FLAG_NO_INDEX,
  NGHTTP2_SESSION_SERVER,
  NGHTTP2_SESSION_CLIENT,
  NGHTTP2_ERR_DEFERRED,
  NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE,
  NGHTTP2_ERR_INVALID_ARGUMENT,
  NGHTTP2_ERR_STREAM_CLOSED,
  NGHTTP2_ERR_NOMEM,
  NGHTTP2_ERR_FRAME_SIZE_ERROR,
  NGHTTP2_STREAM_STATE_IDLE,
  NGHTTP2_STREAM_STATE_OPEN,
  NGHTTP2_STREAM_STATE_RESERVED_LOCAL,
  NGHTTP2_STREAM_STATE_RESERVED_REMOTE,
  NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL,
  NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE,
  NGHTTP2_STREAM_STATE_CLOSED,
  NGHTTP2_FLAG_NONE,
  NGHTTP2_FLAG_END_STREAM,
  NGHTTP2_FLAG_END_HEADERS,
  NGHTTP2_FLAG_ACK,
  NGHTTP2_FLAG_PADDED,
  NGHTTP2_FLAG_PRIORITY,
  NGHTTP2_SETTINGS_HEADER_TABLE_SIZE,
  NGHTTP2_SETTINGS_ENABLE_PUSH,
  NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS,
  NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE,
  NGHTTP2_SETTINGS_MAX_FRAME_SIZE,
  NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE,
  NGHTTP2_SETTINGS_ENABLE_CONNECT_PROTOCOL,
  DEFAULT_SETTINGS_HEADER_TABLE_SIZE,
  DEFAULT_SETTINGS_ENABLE_PUSH,
  DEFAULT_SETTINGS_MAX_CONCURRENT_STREAMS,
  DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE,
  DEFAULT_SETTINGS_MAX_FRAME_SIZE,
  DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE,
  DEFAULT_SETTINGS_ENABLE_CONNECT_PROTOCOL,
  MAX_MAX_FRAME_SIZE,
  MIN_MAX_FRAME_SIZE,
  MAX_INITIAL_WINDOW_SIZE,
  PADDING_STRATEGY_NONE,
  PADDING_STRATEGY_ALIGNED,
  PADDING_STRATEGY_MAX,
  PADDING_STRATEGY_CALLBACK,
  NGHTTP2_NO_ERROR,
  NGHTTP2_PROTOCOL_ERROR,
  NGHTTP2_INTERNAL_ERROR,
  NGHTTP2_FLOW_CONTROL_ERROR,
  NGHTTP2_SETTINGS_TIMEOUT,
  NGHTTP2_STREAM_CLOSED,
  NGHTTP2_FRAME_SIZE_ERROR,
  NGHTTP2_REFUSED_STREAM,
  NGHTTP2_CANCEL,
  NGHTTP2_COMPRESSION_ERROR,
  NGHTTP2_CONNECT_ERROR,
  NGHTTP2_ENHANCE_YOUR_CALM,
  NGHTTP2_INADEQUATE_SECURITY,
  NGHTTP2_HTTP_1_1_REQUIRED,
  HEADER_TABLE_SIZE,
  ENABLE_PUSH,
  MAX_CONCURRENT_STREAMS,
  INITIAL_WINDOW_SIZE,
  MAX_FRAME_SIZE,
  MAX_HEADER_LIST_SIZE,
  ENABLE_CONNECT_PROTOCOL,
  STREAM_OPTION_EMPTY_PAYLOAD,
  STREAM_OPTION_GET_TRAILERS,
  NGHTTP2_DEFAULT_WEIGHT,
  HTTP2_HEADER_STATUS,
  HTTP2_HEADER_METHOD,
  HTTP2_HEADER_AUTHORITY,
  HTTP2_HEADER_SCHEME,
  HTTP2_HEADER_PATH,
  HTTP2_HEADER_PROTOCOL,
  HTTP2_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS,
  HTTP2_HEADER_ACCESS_CONTROL_MAX_AGE,
  HTTP2_HEADER_ACCESS_CONTROL_REQUEST_METHOD,
  HTTP2_HEADER_AGE,
  HTTP2_HEADER_AUTHORIZATION,
  HTTP2_HEADER_CONTENT_ENCODING,
  HTTP2_HEADER_CONTENT_LANGUAGE,
  HTTP2_HEADER_CONTENT_LENGTH,
  HTTP2_HEADER_CONTENT_LOCATION,
  HTTP2_HEADER_CONTENT_MD5,
  HTTP2_HEADER_CONTENT_RANGE,
  HTTP2_HEADER_CONTENT_TYPE,
  HTTP2_HEADER_COOKIE,
  HTTP2_HEADER_DATE,
  HTTP2_HEADER_DNT,
  HTTP2_HEADER_ETAG,
  HTTP2_HEADER_EXPIRES,
  HTTP2_HEADER_FROM,
  HTTP2_HEADER_HOST,
  HTTP2_HEADER_IF_MATCH,
  HTTP2_HEADER_IF_NONE_MATCH,
  HTTP2_HEADER_IF_MODIFIED_SINCE,
  HTTP2_HEADER_IF_RANGE,
  HTTP2_HEADER_IF_UNMODIFIED_SINCE,
  HTTP2_HEADER_LAST_MODIFIED,
  HTTP2_HEADER_LOCATION,
  HTTP2_HEADER_MAX_FORWARDS,
  HTTP2_HEADER_PROXY_AUTHORIZATION,
  HTTP2_HEADER_RANGE,
  HTTP2_HEADER_REFERER,
  HTTP2_HEADER_RETRY_AFTER,
  HTTP2_HEADER_SET_COOKIE,
  HTTP2_HEADER_TK,
  HTTP2_HEADER_UPGRADE_INSECURE_REQUESTS,
  HTTP2_HEADER_USER_AGENT,
  HTTP2_HEADER_X_CONTENT_TYPE_OPTIONS,
  HTTP2_HEADER_CONNECTION,
  HTTP2_HEADER_UPGRADE,
  HTTP2_HEADER_HTTP2_SETTINGS,
  HTTP2_HEADER_TE,
  HTTP2_HEADER_TRANSFER_ENCODING,
  HTTP2_HEADER_KEEP_ALIVE,
  HTTP2_HEADER_PROXY_CONNECTION,
  HTTP2_HEADER_ACCEPT,
  HTTP2_HEADER_ACCEPT_CHARSET,
  HTTP2_HEADER_ACCEPT_ENCODING,
  HTTP2_HEADER_ACCEPT_LANGUAGE,
  HTTP2_HEADER_ACCEPT_RANGES,
  HTTP2_HEADER_ACCESS_CONTROL_ALLOW_HEADERS,
  HTTP2_HEADER_ACCESS_CONTROL_ALLOW_METHODS,
  HTTP2_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
  HTTP2_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS,
  HTTP2_HEADER_ACCESS_CONTROL_REQUEST_HEADERS,
  HTTP2_HEADER_ALLOW,
  HTTP2_HEADER_ALT_SVC,
  HTTP2_HEADER_CACHE_CONTROL,
  HTTP2_HEADER_CONTENT_DISPOSITION,
  HTTP2_HEADER_CONTENT_SECURITY_POLICY,
  HTTP2_HEADER_EARLY_DATA,
  HTTP2_HEADER_EXPECT,
  HTTP2_HEADER_EXPECT_CT,
  HTTP2_HEADER_FORWARDED,
  HTTP2_HEADER_LINK,
  HTTP2_HEADER_ORIGIN,
  HTTP2_HEADER_PREFER,
  HTTP2_HEADER_PRIORITY,
  HTTP2_HEADER_PROXY_AUTHENTICATE,
  HTTP2_HEADER_PURPOSE,
  HTTP2_HEADER_REFRESH,
  HTTP2_HEADER_SERVER,
  HTTP2_HEADER_STRICT_TRANSPORT_SECURITY,
  HTTP2_HEADER_TIMING_ALLOW_ORIGIN,
  HTTP2_HEADER_TRAILER,
  HTTP2_HEADER_VARY,
  HTTP2_HEADER_VIA,
  HTTP2_HEADER_WARNING,
  HTTP2_HEADER_WWW_AUTHENTICATE,
  HTTP2_HEADER_X_FORWARDED_FOR,
  HTTP2_HEADER_X_FRAME_OPTIONS,
  HTTP2_HEADER_X_XSS_PROTECTION,
  HTTP2_METHOD_CONNECT,
  HTTP2_METHOD_DELETE,
  HTTP2_METHOD_GET,
  HTTP2_METHOD_HEAD,
  HTTP_STATUS_CONTINUE,
  HTTP_STATUS_SWITCHING_PROTOCOLS,
  HTTP_STATUS_EARLY_HINTS,
  HTTP_STATUS_OK,
  HTTP_STATUS_NO_CONTENT,
  HTTP_STATUS_RESET_CONTENT,
  HTTP_STATUS_NOT_MODIFIED,
  HTTP_STATUS_METHOD_NOT_ALLOWED,
  HTTP_STATUS_EXPECTATION_FAILED,
  HTTP_STATUS_MISDIRECTED_REQUEST,
};
})();
