diff --git a/docs/website/docs/examples/advanced-examples/cors.md b/docs/website/docs/examples/advanced-examples/cors.md deleted file mode 100644 index 2d28565ca2..0000000000 --- a/docs/website/docs/examples/advanced-examples/cors.md +++ /dev/null @@ -1,22 +0,0 @@ -# CORS Handling - -```scala -import zhttp.http._ -import zhttp.service.Server -import zio._ - -object HelloWorldWithCORS extends ZIOAppDefault { - // Create HTTP route with CORS enabled - val app: HttpApp[Any, Nothing] = CORS( - Http.collect[Request] { - case Method.GET -> !! / "text" => Response.text("Hello World!") - case Method.GET -> !! / "json" => Response.jsonString("""{"greetings": "Hello World!"}""") - }, - config = CORSConfig(anyOrigin = true), - ) - - // Run it like any simple app - val run = - Server.start(8090, app.silent) -} -``` \ No newline at end of file diff --git a/docs/website/docs/examples/advanced-examples/stream-file.md b/docs/website/docs/examples/advanced-examples/stream-file.md deleted file mode 100644 index 32c16875a7..0000000000 --- a/docs/website/docs/examples/advanced-examples/stream-file.md +++ /dev/null @@ -1,33 +0,0 @@ -# Streaming File -```scala -import zhttp.http._ -import zhttp.service.Server -import zio.stream.ZStream -import zio._ - -import java.io.File -import java.nio.file.Paths - -object FileStreaming extends ZIOAppDefault { - - // Create HTTP route - val app = Http.collectHttp[Request] { - case Method.GET -> !! / "health" => Http.ok - - // Read the file as ZStream - // Uses the blocking version of ZStream.fromFile - case Method.GET -> !! / "blocking" => Http.fromStream(ZStream.fromFile(Paths.get("README.md"))) - - // Uses netty's capability to write file content to the Channel - // Content-type response headers are automatically identified and added - // Does not use Chunked transfer encoding - case Method.GET -> !! / "video" => Http.fromFile(new File("src/main/resources/TestVideoFile.mp4")) - case Method.GET -> !! / "text" => Http.fromFile(new File("src/main/resources/TestFile.txt")) - } - - // Run it like any simple app - val run = - Server.start(8090, app.silent) -} - -``` \ No newline at end of file diff --git a/docs/website/docs/examples/zio-http-basic-examples/https-server.md b/docs/website/docs/examples/zio-http-basic-examples/https-server.md deleted file mode 100644 index e6d948031f..0000000000 --- a/docs/website/docs/examples/zio-http-basic-examples/https-server.md +++ /dev/null @@ -1,37 +0,0 @@ -# HTTPS Server -```scala -import zhttp.http._ -import zhttp.service.server.ServerChannelFactory -import zhttp.service.server.ServerSSLHandler._ -import zhttp.service.{EventLoopGroup, Server} -import zio._ - -object HttpsHelloWorld extends ZIOAppDefault { - - // Create HTTP route - val app: HttpApp[Any, Nothing] = Http.collect[Request] { - case Method.GET -> !! / "text" => Response.text("Hello World!") - case Method.GET -> !! / "json" => Response.json("""{"greetings": "Hello World!"}""") - } - - /** - * sslcontext can be created using SslContexBuilder. In this example an inbuilt API using keystore is used. For - * testing this example using curl, setup the certificate named "server.crt" from resources for the OS. Alternatively - * you can create the keystore and certificate using the following link - * https://medium.com/@maanadev/netty-with-https-tls-9bf699e07f01 - */ - val sslctx = ctxFromCert( - getClass().getClassLoader().getResourceAsStream("server.crt"), - getClass().getClassLoader().getResourceAsStream("server.key"), - ) - - private val server = - Server.port(8090) ++ Server.app(app) ++ Server.ssl( - ServerSSLOptions(sslctx, SSLHttpBehaviour.Accept), - ) - - val run = - server.make.useForever - .provideCustom(ServerChannelFactory.auto, EventLoopGroup.auto(0)) -} -``` \ No newline at end of file diff --git a/docs/website/docs/examples/zio-http-basic-examples/simple-client.md b/docs/website/docs/examples/zio-http-basic-examples/simple-client.md deleted file mode 100644 index a88adbb552..0000000000 --- a/docs/website/docs/examples/zio-http-basic-examples/simple-client.md +++ /dev/null @@ -1,23 +0,0 @@ -# Simple HTTP Client - -```scala -import zhttp.http.Headers -import zhttp.service.{ChannelFactory, Client, EventLoopGroup} -import zio._ - -object SimpleClient extends ZIOAppDefault { - val env = ChannelFactory.auto ++ EventLoopGroup.auto() - val url = "http://sports.api.decathlon.com/groups/water-aerobics" - val headers = Headers.host("sports.api.decathlon.com") - - val program = for { - res <- Client.request(url, headers) - data <- res.getBodyAsString - _ <- console.putStrLn { data } - } yield () - - override def run = - program.provideCustomLayer(env) - -} -``` \ No newline at end of file diff --git a/example/src/main/scala/example/SignCookies.scala b/example/src/main/scala/example/SignCookies.scala index 4de03d5978..49b20719cd 100644 --- a/example/src/main/scala/example/SignCookies.scala +++ b/example/src/main/scala/example/SignCookies.scala @@ -17,6 +17,5 @@ object SignCookies extends ZIOAppDefault { } // Run it like any simple app - val run = - Server.start(8090, app).exitCode + val run = Server.start(8090, app) } diff --git a/zio-http/src/main/scala/zhttp/http/Middleware.scala b/zio-http/src/main/scala/zhttp/http/Middleware.scala index 8dfb9ce7ca..7a595df4ac 100644 --- a/zio-http/src/main/scala/zhttp/http/Middleware.scala +++ b/zio-http/src/main/scala/zhttp/http/Middleware.scala @@ -1,15 +1,8 @@ package zhttp.http -import io.netty.handler.codec.http.HttpHeaderNames -import io.netty.util.AsciiString.contentEqualsIgnoreCase -import zhttp.http.CORS.DefaultCORSConfig -import zhttp.http.Headers.BasicSchemeName -import zhttp.http.Middleware.{Flag, RequestP} +import zhttp.http.middleware.Web import zio._ -import java.io.IOException -import java.util.UUID - /** * Middlewares are essentially transformations that one can apply on any Http to produce a new one. They can modify * requests and responses and also transform them into more concrete domain entities. diff --git a/zio-http/src/test/scala/zhttp/service/WebSocketServerSpec.scala b/zio-http/src/test/scala/zhttp/service/WebSocketServerSpec.scala new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/zio-http/src/test/scala/zhttp/service/WebSocketServerSpec.scala @@ -0,0 +1 @@ +