{"id":22525694,"url":"https://github.com/xinpianchang/xpc-http","last_synced_at":"2025-08-03T21:32:40.203Z","repository":{"id":42395151,"uuid":"386651313","full_name":"xinpianchang/xpc-http","owner":"xinpianchang","description":"a http utility for node.js","archived":false,"fork":false,"pushed_at":"2023-05-11T07:46:56.000Z","size":31,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-18T09:13:32.008Z","etag":null,"topics":["context","http","nextjs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xinpianchang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-16T13:44:02.000Z","updated_at":"2023-02-10T11:50:02.000Z","dependencies_parsed_at":"2022-09-27T10:50:27.289Z","dependency_job_id":null,"html_url":"https://github.com/xinpianchang/xpc-http","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xinpianchang%2Fxpc-http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xinpianchang%2Fxpc-http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xinpianchang%2Fxpc-http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xinpianchang%2Fxpc-http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xinpianchang","download_url":"https://codeload.github.com/xinpianchang/xpc-http/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228567012,"owners_count":17937986,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["context","http","nextjs"],"created_at":"2024-12-07T06:11:06.157Z","updated_at":"2024-12-07T06:11:06.832Z","avatar_url":"https://github.com/xinpianchang.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Instructions\n\n  [![@newstudios/http-utils][npm-image]][npm-url]\n\n## Npm install\n```shell\n  npm install --save @newstudios/http-utils\n```\n\n## Yarn install\n```shell\n  yarn add @newstudios/http-utils\n```\n\n# Usage notice\n\nThe package is a commonjs library, and needs some environments to work as expected\n```bash\n# whether the http server is behind a proxy, default is false\nHTTP_BEHIND_PROXY = true\n\n# http forwarded ip header name, default is 'x-forwaded-for'\nHTTP_FORWARDED_IP_HEADERS = x-forwarded-for\n\n# http forwaded ips max count, default is 0, means no limit restrictions\nHTTP_MAX_IPS_COUNT = 0\n```\n\n# API\n```typescript\nexport declare function getHeader\u003cF extends string\u003e(req: IncomingMessage, field: F): HeaderType\u003cF\u003e;\nexport declare function getUserAgent(req: IncomingMessage): string;\nexport declare function getHost(req: IncomingMessage): string;\n/**\n * Parse the \"Host\" header field hostname\n * and support X-Forwarded-Host when a\n * proxy is enabled.\n */\nexport declare function getHostname(req: IncomingMessage): string;\n/**\n * Get WHATWG parsed URL.\n * Lazily memoized.\n */\nexport declare function getURL(req: IncomingMessage): URL;\nexport declare function getHref(req: IncomingMessage): string;\nexport declare function getOrigin(req: IncomingMessage): string;\n/**\n * Return the protocol string \"http\" or \"https\"\n * when requested with TLS. When the proxy setting\n * is enabled the \"X-Forwarded-Proto\" header\n * field will be trusted. If you're running behind\n * a reverse proxy that supplies https for you this\n * may be enabled.\n */\nexport declare function getProtocol(req: IncomingMessage): string;\n/**\n * When `config.proxy` is `true`, parse\n * the \"X-Forwarded-For\" ip address list.\n *\n * For example if the value was \"client, proxy1, proxy2\"\n * you would receive the array `[\"client\", \"proxy1\", \"proxy2\"]`\n * where \"proxy2\" is the furthest down-stream.\n */\nexport declare function getIps(req: IncomingMessage): string[];\n/**\n * Return request's remote address\n * When `config.proxy` is `true`, parse\n * the \"X-Forwarded-For\" ip address list and return the first one\n */\nexport declare function getIp(req: IncomingMessage): string;\nexport declare function setIp(req: IncomingMessage, ip: string): void;\nexport declare function setHeader(res: ServerResponse, field: Record\u003cstring, any\u003e): void;\nexport declare function setHeader(res: ServerResponse, field: string, val: any): void;\nexport declare function appendHeader(res: ServerResponse, field: string, val: any): void;\nexport declare function appendHeaders(res: ServerResponse, init: HeadersInit): void;\nexport declare type SetCookieOptions = Omit\u003cCookieSerializeOptions, 'encode'\u003e;\n/**\n * Get cookie from request headers cookie, value will be decoded with decodeURIComponent\n * @returns {string | undefined}\n */\nexport declare function getCookie(req: IncomingMessage, name: string): string | undefined;\n/**\n * set cookie on response, value will be encoded with encodeURIComponent\n * @param options {SetCookieOptions} options.maxAge in milliseconds\n */\nexport declare function setCookie(res: ServerResponse, name: string, val: string, options?: SetCookieOptions): void;\nexport declare function clearCookie(res: ServerResponse, name: string, options?: SetCookieOptions): void;\n```\n\n[npm-image]: https://img.shields.io/npm/v/@newstudios/http-utils.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@newstudios/http-utils\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxinpianchang%2Fxpc-http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxinpianchang%2Fxpc-http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxinpianchang%2Fxpc-http/lists"}