From f83c54b6886284d66f85fc7faf0860245a303b45 Mon Sep 17 00:00:00 2001 From: Tushar Mathur Date: Thu, 10 Feb 2022 16:32:31 +0530 Subject: [PATCH] feature: add `fromFileZIO` --- zio-http/src/main/scala/zhttp/http/Http.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/zio-http/src/main/scala/zhttp/http/Http.scala b/zio-http/src/main/scala/zhttp/http/Http.scala index eae70ea90a..bec26f1116 100644 --- a/zio-http/src/main/scala/zhttp/http/Http.scala +++ b/zio-http/src/main/scala/zhttp/http/Http.scala @@ -544,6 +544,12 @@ object Http { */ def fromFile(file: java.io.File): HttpApp[Any, Nothing] = response(Response(data = HttpData.fromFile(file))) + /* + * Creates an Http app from the contents of a file which is produced from an effect + */ + def fromFileZIO[R, E](fileZIO: ZIO[R, E, java.io.File]): HttpApp[R, E] = + Http.fromZIO(fileZIO.map(file => response(Response(data = HttpData.fromFile(file))))).flatten + /** * Creates a Http from a pure function */