diff --git a/packages/effect/src/unstable/http/HttpServerResponse.ts b/packages/effect/src/unstable/http/HttpServerResponse.ts index 2cef8b8e3..095c337dd 100644 --- a/packages/effect/src/unstable/http/HttpServerResponse.ts +++ b/packages/effect/src/unstable/http/HttpServerResponse.ts @@ -78,11 +78,17 @@ export const isHttpServerResponse = (u: unknown): u is HttpServerResponse => has */ export const empty = ( options?: Options.WithContent | undefined -): HttpServerResponse => - makeResponse({ +): HttpServerResponse => { + const headers = options?.headers + ? Headers.fromInput(options.headers) + : Headers.empty + return makeResponse({ status: options?.status ?? 204, - statusText: options?.statusText + statusText: options?.statusText, + headers, + cookies: options?.cookies ?? Cookies.empty }) +} /** * @since 4.0.0 diff --git a/packages/platform-node/test/NodeHttpServer.test.ts b/packages/platform-node/test/NodeHttpServer.test.ts index 2cedc2d7c..7fd0ab650 100644 --- a/packages/platform-node/test/NodeHttpServer.test.ts +++ b/packages/platform-node/test/NodeHttpServer.test.ts @@ -34,6 +34,27 @@ const IdParams = Schema.Struct({ const todoResponse = HttpServerResponse.schemaJson(Todo) describe("HttpServer", () => { + it.effect("empty", () => + Effect.gen(function*() { + const now = new Date().toISOString() + yield* HttpRouter.add( + "GET", + "/healthz", + Effect.succeed( + HttpServerResponse.empty({ + status: 200, + headers: { date: now } + }) + ) + ).pipe( + HttpRouter.serve, + Layer.build + ) + const health = yield* HttpClient.get("/healthz") + expect(health.status).toEqual(200) + expect(health.headers.date).toEqual(now) + }).pipe(Effect.provide(NodeHttpServer.layerTest))) + it.effect("schema", () => Effect.gen(function*() { yield* HttpRouter.add(