@alwatr/http-primer
Version:
Essential HTTP utilities for TypeScript, including types for HTTP methods, status codes, and headers.
8 lines (7 loc) • 19.3 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../src/main.ts", "../src/constant.ts"],
"sourcesContent": ["export * from './constant.js';\nexport type * from './type.js';\n", "/**\n * Object representing standard HTTP methods.\n */\nexport const HttpMethods = /* #__PURE__ */ {\n /**\n * GET: Requests a representation of the specified resource.\n */\n GET: 'GET',\n\n /**\n * HEAD: Asks for a response identical to that of a GET request, but without the response body.\n */\n HEAD: 'HEAD',\n\n /**\n * POST: Submits data to be processed (e.g., from an HTML form) to the identified resource.\n */\n POST: 'POST',\n\n /**\n * PUT: Uploads a representation of the specified URI.\n */\n PUT: 'PUT',\n\n /**\n * DELETE: Deletes the specified resource.\n */\n DELETE: 'DELETE',\n\n /**\n * CONNECT: Establishes a tunnel to the server identified by the target resource.\n */\n CONNECT: 'CONNECT',\n\n /**\n * OPTIONS: Describes the communication options for the target resource.\n */\n OPTIONS: 'OPTIONS',\n\n /**\n * TRACE: Performs a message loop-back test along the path to the target resource.\n */\n TRACE: 'TRACE',\n\n /**\n * PATCH: Applies partial modifications to a resource.\n */\n PATCH: 'PATCH',\n} as const;\n\n/**\n * Object representing standard HTTP status codes.\n */\nexport const HttpStatusCodes = /* #__PURE__ */ {\n /**\n * 100 Continue: The server has received the request headers and the client should proceed to send the request body.\n */\n Info_100_Continue: 100,\n\n /**\n * 101 Switching Protocols: The server understands and is willing to comply with the clients request to switch protocols.\n */\n Info_101_Switching_Protocols: 101,\n\n /**\n * 102 Processing: The server has received and is processing the request, but no response is available yet.\n */\n Info_102_Processing: 102,\n\n /**\n * 103 Early Hints: The server is sending some response headers before the final HTTP message.\n */\n Info_103_Early_Hints: 103,\n\n /**\n * 200 OK: The request has succeeded.\n */\n Success_200_OK: 200,\n\n /**\n * 201 Created: The request has been fulfilled and resulted in a new resource being created.\n */\n Success_201_Created: 201,\n\n /**\n * 202 Accepted: The request has been accepted for processing, but the processing has not been completed.\n */\n Success_202_Accepted: 202,\n\n /**\n * 203 Non-Authoritative Information: The server is a transforming proxy that received a 200 OK\n * from the origin server but is returning a modified version of the origins response.\n */\n Success_203_Non_Authoritative_Information: 203,\n\n /**\n * 204 No Content: The server successfully processed the request and is not returning any content.\n */\n Success_204_No_Content: 204,\n\n /**\n * 205 Reset Content: The server successfully processed the request,\n * asks that the client reset its document view, and is not returning any content.\n */\n Success_205_Reset_Content: 205,\n\n /**\n * 206 Partial Content: The server is delivering only part of the resource due to a range header sent by the client.\n */\n Success_206_Partial_Content: 206,\n\n /**\n * 207 Multi-Status: The message body that follows is an XML message\n * and can contain a number of separate response codes, depending on how many sub-requests were made.\n */\n Success_207_Multi_Status: 207,\n\n /**\n * 208 Already Reported: The members of a DAV binding have already been enumerated\n * in a preceding part of the (multi-status) response, and are not being included again.\n */\n Success_208_Already_Reported: 208,\n\n /**\n * 226 IM Used: The server has fulfilled a request for the resource, and the response is a representation\n * of the result of one or more instance-manipulations applied to the current instance.\n */\n Success_226_IM_Used: 226,\n\n /**\n * 300 Multiple Choices: The request has more than one possible response.\n */\n Redirect_300_Multiple_Choices: 300,\n\n /**\n * 301 Moved Permanently: The URL of the requested resource has been changed permanently.\n */\n Redirect_301_Moved_Permanently: 301,\n\n /**\n * 302 Found: The URL of the requested resource has been changed temporarily.\n */\n Redirect_302_Found: 302,\n\n /**\n * 303 See Other: The response to the request can be found under another URI using a GET method.\n */\n Redirect_303_See_Other: 303,\n\n /**\n * 304 Not Modified: The resource has not been modified since the version specified\n * by the request headers If-Modified-Since or If-None-Match.\n */\n Redirect_304_Not_Modified: 304,\n\n /**\n * 305 Use Proxy: The requested resource is only available through a proxy, the address for which is provided in the response.\n */\n Redirect_305_Use_Proxy: 305,\n\n /**\n * 306 Switch Proxy: No longer used. Originally meant \"Subsequent requests should use the specified proxy.\"\n */\n Redirect_306_Switch_Proxy: 306,\n\n /**\n * 307 Temporary Redirect: The server sends this response to direct the client\n * to get the requested resource at another URI with the same method that was used in the prior request.\n */\n Redirect_307_Temporary_Redirect: 307,\n\n /**\n * 308 Permanent Redirect: This means that the resource is now permanently located at another URI,\n * specified by the Location: HTTP Response header.\n */\n Redirect_308_Permanent_Redirect: 308,\n\n /**\n * 400 Bad Request: The server cannot or will not process the request due to something that is perceived to be a client error.\n */\n Error_Client_400_Bad_Request: 400,\n\n /**\n * 401 Unauthorized: The request has not been applied because it lacks valid authentication credentials for the target resource.\n */\n Error_Client_401_Unauthorized: 401,\n\n /**\n * 402 Payment Required: Reserved for future use.\n */\n Error_Client_402_Payment_Required: 402,\n\n /**\n * 403 Forbidden: The client does not have access rights to the content, so the server is refusing to give the requested resource.\n */\n Error_Client_403_Forbidden: 403,\n\n /**\n * 404 Not Found: The server can not find the requested resource.\n */\n Error_Client_404_Not_Found: 404,\n\n /**\n * 405 Method Not Allowed: The request method is known by the server but is not supported by the target resource.\n */\n Error_Client_405_Method_Not_Allowed: 405,\n\n /**\n * 406 Not Acceptable: The target resource does not have a current representation that would be acceptable\n * to the user agent, according to the proactive negotiation header fields received in the request,\n * and the server is unwilling to supply a default representation.\n */\n Error_Client_406_Not_Acceptable: 406,\n\n /**\n * 407 Proxy Authentication Required: Similar to 401 Unauthorized,\n * but it indicates that the client needs to authenticate itself in order to use a proxy.\n */\n Error_Client_407_Proxy_Authentication_Required: 407,\n\n /**\n * 408 Request Timeout: The server timed out waiting for the request.\n */\n Error_Client_408_Request_Timeout: 408,\n\n /**\n * 409 Conflict: The request could not be processed because of conflict in the request, such as an edit conflict.\n */\n Error_Client_409_Conflict: 409,\n\n /**\n * 410 Gone: The requested resource is no longer available and will not be available again.\n */\n Error_Client_410_Gone: 410,\n\n /**\n * 411 Length Required: The server refuses to accept the request without a defined Content-Length header.\n */\n Error_Client_411_Length_Required: 411,\n\n /**\n * 412 Precondition Failed: One or more conditions given in the request header fields evaluated to false when tested on the server.\n */\n Error_Client_412_Precondition_Failed: 412,\n\n /**\n * 413 Payload Too Large: The server is refusing to process a request because the request payload is larger\n * than the server is willing or able to process.\n */\n Error_Client_413_Payload_Too_Large: 413,\n\n /**\n * 414 URI Too Long: The server is refusing to service the request because the URI is longer than the server is willing to interpret.\n */\n Error_Client_414_URI_Too_Long: 414,\n\n /**\n * 415 Unsupported Media Type: The server is refusing to service the request\n * because the entity of the request is in a format not supported by the requested resource for the requested method.\n */\n Error_Client_415_Unsupported_Media_Type: 415,\n\n /**\n * 416 Range Not Satisfiable: The client has asked for a portion of the file, but the server cannot supply that portion.\n */\n Error_Client_416_Range_Not_Satisfiable: 416,\n\n /**\n * 417 Expectation Failed: The server cannot meet the requirements of the Expect request-header field.\n */\n Error_Client_417_Expectation_Failed: 417,\n\n /**\n * 421 Misdirected Request: The request was directed at a server that is not able to produce a response.\n */\n Error_Client_421_Misdirected_Request: 421,\n\n /**\n * 422 Unprocessable Entity: The request was well-formed but was unable to be followed due to semantic errors.\n */\n Error_Client_422_Unprocessable_Entity: 422,\n\n /**\n * 423 Locked: The resource that is being accessed is locked.\n */\n Error_Client_423_Locked: 423,\n\n /**\n * 424 Failed Dependency: The request failed due to a failure of a previous request.\n */\n Error_Client_424_Failed_Dependency: 424,\n\n /**\n * 425 Too Early: The server is unwilling to risk processing a request that might be replayed.\n */\n Error_Client_425_Too_Early: 425,\n\n /**\n * 426 Upgrade Required: The server refuses to perform the request using the current protocol\n * but might be willing to do so after the client upgrades to a different protocol.\n */\n Error_Client_426_Upgrade_Required: 426,\n\n /**\n * 428 Precondition Required: The origin server requires the request to be conditional.\n */\n Error_Client_428_Precondition_Required: 428,\n\n /**\n * 429 Too Many Requests: The user has sent too many requests in a given amount of time (\"rate limiting\").\n */\n Error_Client_429_Too_Many_Requests: 429,\n\n /**\n * 431 Request Header Fields Too Large: The server is unwilling to process the request because its header fields are too large.\n */\n Error_Client_431_Request_Header_Fields_Too_Large: 431,\n\n /**\n * 451 Unavailable For Legal Reasons: The user requests an illegal resource, such as a web page censored by a government.\n */\n Error_Client_451_Unavailable_For_Legal_Reasons: 451,\n\n /**\n * 500 Internal Server Error: A generic error message, given when no more specific message is suitable.\n */\n Error_Server_500_Internal_Server_Error: 500,\n\n /**\n * 501 Not Implemented: The server either does not recognize the request method, or it lacks the ability to fulfill the request.\n */\n Error_Server_501_Not_Implemented: 501,\n\n /**\n * 502 Bad Gateway: The server was acting as a gateway or proxy and received an invalid response from the upstream server.\n */\n Error_Server_502_Bad_Gateway: 502,\n\n /**\n * 503 Service Unavailable: The server is currently unavailable (because it is overloaded or down for maintenance).\n */\n Error_Server_503_Service_Unavailable: 503,\n\n /**\n * 504 Gateway Timeout: The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.\n */\n Error_Server_504_Gateway_Timeout: 504,\n\n /**\n * 505 HTTP Version Not Supported: The server does not support the HTTP protocol version used in the request.\n */\n Error_Server_505_HTTP_Version_Not_Supported: 505,\n\n /**\n * 506 Variant Also Negotiates: Transparent content negotiation for the request results in a circular reference.\n */\n Error_Server_506_Variant_Also_Negotiates: 506,\n\n /**\n * 507 Insufficient Storage: The server is unable to store the representation needed to complete the request.\n */\n Error_Server_507_Insufficient_Storage: 507,\n\n /**\n * 508 Loop Detected: The server detected an infinite loop while processing the request.\n */\n Error_Server_508_Loop_Detected: 508,\n\n /**\n * 510 Not Extended: Further extensions to the request are required for the server to fulfill it.\n */\n Error_Server_510_Not_Extended: 510,\n\n /**\n * 511 Network Authentication Required: The client needs to authenticate to gain network access.\n */\n Error_Server_511_Network_Authentication_Required: 511,\n} as const;\n\n/**\n * Object representing standard HTTP status messages.\n */\nexport const HttpStatusMessages = /* #__PURE__ */ {\n 100: 'Continue',\n 101: 'Switching Protocols',\n 102: 'Processing',\n 103: 'Early Hints',\n 200: 'OK',\n 201: 'Created',\n 202: 'Accepted',\n 203: 'Non-Authoritative Information',\n 204: 'No Content',\n 205: 'Reset Content',\n 206: 'Partial Content',\n 207: 'Multi-Status',\n 208: 'Already Reported',\n 226: 'IM Used',\n 300: 'Multiple Choices',\n 301: 'Moved Permanently',\n 302: 'Found',\n 303: 'See Other',\n 304: 'Not Modified',\n 305: 'Use Proxy',\n 307: 'Temporary Redirect',\n 308: 'Permanent Redirect',\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 402: 'Payment Required',\n 403: 'Forbidden',\n 404: 'Not Found',\n 405: 'Method Not Allowed',\n 406: 'Not Acceptable',\n 407: 'Proxy Authentication Required',\n 408: 'Request Timeout',\n 409: 'Conflict',\n 410: 'Gone',\n 411: 'Length Required',\n 412: 'Precondition Failed',\n 413: 'Payload Too Large',\n 414: 'URI Too Long',\n 415: 'Unsupported Media Type',\n 416: 'Range Not Satisfiable',\n 417: 'Expectation Failed',\n 418: \"I'm a Teapot\",\n 421: 'Misdirected Request',\n 422: 'Unprocessable Entity',\n 423: 'Locked',\n 424: 'Failed Dependency',\n 425: 'Too Early',\n 426: 'Upgrade Required',\n 428: 'Precondition Required',\n 429: 'Too Many Requests',\n 431: 'Request Header Fields Too Large',\n 451: 'Unavailable For Legal Reasons',\n 500: 'Internal Server Error',\n 501: 'Not Implemented',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n 505: 'HTTP Version Not Supported',\n 506: 'Variant Also Negotiates',\n 507: 'Insufficient Storage',\n 508: 'Loop Detected',\n 509: 'Bandwidth Limit Exceeded',\n 510: 'Not Extended',\n 511: 'Network Authentication Required',\n};\n\n/**\n * Type representing standard HTTP status codes.\n */\nexport type HttpStatusCode = keyof typeof HttpStatusMessages;\n\n/**\n * Object representing standard MIME types.\n */\nexport const MimeTypes = /* #__PURE__ */ {\n AAC: 'audio/aac',\n ABW: 'application/x-abiword',\n ARC: 'application/x-freearc',\n AVI: 'video/x-msvideo',\n AZW: 'application/vnd.amazon.ebook',\n BIN: 'application/octet-stream',\n BMP: 'image/bmp',\n BZ: 'application/x-bzip',\n BZ2: 'application/x-bzip2',\n CSH: 'application/x-csh',\n CSS: 'text/css',\n CSV: 'text/csv',\n DOC: 'application/msword',\n DOCX: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n EOT: 'application/vnd.ms-fontobject',\n EPUB: 'application/epub+zip',\n GZ: 'application/gzip',\n GIF: 'image/gif',\n HTML: 'text/html',\n ICO: 'image/vnd.microsoft.icon',\n ICS: 'text/calendar',\n JAR: 'application/java-archive',\n JPEG: 'image/jpeg',\n JS: 'text/javascript',\n JSON: 'application/json',\n JSONLD: 'application/ld+json',\n MID: 'audio/midi',\n MIDI: 'audio/midi',\n MJS: 'text/javascript',\n MP3: 'audio/mpeg',\n MP4: 'video/mp4',\n MPEG: 'video/mpeg',\n MPKG: 'application/vnd.apple.installer+xml',\n ODP: 'application/vnd.oasis.opendocument.presentation',\n ODS: 'application/vnd.oasis.opendocument.spreadsheet',\n ODT: 'application/vnd.oasis.opendocument.text',\n OGA: 'audio/ogg',\n OGV: 'video/ogg',\n OGX: 'application/ogg',\n OPUS: 'audio/opus',\n OTF: 'font/otf',\n PNG: 'image/png',\n PDF: 'application/pdf',\n PHP: 'application/x-httpd-php',\n PPT: 'application/vnd.ms-powerpoint',\n PPTX: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n RAR: 'application/vnd.rar',\n RTF: 'application/rtf',\n SH: 'application/x-sh',\n SVG: 'image/svg+xml',\n SWF: 'application/x-shockwave-flash',\n TAR: 'application/x-tar',\n TIFF: 'image/tiff',\n TS: 'video/mp2t',\n TTF: 'font/ttf',\n TXT: 'text/plain',\n VS: 'application/x-sh',\n WAV: 'audio/wav',\n WEBA: 'audio/webm',\n WEBM: 'video/webm',\n WEBP: 'image/webp',\n WOFF: 'font/woff',\n WOFF2: 'font/woff2',\n XHTML: 'application/xhtml+xml',\n XLS: 'application/vnd.ms-excel',\n XLSX: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n XML: 'application/xml',\n XUL: 'application/vnd.mozilla.xul+xml',\n ZIP: 'application/zip',\n '3GP': 'video/3gpp',\n '3G2': 'video/3gpp2',\n '7Z': 'application/x-7z-compressed',\n} as const;\n"],
"mappings": ";qqBAAA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AK,kBACL,GAAI,mBACJ,IAAK,gBACL,IAAK,gCACL,IAAK,oBACL,KAAM,aACN,GAAI,aACJ,IAAK,WACL,IAAK,aACL,GAAI,mBACJ,IAAK,YACL,KAAM,aACN,KAAM,aACN,KAAM,aACN,KAAM,YACN,MAAO,aACP,MAAO,wBACP,IAAK,2BACL,KAAM,oEACN,IAAK,kBACL,IAAK,kCACL,IAAK,kBACL,MAAO,aACP,MAAO,cACP,KAAM,6BACR",
"names": []
}