{"id":19475464,"url":"https://github.com/artdecocode/https-context","last_synced_at":"2025-08-01T09:37:48.558Z","repository":{"id":57268515,"uuid":"139454992","full_name":"artdecocode/https-context","owner":"artdecocode","description":"A Zoroaster test context that sets up an HTTP and self-signed HTTPS servers.","archived":false,"fork":false,"pushed_at":"2018-09-24T12:41:23.000Z","size":34,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-30T07:17:43.652Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://contexttesting.com","language":"JavaScript","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/artdecocode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2018-07-02T14:32:09.000Z","updated_at":"2018-09-24T12:41:24.000Z","dependencies_parsed_at":"2022-09-02T02:02:02.462Z","dependency_job_id":null,"html_url":"https://github.com/artdecocode/https-context","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/artdecocode/https-context","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artdecocode%2Fhttps-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artdecocode%2Fhttps-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artdecocode%2Fhttps-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artdecocode%2Fhttps-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/artdecocode","download_url":"https://codeload.github.com/artdecocode/https-context/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artdecocode%2Fhttps-context/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268199860,"owners_count":24211826,"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","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-10T19:32:58.108Z","updated_at":"2025-08-01T09:37:48.486Z","avatar_url":"https://github.com/artdecocode.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# https-context\n\n[![npm version](https://badge.fury.io/js/https-context.svg)](https://npmjs.org/package/https-context)\n\n`https-context` is a Zoroaster test context that sets up an HTTP and self-signed HTTPS servers. It can be used in testing packages that make requests. A new server will be installed for each test case, and all connections open to the server will be closed in the destroy method. This ensures that every gets gets a unique http server to be tested against, which is automatically destroyed so that the developers don't need to worry about implementing the tear-down.\n\n```sh\nyarn add -DE https-context\n```\n\n## Table Of Contents\n\n- [Table Of Contents](#table-of-contents)\n- [HTTP API](#http-api)\n  * [`response(): string|buffer`](#response-stringbuffer)\n  * [`host(): string`](#host-string)\n  * [`url(): string`](#url-string)\n  * [`setResponse(data: string|Buffer)`](#setresponsedata-stringbuffer-void)\n  * [`setHeaders(headers: Object)`](#setheadersheaders-object-void)\n  * [`setContentType(contentType: string)`](#setcontenttypecontenttype-string-void)\n  * [`state(): State`](#state-state)\n  * [`State` Type](#state-type)\n    * [\u003ccode\u003ecalled\u003c/code\u003e](#called)\n    * [\u003ccode\u003eheaders\u003c/code\u003e](#headers)\n    * [\u003ccode\u003epostData\u003c/code\u003e](#postdata)\n\n## HTTP API\n\nThe context can be used by setting it in a `zoroaster` test case:\n\n```javascript\nimport { ok, deepEqual } from 'zoroaster/assert'\nimport rqt from 'rqt'\nimport { HTTPContext } from 'https-context'\n\n/** @type {Object.\u003cstring, (c: HTTPContext)\u003e} */\nconst T = {\n  context: HTTPContext,\n  async 'starts the context'({ url }) {\n    ok(url)\n  },\n  async 'responds to the message'({ url, setResponse, setContentType }) {\n    const d = { hello: 'world' }\n    setResponse(JSON.stringify(d))\n    setContentType('application/json')\n    const res = await rqt(url)\n    deepEqual(res, d)\n  },\n  async 'sends headers'({ url, state, host }) {\n    const headers = {\n      'user-agent': 'node.js',\n    }\n    await rqt(url, {\n      headers,\n    })\n    ok(state.called)\n    deepEqual(state.headers, {\n      host,\n      connection: 'close',\n      ...headers,\n    })\n  },\n}\n\nexport default T\n```\n\n### `response(): string|buffer`\n\nReturns what the response was set to (default `OK`).\n\n\n### `host(): string`\n\nThe host of the server, e.g., `127.0.0.1:49629`.\n\n### `url(): string`\n\nReturns the server `url`, such as `http://127.0.0.1:49629`.\n\n### `setResponse(`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`data: string|Buffer,`\u003cbr/\u003e`): void`\n\nSets the response with which the server will end the request. `OK` by default.\n\n### `setHeaders(`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`headers: Object,`\u003cbr/\u003e`): void`\n\nSets the headers which are sent back to the client.\n\n### `setContentType(`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`contentType: string,`\u003cbr/\u003e`): void`\n\nSets the content type of the response. If not set, `text/plain` will be used by default.\n\n### `state(): State`\n\nGet the state of the context, according to the [State type](#state-type).\n\n### `State` Type\n\n\u003ctable\u003e\n \u003cthead\u003e\n  \u003ctr\u003e\n   \u003cth\u003eProperty\u003c/th\u003e\n   \u003cth\u003eType\u003c/th\u003e\n   \u003cth\u003eDescription\u003c/th\u003e\n   \u003cth\u003eExample\u003c/th\u003e\n  \u003c/tr\u003e\n \u003c/thead\u003e\n \u003ctbody\u003e\n   \u003ctr\u003e\n  \u003ctd\u003e\u003ca name=\"called\"\u003e\u003ccode\u003ecalled\u003c/code\u003e\u003c/a\u003e\u003c/td\u003e\n  \u003ctd\u003e\u003cem\u003enumber\u003c/em\u003e\u003c/td\u003e\n  \u003ctd\u003eThe number of times the server was called. Starts with 0.\u003c/td\u003e\n  \u003ctd\u003e0, 2, 3\u003c/td\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\n  \u003ctd\u003e\u003ca name=\"headers\"\u003e\u003ccode\u003eheaders\u003c/code\u003e\u003c/a\u003e\u003c/td\u003e\n  \u003ctd\u003e\u003cem\u003eobject\u003c/em\u003e\u003c/td\u003e\n  \u003ctd\u003eRequest headers used previously.\u003c/td\u003e\n  \u003ctd\u003e{}\u003c/td\u003e\n \u003c/tr\u003e\n \u003ctr\u003e\n  \u003ctd\u003e\u003ca name=\"postdata\"\u003e\u003ccode\u003epostData\u003c/code\u003e\u003c/a\u003e\u003c/td\u003e\n  \u003ctd\u003e\u003cem\u003estring\u003c/em\u003e\u003c/td\u003e\n  \u003ctd\u003eThe data sent with the request via any method other than `POST`.\u003c/td\u003e\n  \u003ctd\u003eHello World\u003c/td\u003e\n \u003c/tr\u003e\n \u003c/tbody\u003e\n\u003c/table\u003e\n\n---\n\n(c) [Art Deco Code][1] 2018\n\n[1]: https://artdeco.bz\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartdecocode%2Fhttps-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartdecocode%2Fhttps-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartdecocode%2Fhttps-context/lists"}