diff --git a/sbt-zio-http-grpc/src/main/scala/zio/http/grpc/ZIOHttpGRPCGen.scala b/sbt-zio-http-grpc/src/main/scala/zio/http/grpc/ZIOHttpGRPCGen.scala index 25bf62724e..050c045b74 100644 --- a/sbt-zio-http-grpc/src/main/scala/zio/http/grpc/ZIOHttpGRPCGen.scala +++ b/sbt-zio-http-grpc/src/main/scala/zio/http/grpc/ZIOHttpGRPCGen.scala @@ -5,11 +5,10 @@ import scala.jdk.CollectionConverters._ import zio.http.gen.grpc._ import zio.http.gen.scala.{Code, CodeGen} +import com.google.protobuf._ import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse -import com.google.protobuf.{Descriptors, ExtensionRegistry} import protocgen.{CodeGenApp, CodeGenRequest, CodeGenResponse} -import scalapb.compiler.{DescriptorImplicits, ProtobufGenerator} -import scalapb.options.Scalapb +import scalapb.compiler._ object ZIOHttpGRPCGen extends CodeGenApp { @@ -17,11 +16,11 @@ object ZIOHttpGRPCGen extends CodeGenApp { ProtobufGenerator.parseParameters(request.parameter) match { case Right(_) => val services = request.filesToGenerate.flatMap(fromProtobuf(_).files) - val schemas = services.map(getImplicitSchemas(_)).map { case (pkg, tpes) => + val schemas = services.map(getImplicitSchemas).map { case (pkg, tpes) => schemasFile(pkg, tpes) } CodeGenResponse.succeed( - schemas ++ services.map(fileToPluginCode(_)), + schemas ++ services.map(fileToPluginCode), Set(CodeGeneratorResponse.Feature.FEATURE_PROTO3_OPTIONAL), ) case Left(error) => @@ -55,7 +54,7 @@ object ZIOHttpGRPCGen extends CodeGenApp { val content = s"package ${pkg.mkString(".")} \nobject Schemas {\n" + "import zio.schema.{DeriveSchema, Schema}\n" + - tpes.distinct.map(tpeToSchema(_)).mkString("") + + tpes.distinct.map(tpeToSchema).mkString("") + "\n}" b.setContent(content) b.build @@ -66,39 +65,36 @@ object ZIOHttpGRPCGen extends CodeGenApp { } def fromDescriptor(file: Descriptors.FileDescriptor): Protobuf.File = { - val deps = file - .getDependencies() - .asScala - .toList + val deps = file.getDependencies.asScala.toList .map(_.getName()) - val opt = file.getOptions() - val pkg = if (opt.hasJavaPackage() && opt.getJavaPackage() != "") opt.getJavaPackage() else file.getPackage() + val opt = file.getOptions + val pkg = if (opt.hasJavaPackage && opt.getJavaPackage != "") opt.getJavaPackage else file.getPackage val pkgPath = if (pkg == "") Nil else pkg.split('.').toList val name0 = - if (opt.hasJavaOuterClassname() && opt.getJavaOuterClassname() != "") opt.getJavaOuterClassname() - else file.getName() + if (opt.hasJavaOuterClassname && opt.getJavaOuterClassname != "") opt.getJavaOuterClassname + else file.getName val name = if (name0.endsWith(".proto")) name0.dropRight(6) else name0 def fromService(service: Descriptors.ServiceDescriptor): Protobuf.Service = Protobuf.Service( - service.getName(), - service.getMethods.asScala.toList.map(fromMethod(_)), + service.getName, + service.getMethods.asScala.toList.map(fromMethod), ) def fromMethod(method: Descriptors.MethodDescriptor): Protobuf.Method = Protobuf.Method( - method.getName(), - method.getInputType().getName(), - method.getOutputType().getName(), - method.isClientStreaming(), - method.isServerStreaming(), + method.getName, + method.getInputType.getName, + method.getOutputType.getName, + method.isClientStreaming, + method.isServerStreaming, ) Protobuf.File( name, pkgPath, deps, - file.getServices().asScala.toList.map(fromService(_)), + file.getServices.asScala.toList.map(fromService), ) } diff --git a/zio-http-benchmarks/src/main/scala/zhttp.benchmarks/HttpCollectEval.scala b/zio-http-benchmarks/src/main/scala/zhttp.benchmarks/HttpCollectEval.scala index 2a4ea98119..75516fa33f 100644 --- a/zio-http-benchmarks/src/main/scala/zhttp.benchmarks/HttpCollectEval.scala +++ b/zio-http-benchmarks/src/main/scala/zhttp.benchmarks/HttpCollectEval.scala @@ -2,8 +2,6 @@ package zio.benchmarks import java.util.concurrent.TimeUnit -import zio.{Trace, Unsafe} - import zio.http._ import org.openjdk.jmh.annotations._ diff --git a/zio-http-benchmarks/src/main/scala/zhttp.benchmarks/HttpCombineEval.scala b/zio-http-benchmarks/src/main/scala/zhttp.benchmarks/HttpCombineEval.scala index 884eebca4d..50a0b71cd6 100644 --- a/zio-http-benchmarks/src/main/scala/zhttp.benchmarks/HttpCombineEval.scala +++ b/zio-http-benchmarks/src/main/scala/zhttp.benchmarks/HttpCombineEval.scala @@ -2,8 +2,6 @@ package zio.benchmarks import java.util.concurrent.TimeUnit -import zio.{Trace, Unsafe} - import zio.http._ import org.openjdk.jmh.annotations._ diff --git a/zio-http-benchmarks/src/main/scala/zhttp.benchmarks/HttpNestedFlatMapEval.scala b/zio-http-benchmarks/src/main/scala/zhttp.benchmarks/HttpNestedFlatMapEval.scala index 5188306ae1..2842b6d646 100644 --- a/zio-http-benchmarks/src/main/scala/zhttp.benchmarks/HttpNestedFlatMapEval.scala +++ b/zio-http-benchmarks/src/main/scala/zhttp.benchmarks/HttpNestedFlatMapEval.scala @@ -2,8 +2,6 @@ package zio.benchmarks import java.util.concurrent.TimeUnit -import zio.{Trace, Unsafe} - import zio.http._ import org.openjdk.jmh.annotations._ diff --git a/zio-http-cli/src/main/scala/zio/http/endpoint/cli/CliRequest.scala b/zio-http-cli/src/main/scala/zio/http/endpoint/cli/CliRequest.scala index 9859f4a139..5b169b487a 100644 --- a/zio-http-cli/src/main/scala/zio/http/endpoint/cli/CliRequest.scala +++ b/zio-http-cli/src/main/scala/zio/http/endpoint/cli/CliRequest.scala @@ -1,16 +1,6 @@ package zio.http.endpoint.cli -import java.io.{File, IOException} -import java.nio.channels.FileChannel -import java.nio.file.Path - -import scala.io.Source - import zio._ -import zio.cli._ -import zio.json.ast._ - -import zio.stream.{ZSink, ZStream} import zio.http._ @@ -28,16 +18,16 @@ private[cli] final case class CliRequest( saveResponse: Boolean = false, ) { self => - def addBody(value: Retriever) = + def addBody(value: Retriever): CliRequest = self.copy(body = self.body ++ Chunk(value)) def addHeader(name: String, value: String): CliRequest = self.copy(headers = self.headers.addHeader(name, value)) - def addPathParam(value: String) = + def addPathParam(value: String): CliRequest = self.copy(url = self.url.copy(path = self.url.path / value)) - def addQueryParam(key: String, value: String) = + def addQueryParam(key: String, value: String): CliRequest = self.copy(url = self.url.setQueryParams(self.url.queryParams.addQueryParam(key, value))) def method(method: Method): CliRequest = @@ -63,6 +53,6 @@ private[cli] final case class CliRequest( private[cli] object CliRequest { - val empty = CliRequest(Chunk.empty, Headers.empty, Method.GET, URL.empty) + val empty: CliRequest = CliRequest(Chunk.empty, Headers.empty, Method.GET, URL.empty) } diff --git a/zio-http-cli/src/test/scala/zio/http/endpoint/cli/CliSpec.scala b/zio-http-cli/src/test/scala/zio/http/endpoint/cli/CliSpec.scala index 2a3418ff94..5153f1ab47 100644 --- a/zio-http-cli/src/test/scala/zio/http/endpoint/cli/CliSpec.scala +++ b/zio-http-cli/src/test/scala/zio/http/endpoint/cli/CliSpec.scala @@ -61,7 +61,7 @@ object CliSpec extends ZIOSpecDefault { for { text <- body.asMultipartForm .map(_.formData) - .map(_.map(_.stringValue.toString())) + .map(_.map(_.stringValue.toString)) .map(_.toString()) .mapError(e => Response.error(Status.BadRequest, e.getMessage)) } yield if (text == "Chunk(Some(342.76))") Response.text("received 1") else Response.text(text) diff --git a/zio-http-cli/src/test/scala/zio/http/endpoint/cli/CommandGen.scala b/zio-http-cli/src/test/scala/zio/http/endpoint/cli/CommandGen.scala index ec56387704..ad99897218 100644 --- a/zio-http-cli/src/test/scala/zio/http/endpoint/cli/CommandGen.scala +++ b/zio-http-cli/src/test/scala/zio/http/endpoint/cli/CommandGen.scala @@ -20,15 +20,15 @@ object CommandGen { def getSegment(segment: SegmentCodec[_]): (String, String) = { def fromSegment[A](segment: SegmentCodec[A]): (String, String) = segment match { - case SegmentCodec.UUID(name) => (name, "text") - case SegmentCodec.Text(name) => (name, "text") - case SegmentCodec.IntSeg(name) => (name, "integer") - case SegmentCodec.LongSeg(name) => (name, "integer") - case SegmentCodec.BoolSeg(name) => (name, "boolean") - case SegmentCodec.Literal(_) => ("", "") - case SegmentCodec.Trailing => ("", "") - case SegmentCodec.Empty => ("", "") - case SegmentCodec.Combined(left, right, combiner) => + case SegmentCodec.UUID(name) => (name, "text") + case SegmentCodec.Text(name) => (name, "text") + case SegmentCodec.IntSeg(name) => (name, "integer") + case SegmentCodec.LongSeg(name) => (name, "integer") + case SegmentCodec.BoolSeg(name) => (name, "boolean") + case SegmentCodec.Literal(_) => ("", "") + case SegmentCodec.Trailing => ("", "") + case SegmentCodec.Empty => ("", "") + case SegmentCodec.Combined(_, _, _) => ??? } @@ -37,7 +37,7 @@ object CommandGen { lazy val anyEndpoint: Gen[Any, HelpRepr[Endpoint[_, _, _, _, _]]] = anyCodec - .map(_.map2(getCommand(_))) + .map(_.map2(getCommand)) .map(_.map(fromInputCodec(Doc.empty, _))) def getCommand(cliEndpoint: CliEndpoint): HelpDoc = { diff --git a/zio-http-cli/src/test/scala/zio/http/endpoint/cli/EndpointGen.scala b/zio-http-cli/src/test/scala/zio/http/endpoint/cli/EndpointGen.scala index c25e128e34..d868a86cca 100644 --- a/zio-http-cli/src/test/scala/zio/http/endpoint/cli/EndpointGen.scala +++ b/zio-http-cli/src/test/scala/zio/http/endpoint/cli/EndpointGen.scala @@ -7,7 +7,6 @@ import zio.schema.Schema import zio.http._ import zio.http.codec._ -import zio.http.codec.internal.TextBinaryCodec import zio.http.endpoint._ import zio.http.endpoint.cli.AuxGen._ import zio.http.endpoint.cli.CliRepr.CliReprOf diff --git a/zio-http-cli/src/test/scala/zio/http/endpoint/cli/OptionsGen.scala b/zio-http-cli/src/test/scala/zio/http/endpoint/cli/OptionsGen.scala index 01bf2a1bb5..58fe22aa85 100644 --- a/zio-http-cli/src/test/scala/zio/http/endpoint/cli/OptionsGen.scala +++ b/zio-http-cli/src/test/scala/zio/http/endpoint/cli/OptionsGen.scala @@ -8,7 +8,6 @@ import zio.schema.Schema import zio.http._ import zio.http.codec._ -import zio.http.codec.internal.TextBinaryCodec import zio.http.endpoint.cli.AuxGen._ import zio.http.endpoint.cli.CliRepr._ diff --git a/zio-http-example/src/main/scala/example/CombinerTypesExample.scala b/zio-http-example/src/main/scala/example/CombinerTypesExample.scala index 0c85ea1b61..540c9a0840 100644 --- a/zio-http-example/src/main/scala/example/CombinerTypesExample.scala +++ b/zio-http-example/src/main/scala/example/CombinerTypesExample.scala @@ -1,6 +1,5 @@ package example -import zio.http.codec.HttpCodec._ import zio.http.codec._ object CombinerTypesExample extends App { diff --git a/zio-http-example/src/main/scala/example/EndpointExamples.scala b/zio-http-example/src/main/scala/example/EndpointExamples.scala index a99176a5e3..01f5bedcd3 100644 --- a/zio-http-example/src/main/scala/example/EndpointExamples.scala +++ b/zio-http-example/src/main/scala/example/EndpointExamples.scala @@ -2,7 +2,6 @@ package example import zio._ -import zio.http.Header.Authorization import zio.http._ import zio.http.codec.PathCodec.path import zio.http.codec._ diff --git a/zio-http-example/src/main/scala/example/ServerSentEventAsJsonEndpoint.scala b/zio-http-example/src/main/scala/example/ServerSentEventAsJsonEndpoint.scala index e60f838fa2..e57b7208ae 100644 --- a/zio-http-example/src/main/scala/example/ServerSentEventAsJsonEndpoint.scala +++ b/zio-http-example/src/main/scala/example/ServerSentEventAsJsonEndpoint.scala @@ -9,7 +9,7 @@ import zio.stream.ZStream import zio.schema.{DeriveSchema, Schema} import zio.http._ -import zio.http.codec.{CodecConfig, HttpCodec} +import zio.http.codec._ import zio.http.endpoint._ object ServerSentEventAsJsonEndpoint extends ZIOAppDefault { diff --git a/zio-http-example/src/main/scala/example/ServerSentEventEndpoint.scala b/zio-http-example/src/main/scala/example/ServerSentEventEndpoint.scala index 2fac1efd33..75b731117c 100644 --- a/zio-http-example/src/main/scala/example/ServerSentEventEndpoint.scala +++ b/zio-http-example/src/main/scala/example/ServerSentEventEndpoint.scala @@ -8,7 +8,7 @@ import zio._ import zio.stream.ZStream import zio.http._ -import zio.http.codec.{CodecConfig, HttpCodec} +import zio.http.codec._ import zio.http.endpoint._ object ServerSentEventEndpoint extends ZIOAppDefault { diff --git a/zio-http-example/src/main/scala/example/endpoint/EndpointWithMultipleErrorsUsingEither.scala b/zio-http-example/src/main/scala/example/endpoint/EndpointWithMultipleErrorsUsingEither.scala index b91bd6e96a..a8de92fa40 100644 --- a/zio-http-example/src/main/scala/example/endpoint/EndpointWithMultipleErrorsUsingEither.scala +++ b/zio-http-example/src/main/scala/example/endpoint/EndpointWithMultipleErrorsUsingEither.scala @@ -5,7 +5,7 @@ import zio._ import zio.schema.{DeriveSchema, Schema} import zio.http._ -import zio.http.codec.{CodecConfig, HeaderCodec, PathCodec} +import zio.http.codec._ import zio.http.endpoint.{AuthType, Endpoint} object EndpointWithMultipleErrorsUsingEither extends ZIOAppDefault { diff --git a/zio-http-example/src/main/scala/example/endpoint/EndpointWithMultipleUnifiedErrors.scala b/zio-http-example/src/main/scala/example/endpoint/EndpointWithMultipleUnifiedErrors.scala index de49dd9c8f..fa15fbb218 100644 --- a/zio-http-example/src/main/scala/example/endpoint/EndpointWithMultipleUnifiedErrors.scala +++ b/zio-http-example/src/main/scala/example/endpoint/EndpointWithMultipleUnifiedErrors.scala @@ -7,7 +7,7 @@ import zio._ import zio.schema.{DeriveSchema, Schema} import zio.http._ -import zio.http.codec.{CodecConfig, HeaderCodec, HttpCodec, PathCodec} +import zio.http.codec._ import zio.http.endpoint.{AuthType, Endpoint} object EndpointWithMultipleUnifiedErrors extends ZIOAppDefault { diff --git a/zio-http-testkit/src/main/scala/zio/http/TestChannel.scala b/zio-http-testkit/src/main/scala/zio/http/TestChannel.scala index 4f5a6c1e02..f73445e807 100644 --- a/zio-http-testkit/src/main/scala/zio/http/TestChannel.scala +++ b/zio-http-testkit/src/main/scala/zio/http/TestChannel.scala @@ -3,7 +3,7 @@ package zio.http import zio._ import zio.stacktracer.TracingImplicits.disableAutoTrace -import zio.http.ChannelEvent.{Unregistered, UserEvent, UserEventTriggered} +import zio.http.ChannelEvent._ case class TestChannel( in: Queue[WebSocketChannelEvent], diff --git a/zio-http/js/src/main/scala/zio/http/URLPlatformSpecific.scala b/zio-http/js/src/main/scala/zio/http/URLPlatformSpecific.scala index 42c5fcc1f2..a8df7973a5 100644 --- a/zio-http/js/src/main/scala/zio/http/URLPlatformSpecific.scala +++ b/zio-http/js/src/main/scala/zio/http/URLPlatformSpecific.scala @@ -1,7 +1,5 @@ package zio.http -import scala.util.Try - trait URLPlatformSpecific { self: URL => } diff --git a/zio-http/jvm/src/main/scala/zio/http/internal/BodyEncodingPlatformSpecific.scala b/zio-http/jvm/src/main/scala/zio/http/internal/BodyEncodingPlatformSpecific.scala index 6fa7bd2628..a32ca2c007 100644 --- a/zio-http/jvm/src/main/scala/zio/http/internal/BodyEncodingPlatformSpecific.scala +++ b/zio-http/jvm/src/main/scala/zio/http/internal/BodyEncodingPlatformSpecific.scala @@ -18,6 +18,6 @@ package zio.http.internal import zio.http.netty.NettyBody -trait BodyEncodingPlatformSpecific { +private[http] trait BodyEncodingPlatformSpecific { val default: BodyEncoding = NettyBody } diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/AsyncBodyReader.scala b/zio-http/jvm/src/main/scala/zio/http/netty/AsyncBodyReader.scala index e1a4a3aeec..290c555c81 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/AsyncBodyReader.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/AsyncBodyReader.scala @@ -29,7 +29,7 @@ import io.netty.buffer.ByteBufUtil import io.netty.channel.{ChannelHandlerContext, SimpleChannelInboundHandler} import io.netty.handler.codec.http.{HttpContent, LastHttpContent} -abstract class AsyncBodyReader extends SimpleChannelInboundHandler[HttpContent](true) { +private[netty] abstract class AsyncBodyReader extends SimpleChannelInboundHandler[HttpContent](true) { import zio.http.netty.AsyncBodyReader._ private var state: State = State.Buffering @@ -138,7 +138,7 @@ abstract class AsyncBodyReader extends SimpleChannelInboundHandler[HttpContent]( } } -object AsyncBodyReader { +private[netty] object AsyncBodyReader { sealed trait State diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/CachedDateHeader.scala b/zio-http/jvm/src/main/scala/zio/http/netty/CachedDateHeader.scala index 63171b2397..fe6749e5a3 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/CachedDateHeader.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/CachedDateHeader.scala @@ -9,7 +9,7 @@ private object CachedDateHeader { lazy val default: CachedDateHeader = new CachedDateHeader() } -final private class CachedDateHeader( +private final class CachedDateHeader( clock: Clock = Clock.tickSeconds(ZoneOffset.UTC), dateEncoding: DateEncoding = DateEncoding.default, ) { diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/ChannelFactories.scala b/zio-http/jvm/src/main/scala/zio/http/netty/ChannelFactories.scala index 6616c9d2c9..bed87a955b 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/ChannelFactories.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/ChannelFactories.scala @@ -25,7 +25,7 @@ import io.netty.channel.epoll._ import io.netty.channel.kqueue._ import io.netty.channel.socket.nio._ import io.netty.incubator.channel.uring._ -object ChannelFactories { +private[netty] object ChannelFactories { private[zio] def make[A <: Channel](channel: => A)(implicit trace: Trace): UIO[ChannelFactory[A]] = ZIO.succeed(new ChannelFactory[A] { diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/EventLoopGroups.scala b/zio-http/jvm/src/main/scala/zio/http/netty/EventLoopGroups.scala index 9904cd3c09..19a4615c5f 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/EventLoopGroups.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/EventLoopGroups.scala @@ -16,7 +16,6 @@ package zio.http.netty -import java.time.temporal.TemporalUnit import java.util.concurrent.Executor import scala.concurrent.duration.TimeUnit diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/HybridContentLengthHandler.scala b/zio-http/jvm/src/main/scala/zio/http/netty/HybridContentLengthHandler.scala index 2cc27f96cd..2b55b70d40 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/HybridContentLengthHandler.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/HybridContentLengthHandler.scala @@ -5,7 +5,7 @@ import io.netty.handler.codec.http.HttpUtil.getContentLength import io.netty.handler.codec.http._ import io.netty.handler.stream.ChunkedWriteHandler -class HybridContentLengthHandler(maxAggregatedLength: Int) extends ChannelInboundHandlerAdapter { +private[netty] class HybridContentLengthHandler(maxAggregatedLength: Int) extends ChannelInboundHandlerAdapter { var maxLength = maxAggregatedLength override def channelRead(ctx: ChannelHandlerContext, msg: Any): Unit = { msg match { diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/NettyBody.scala b/zio-http/jvm/src/main/scala/zio/http/netty/NettyBody.scala index 9792f08b6e..c5ba490efa 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/NettyBody.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/NettyBody.scala @@ -79,7 +79,7 @@ object NettyBody extends BodyEncoding { override def asStream(implicit trace: Trace): ZStream[Any, Throwable, Byte] = ZStream.unwrap(asChunk.map(ZStream.fromChunk(_))) - override def toString(): String = s"Body.fromAsciiString($asciiString)" + override def toString: String = s"Body.fromAsciiString($asciiString)" private[zio] override def unsafeAsArray(implicit unsafe: Unsafe): Array[Byte] = asciiString.array() @@ -131,7 +131,7 @@ object NettyBody extends BodyEncoding { override def isEmpty: Boolean = false - override def toString(): String = s"AsyncBody($unsafeAsync)" + override def toString: String = s"AsyncBody($unsafeAsync)" override def contentType(newContentType: Body.ContentType): Body = copy(contentType = Some(newContentType)) } diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/NettyBodyWriter.scala b/zio-http/jvm/src/main/scala/zio/http/netty/NettyBodyWriter.scala index 8c36f13623..667d2c58fb 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/NettyBodyWriter.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/NettyBodyWriter.scala @@ -32,7 +32,7 @@ import io.netty.buffer.Unpooled import io.netty.channel._ import io.netty.handler.codec.http.{DefaultHttpContent, LastHttpContent} -object NettyBodyWriter { +private[netty] object NettyBodyWriter { @tailrec def writeAndFlush( diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/NettyChannel.scala b/zio-http/jvm/src/main/scala/zio/http/netty/NettyChannel.scala index f077df8c64..d18041d14f 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/NettyChannel.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/NettyChannel.scala @@ -16,12 +16,12 @@ package zio.http.netty +import zio._ import zio.stacktracer.TracingImplicits.disableAutoTrace -import zio.{Task, Trace, UIO, ZIO} import io.netty.channel.{Channel => JChannel, ChannelFuture => JChannelFuture} -final case class NettyChannel[-A]( +private[netty] final case class NettyChannel[-A]( private val channel: JChannel, private val convert: A => Any, ) { @@ -67,6 +67,6 @@ final case class NettyChannel[-A]( } } -object NettyChannel { +private[netty] object NettyChannel { def make[A](channel: JChannel): NettyChannel[A] = NettyChannel(channel, identity) } diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/NettyProxy.scala b/zio-http/jvm/src/main/scala/zio/http/netty/NettyProxy.scala index c253182fbf..bfc1a45815 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/NettyProxy.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/NettyProxy.scala @@ -23,7 +23,7 @@ import zio.http.{Credentials, Proxy} import io.netty.handler.proxy.HttpProxyHandler -class NettyProxy private (proxy: Proxy) { +private[netty] class NettyProxy private (proxy: Proxy) { /** * Converts a Proxy to [io.netty.handler.proxy.HttpProxyHandler] diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/NettyResponse.scala b/zio-http/jvm/src/main/scala/zio/http/netty/NettyResponse.scala index 8ac8ae2184..ee6e0677e6 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/NettyResponse.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/NettyResponse.scala @@ -16,19 +16,18 @@ package zio.http.netty +import zio._ import zio.stacktracer.TracingImplicits.disableAutoTrace -import zio.{Exit, Promise, Trace, Unsafe, ZIO} import zio.http.internal.ChannelState import zio.http.netty.client.ClientResponseStreamHandler import zio.http.netty.model.Conversions import zio.http.{Body, Header, Response} -import io.netty.buffer.{ByteBufUtil, Unpooled} import io.netty.channel.ChannelHandlerContext import io.netty.handler.codec.http.{FullHttpResponse, HttpResponse} -object NettyResponse { +private[netty] object NettyResponse { def apply(jRes: FullHttpResponse)(implicit unsafe: Unsafe): Response = { val status = Conversions.statusFromNetty(jRes.status()) diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/client/ClientFailureHandler.scala b/zio-http/jvm/src/main/scala/zio/http/netty/client/ClientFailureHandler.scala index b11a0cdf55..14cdeb8488 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/client/ClientFailureHandler.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/client/ClientFailureHandler.scala @@ -8,7 +8,7 @@ import zio.http.internal.ChannelState import io.netty.channel.{ChannelHandlerContext, ChannelInboundHandlerAdapter} /** Handles failures happening in ClientInboundHandler */ -final class ClientFailureHandler( +private[netty] final class ClientFailureHandler( onResponse: Promise[Throwable, Response], onComplete: Promise[Throwable, ChannelState], ) extends ChannelInboundHandlerAdapter { diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/client/ClientInboundHandler.scala b/zio-http/jvm/src/main/scala/zio/http/netty/client/ClientInboundHandler.scala index abb8335421..1ca7994d45 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/client/ClientInboundHandler.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/client/ClientInboundHandler.scala @@ -29,7 +29,7 @@ import io.netty.handler.codec.http._ /** * Handles HTTP response */ -final class ClientInboundHandler( +private[netty] final class ClientInboundHandler( rtm: NettyRuntime, req: Request, jReq: HttpRequest, diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/client/ClientResponseStreamHandler.scala b/zio-http/jvm/src/main/scala/zio/http/netty/client/ClientResponseStreamHandler.scala index 28e704771e..b9cebb5b66 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/client/ClientResponseStreamHandler.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/client/ClientResponseStreamHandler.scala @@ -16,8 +16,8 @@ package zio.http.netty.client +import zio._ import zio.stacktracer.TracingImplicits.disableAutoTrace -import zio.{Exit, Promise, Trace, Unsafe} import zio.http.Status import zio.http.internal.ChannelState @@ -26,7 +26,7 @@ import zio.http.netty.AsyncBodyReader import io.netty.channel._ import io.netty.handler.codec.http.{HttpContent, LastHttpContent} -final class ClientResponseStreamHandler( +private[netty] final class ClientResponseStreamHandler( onComplete: Promise[Throwable, ChannelState], keepAlive: Boolean, status: Status, diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/client/ClientSSLConverter.scala b/zio-http/jvm/src/main/scala/zio/http/netty/client/ClientSSLConverter.scala index f288fad375..6df29da1db 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/client/ClientSSLConverter.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/client/ClientSSLConverter.scala @@ -30,7 +30,7 @@ import zio.http.ClientSSLConfig import io.netty.handler.ssl.util.InsecureTrustManagerFactory import io.netty.handler.ssl.{SslContext, SslContextBuilder} -object ClientSSLConverter { +private[netty] object ClientSSLConverter { private def trustStoreToSslContext( trustStoreStream: InputStream, trustStorePassword: Secret, diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/client/NettyConnectionPool.scala b/zio-http/jvm/src/main/scala/zio/http/netty/client/NettyConnectionPool.scala index 97e20e393f..147f38bac6 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/client/NettyConnectionPool.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/client/NettyConnectionPool.scala @@ -32,9 +32,9 @@ import io.netty.handler.codec.http.{HttpClientCodec, HttpContentDecompressor} import io.netty.handler.proxy.HttpProxyHandler import io.netty.handler.timeout.{ReadTimeoutException, ReadTimeoutHandler} -trait NettyConnectionPool extends ConnectionPool[JChannel] +private[netty] trait NettyConnectionPool extends ConnectionPool[JChannel] -object NettyConnectionPool { +private[netty] object NettyConnectionPool { protected def createChannel( channelFactory: JChannelFactory[JChannel], diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/client/WebSocketClientInboundHandler.scala b/zio-http/jvm/src/main/scala/zio/http/netty/client/WebSocketClientInboundHandler.scala index 29740447e1..e58e21397d 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/client/WebSocketClientInboundHandler.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/client/WebSocketClientInboundHandler.scala @@ -26,7 +26,7 @@ import zio.http.netty.NettyResponse import io.netty.channel.{ChannelHandlerContext, SimpleChannelInboundHandler} import io.netty.handler.codec.http.FullHttpResponse -final class WebSocketClientInboundHandler( +private[netty] final class WebSocketClientInboundHandler( onResponse: Promise[Throwable, Response], onComplete: Promise[Throwable, ChannelState], ) extends SimpleChannelInboundHandler[FullHttpResponse](true) { diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/server/NettyResponseEncoder.scala b/zio-http/jvm/src/main/scala/zio/http/netty/server/NettyResponseEncoder.scala index cb6470068f..eb1be2b41b 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/server/NettyResponseEncoder.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/server/NettyResponseEncoder.scala @@ -26,7 +26,7 @@ import zio.http.netty.model.Conversions import io.netty.buffer.Unpooled import io.netty.handler.codec.http._ -private object NettyResponseEncoder { +private[netty] object NettyResponseEncoder { private val dateHeaderCache = CachedDateHeader.default def encode(method: Method, response: Response)(implicit unsafe: Unsafe): HttpResponse = diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/server/ServerChannelInitializer.scala b/zio-http/jvm/src/main/scala/zio/http/netty/server/ServerChannelInitializer.scala index c5658f7233..50c3a1f41f 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/server/ServerChannelInitializer.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/server/ServerChannelInitializer.scala @@ -28,7 +28,7 @@ import zio.http.netty.{HybridContentLengthHandler, Names} import io.netty.channel.ChannelHandler.Sharable import io.netty.channel._ -import io.netty.handler.codec.http.HttpObjectDecoder.{DEFAULT_MAX_CHUNK_SIZE, DEFAULT_MAX_INITIAL_LINE_LENGTH} +import io.netty.handler.codec.http.HttpObjectDecoder.DEFAULT_MAX_CHUNK_SIZE import io.netty.handler.codec.http._ import io.netty.handler.flush.FlushConsolidationHandler import io.netty.handler.timeout.ReadTimeoutHandler diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/server/ServerHttpsHandler.scala b/zio-http/jvm/src/main/scala/zio/http/netty/server/ServerHttpsHandler.scala index ac2b80f506..164a6e3dc9 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/server/ServerHttpsHandler.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/server/ServerHttpsHandler.scala @@ -25,7 +25,6 @@ import io.netty.handler.codec.http.{DefaultHttpResponse, HttpMessage, HttpRespon private[zio] class ServerHttpsHandler(httpBehaviour: HttpBehaviour) extends SimpleChannelInboundHandler[HttpMessage] { override def channelRead0(ctx: ChannelHandlerContext, msg: HttpMessage): Unit = { - // TODO: PatMat maybe??? if (msg.isInstanceOf[HttpMessage]) { if (httpBehaviour == HttpBehaviour.Redirect) { val message = msg.asInstanceOf[HttpMessage] diff --git a/zio-http/jvm/src/main/scala/zio/http/netty/server/ServerSSLDecoder.scala b/zio-http/jvm/src/main/scala/zio/http/netty/server/ServerSSLDecoder.scala index 52ff4b1530..53c3dfb3fb 100644 --- a/zio-http/jvm/src/main/scala/zio/http/netty/server/ServerSSLDecoder.scala +++ b/zio-http/jvm/src/main/scala/zio/http/netty/server/ServerSSLDecoder.scala @@ -36,7 +36,7 @@ import io.netty.handler.ssl.ApplicationProtocolConfig.{ import io.netty.handler.ssl._ import io.netty.handler.ssl.util.SelfSignedCertificate import io.netty.handler.ssl.{ClientAuth => NettyClientAuth} -object SSLUtil { +private[netty] object SSLUtil { def getClientAuth(clientAuth: ClientAuth): NettyClientAuth = clientAuth match { case ClientAuth.Required => NettyClientAuth.REQUIRE diff --git a/zio-http/jvm/src/test/scala/zio/http/security/MetricsSpec.scala b/zio-http/jvm/src/test/scala/zio/http/security/MetricsSpec.scala index 5f8e285beb..e5c035da48 100644 --- a/zio-http/jvm/src/test/scala/zio/http/security/MetricsSpec.scala +++ b/zio-http/jvm/src/test/scala/zio/http/security/MetricsSpec.scala @@ -22,7 +22,6 @@ object MetricsSpec extends ZIOHttpSpec { Chunk(TestAspect.timeout(120.seconds), TestAspect.timed) def testMetrics[A](name: String, maxReq: Int, init: A, inc: A => A, mkRequest0: Int => A => Request) = { - val reqDelay = 100.millis val routes = Routes( Method.GET / PathCodec.trailing -> Handler.ok, @@ -30,12 +29,6 @@ object MetricsSpec extends ZIOHttpSpec { extraLabels = Set(MetricLabel("test", name)), ) - val gauge = Metric - .gauge("http_concurrent_requests_total") - .tagged("test", name) - .tagged("path", "/...") - .tagged("method", "GET") - .tagged("status", "200") val histogram = Metric .histogram( "http_request_duration_seconds", @@ -51,7 +44,6 @@ object MetricsSpec extends ZIOHttpSpec { test(name) { for { - ref <- Ref.make[List[Double]](List.empty) port <- Server.install(routes) mkRequest = mkRequest0(port) _ <- ZIO.iterate((0, init))(_._1 < maxReq) { case (n, content) => diff --git a/zio-http/jvm/src/test/scala/zio/http/security/SizeLimitsSpec.scala b/zio-http/jvm/src/test/scala/zio/http/security/SizeLimitsSpec.scala index 86e5080b70..2926182a08 100644 --- a/zio-http/jvm/src/test/scala/zio/http/security/SizeLimitsSpec.scala +++ b/zio-http/jvm/src/test/scala/zio/http/security/SizeLimitsSpec.scala @@ -90,7 +90,7 @@ object SizeLimitsSpec extends ZIOHttpSpec { } def testLimit(size: Int, maxSize: Int, lstTestSize: Int, mkRequest0: Int => String => Request, badStatus: Status) = - testLimit0[String](maxSize, lstTestSize, "A" * size, n => (_ ++ "A"), mkRequest0, badStatus) + testLimit0[String](maxSize, lstTestSize, "A" * size, _ => _ ++ "A", mkRequest0, badStatus) val spec: Spec[TestEnvironment with Scope, Any] = suite("SizeLimitsSpec")( suite("limits are configurable")( test("infinite segment url") { diff --git a/zio-http/jvm/src/test/scala/zio/http/security/StaticFileServingSpec.scala b/zio-http/jvm/src/test/scala/zio/http/security/StaticFileServingSpec.scala index 3c25d6f0ab..5133f6a5d9 100644 --- a/zio-http/jvm/src/test/scala/zio/http/security/StaticFileServingSpec.scala +++ b/zio-http/jvm/src/test/scala/zio/http/security/StaticFileServingSpec.scala @@ -24,9 +24,6 @@ object StaticFileServingSpec extends ZIOSpecDefault { val symlinkContent = Files.createFile(symlinks.resolve("symlinkContent")) Files.write(symlinkContent, "something".getBytes()) - val secrets = Files.createDirectory(root.resolve("secrets")) - val secret = Files.createFile(secrets.resolve("secret")) - val local = Files.createDirectory(root.resolve("local")) val dir = Files.createDirectory(local.resolve("dir")) val file = Files.createFile(dir.resolve("file")) @@ -94,7 +91,7 @@ object StaticFileServingSpec extends ZIOSpecDefault { def spec = suite("StaticFileServingSpec")( test("Middleware.serveDirectory can't escape sandbox") { - ZIO.acquireRelease(mkDir)(deleteDir).flatMap { case tempDir => + ZIO.acquireRelease(mkDir)(deleteDir).flatMap { tempDir => val routes = serveDirectory(tempDir.resolve("local/dir")) check(serveDirectoryPaths) { case (path, expectedStatus) => for { @@ -108,7 +105,7 @@ object StaticFileServingSpec extends ZIOSpecDefault { } }, test("Middleware.serveResources can't escape sandbox") { - ZIO.acquireRelease(mkDir)(deleteDir).flatMap { case _ => + ZIO.acquireRelease(mkDir)(deleteDir).flatMap { _ => val routes = serveResources check(serveResourcesPaths) { case (path, expectedStatus) => for { diff --git a/zio-http/jvm/src/test/scala/zio/http/security/TimingAttacksSpec.scala b/zio-http/jvm/src/test/scala/zio/http/security/TimingAttacksSpec.scala index 202a6f147e..f4466f69c6 100644 --- a/zio-http/jvm/src/test/scala/zio/http/security/TimingAttacksSpec.scala +++ b/zio-http/jvm/src/test/scala/zio/http/security/TimingAttacksSpec.scala @@ -29,7 +29,7 @@ object TimingAttacksSpec extends ZIOSpecDefault { } // after a few iterations, boxTest doesn't detect differences accurately when dealing with `Handlers` - def boxTest[A]( + def boxTest( h: () => Handler[Any, Nothing, Request, Response], slow: Request, fast: Request, @@ -41,9 +41,9 @@ object TimingAttacksSpec extends ZIOSpecDefault { !(diff > statisticsB._2 / 20) } - def statistics[A](h: () => Handler[Any, Nothing, Request, Response], slow: Request): (Long, Long) = { + def statistics(h: () => Handler[Any, Nothing, Request, Response], slow: Request): (Long, Long) = { var sampleUnsorted = List.empty[Long] - for (i <- 0 until nOfTries) { + for (_ <- 0 until nOfTries) { val b = java.lang.System.nanoTime runZ { h().runZIO(slow) } val a = java.lang.System.nanoTime diff --git a/zio-http/jvm/src/test/scala/zio/http/security/UserDataSpec.scala b/zio-http/jvm/src/test/scala/zio/http/security/UserDataSpec.scala index 4be1dcffc7..1322d7e68a 100644 --- a/zio-http/jvm/src/test/scala/zio/http/security/UserDataSpec.scala +++ b/zio-http/jvm/src/test/scala/zio/http/security/UserDataSpec.scala @@ -41,7 +41,7 @@ object UserDataSpec extends ZIOSpecDefault { val spec = suite("UserDataSpec")( test("No sanitation and write to server") { // this is not a bug but could be a vulnerability used wrong - check(tuples.zip(functions)) { case (mediaType, msg, expectedResponse, f) => + check(tuples.zip(functions)) { case (_, msg, expectedResponse, _) => val endpoint = Endpoint(Method.GET / "test") .query(HttpCodec.query[String]("data")) .out[String] @@ -59,7 +59,7 @@ object UserDataSpec extends ZIOSpecDefault { } @@ TestAspect.failing, test("No sanitation using Dom") { // this is not a bug but could be a vulnerability used wrong - check(tuples.zip(functions)) { case (mediaType, msg, expectedResponse, f) => + check(tuples.zip(functions)) { case (_, msg, expectedResponse, _) => val endpoint = Endpoint(Method.GET / "test") .in[Dom] .out[Dom] @@ -89,11 +89,11 @@ object UserDataSpec extends ZIOSpecDefault { } }, test("Header injection DOM") { - check(tuples.zip(functions)) { case (mediaType, msg, expectedResponse, f) => + check(tuples.zip(functions)) { case (mediaType, msg, expectedResponse, _) => val endpoint = Endpoint(Method.GET / "test") .query(HttpCodec.query[Dom]("data")) .out[Dom] - val route = endpoint.implementHandler(Handler.fromFunction { case s => s }) + val route = endpoint.implementHandler(Handler.fromFunction(s => s)) val request = Request .get(URL(Path.root / "test", queryParams = QueryParams(("data", msg)))) @@ -136,7 +136,7 @@ object UserDataSpec extends ZIOSpecDefault { } }, test("Error injection") { - check(tuples.zip(functions)) { case (mediaType, msg, expectedResponse, f) => + check(tuples.zip(functions)) { case (mediaType, msg, expectedResponse, _) => val routes = Routes(Method.POST / "test" -> handler { (req: Request) => req.body.asString.orDie.map(msg => Response.error(Status.InternalServerError, msg)) }) diff --git a/zio-http/shared/src/main/scala/zio/http/Body.scala b/zio-http/shared/src/main/scala/zio/http/Body.scala index 365b47fcdf..a72fdce456 100644 --- a/zio-http/shared/src/main/scala/zio/http/Body.scala +++ b/zio-http/shared/src/main/scala/zio/http/Body.scala @@ -466,7 +466,7 @@ object Body { override def isEmpty: Boolean = true - override def toString(): String = "Body.empty" + override def toString: String = "Body.empty" override private[zio] def unsafeAsArray(implicit unsafe: Unsafe): Array[Byte] = Array.empty[Byte] @@ -513,7 +513,7 @@ object Body { override def asStream(implicit trace: Trace): ZStream[Any, Throwable, Byte] = ZStream.unwrap(asChunk.map(ZStream.fromChunk(_))) - override def toString(): String = s"Body.fromChunk($data)" + override def toString: String = s"Body.fromChunk($data)" override private[zio] def unsafeAsArray(implicit unsafe: Unsafe): Array[Byte] = data.toArray @@ -538,7 +538,7 @@ object Body { override def asStream(implicit trace: Trace): ZStream[Any, Throwable, Byte] = ZStream.unwrap(asChunk.map(ZStream.fromChunk(_))) - override def toString(): String = s"Body.fromArray($data)" + override def toString: String = s"Body.fromArray($data)" override private[zio] def unsafeAsArray(implicit unsafe: Unsafe): Array[Byte] = data diff --git a/zio-http/shared/src/main/scala/zio/http/Cookie.scala b/zio-http/shared/src/main/scala/zio/http/Cookie.scala index ce336faaa2..ba1814b0a4 100644 --- a/zio-http/shared/src/main/scala/zio/http/Cookie.scala +++ b/zio-http/shared/src/main/scala/zio/http/Cookie.scala @@ -23,9 +23,8 @@ import javax.crypto.spec.SecretKeySpec import scala.collection.mutable -import zio.{Chunk, Duration} +import zio._ -import zio.http._ import zio.http.internal.CookieEncoding /** diff --git a/zio-http/shared/src/main/scala/zio/http/HandlerAspect.scala b/zio-http/shared/src/main/scala/zio/http/HandlerAspect.scala index 7f57f8908e..7f28352559 100644 --- a/zio-http/shared/src/main/scala/zio/http/HandlerAspect.scala +++ b/zio-http/shared/src/main/scala/zio/http/HandlerAspect.scala @@ -21,8 +21,6 @@ import java.nio.charset._ import zio._ import zio.metrics._ -import zio.http.template._ - /** * A [[zio.http.HandlerAspect]] is a kind of [[zio.http.ProtocolStack]] that is * specialized to transform a handler's incoming requests and outgoing diff --git a/zio-http/shared/src/main/scala/zio/http/Header.scala b/zio-http/shared/src/main/scala/zio/http/Header.scala index c913dae707..fca8e9d09f 100644 --- a/zio-http/shared/src/main/scala/zio/http/Header.scala +++ b/zio-http/shared/src/main/scala/zio/http/Header.scala @@ -124,7 +124,7 @@ object Header { } } - override def toString(): String = (customName, value).toString() + override def toString: String = (customName, value).toString() } final case class Accept(mimeTypes: NonEmptyChunk[Accept.MediaTypeWithQFactor]) extends Header { diff --git a/zio-http/shared/src/main/scala/zio/http/MediaType.scala b/zio-http/shared/src/main/scala/zio/http/MediaType.scala index 014742613e..8a38bf9ac0 100644 --- a/zio-http/shared/src/main/scala/zio/http/MediaType.scala +++ b/zio-http/shared/src/main/scala/zio/http/MediaType.scala @@ -16,8 +16,6 @@ package zio.http -import scala.annotation.tailrec - final case class MediaType( mainType: String, subType: String, diff --git a/zio-http/shared/src/main/scala/zio/http/Request.scala b/zio-http/shared/src/main/scala/zio/http/Request.scala index 6f230bfad4..333879e3c1 100644 --- a/zio-http/shared/src/main/scala/zio/http/Request.scala +++ b/zio-http/shared/src/main/scala/zio/http/Request.scala @@ -21,7 +21,6 @@ import java.security.cert.Certificate import zio._ -import zio.http.codec.TextCodec import zio.http.internal.{HeaderOps, QueryOps} final case class Request( diff --git a/zio-http/shared/src/main/scala/zio/http/Route.scala b/zio-http/shared/src/main/scala/zio/http/Route.scala index 768a0d10b9..69254f602d 100644 --- a/zio-http/shared/src/main/scala/zio/http/Route.scala +++ b/zio-http/shared/src/main/scala/zio/http/Route.scala @@ -438,7 +438,7 @@ object Route { override def toHandler(implicit ev: Err <:< Response, trace: Trace): Handler[Any, Response, Request, Response] = route.toHandler.provideEnvironment(env) - override def toString() = s"Route.Provided(${route}, ${env})" + override def toString = s"Route.Provided(${route}, ${env})" } private final case class Augmented[InEnv, -OutEnv, +Err]( @@ -452,7 +452,7 @@ object Route { override def toHandler(implicit ev: Err <:< Response, trace: Trace): Handler[OutEnv, Response, Request, Response] = aspect(route.toHandler) - override def toString() = s"Route.Augmented(${route}, ${aspect})" + override def toString = s"Route.Augmented(${route}, ${aspect})" } private final case class Handled[-Env]( @@ -463,7 +463,7 @@ object Route { override def toHandler(implicit ev: Nothing <:< Response, trace: Trace): Handler[Env, Response, Request, Response] = Handler.fromZIO(handler(routePattern)).flatten - override def toString() = s"Route.Handled(${routePattern}, ${location})" + override def toString = s"Route.Handled(${routePattern}, ${location})" } private final case class Unhandled[Params, Input, -Env, +Err]( rpm: Route.Builder[Env, Params], @@ -478,7 +478,7 @@ object Route { convert(handler.asErrorType[Response]) } - override def toString() = s"Route.Unhandled(${routePattern}, ${location})" + override def toString = s"Route.Unhandled(${routePattern}, ${location})" private def convert[Env1 <: Env]( handler: Handler[Env1, Response, Input, Response], diff --git a/zio-http/shared/src/main/scala/zio/http/RoutePattern.scala b/zio-http/shared/src/main/scala/zio/http/RoutePattern.scala index e88062c99d..2c47d99d48 100644 --- a/zio-http/shared/src/main/scala/zio/http/RoutePattern.scala +++ b/zio-http/shared/src/main/scala/zio/http/RoutePattern.scala @@ -15,11 +15,10 @@ */ package zio.http -import scala.annotation.tailrec import scala.collection.immutable.ListMap import scala.language.implicitConversions -import zio.{Chunk, NonEmptyChunk, Zippable} +import zio._ import zio.http.codec._ @@ -139,7 +138,7 @@ final case class RoutePattern[A](method: Method, pathCodec: PathCodec[A]) { self def toHttpCodec: HttpCodec[HttpCodecType.Path with HttpCodecType.Method, A] = MethodCodec.method(method) ++ HttpCodec.Path(pathCodec) - override def toString(): String = render + override def toString: String = render /** * This exists for use with Scala custom extractor syntax, allowing route diff --git a/zio-http/shared/src/main/scala/zio/http/Status.scala b/zio-http/shared/src/main/scala/zio/http/Status.scala index f26acae610..7cc5a4efe6 100644 --- a/zio-http/shared/src/main/scala/zio/http/Status.scala +++ b/zio-http/shared/src/main/scala/zio/http/Status.scala @@ -21,8 +21,6 @@ import scala.util.Try import zio.Trace import zio.stacktracer.TracingImplicits.disableAutoTrace -import zio.http._ - sealed trait Status extends Product with Serializable { self => def isInformational: Boolean = code >= 100 && code < 200 diff --git a/zio-http/shared/src/main/scala/zio/http/URL.scala b/zio-http/shared/src/main/scala/zio/http/URL.scala index 120a6f0830..4c3a86460a 100644 --- a/zio-http/shared/src/main/scala/zio/http/URL.scala +++ b/zio-http/shared/src/main/scala/zio/http/URL.scala @@ -95,7 +95,7 @@ final case class URL( hash } - override def toString(): String = encode + override def toString: String = encode def host: Option[String] = kind match { case URL.Location.Relative => None diff --git a/zio-http/shared/src/main/scala/zio/http/codec/Alternator.scala b/zio-http/shared/src/main/scala/zio/http/codec/Alternator.scala index f43448117a..10b7c7a93d 100644 --- a/zio-http/shared/src/main/scala/zio/http/codec/Alternator.scala +++ b/zio-http/shared/src/main/scala/zio/http/codec/Alternator.scala @@ -20,8 +20,8 @@ import zio.ZNothing import zio.stacktracer.TracingImplicits.disableAutoTrace /** - * A alternator is a type class responsible for combining invariant type - * parameters using an either. It is used to compose parameters of the + * An alternator is a type class responsible for combining invariant type + * parameters using an Either. It is used to compose parameters of the * [[zio.http.codec.HttpCodec]] data type. */ sealed trait Alternator[L, R] { diff --git a/zio-http/shared/src/main/scala/zio/http/codec/Doc.scala b/zio-http/shared/src/main/scala/zio/http/codec/Doc.scala index dd89d4890f..f6e7f3d221 100644 --- a/zio-http/shared/src/main/scala/zio/http/codec/Doc.scala +++ b/zio-http/shared/src/main/scala/zio/http/codec/Doc.scala @@ -539,7 +539,7 @@ private[codec] class DocWriter(stringBuilder: StringBuilder, startOffset: Int, c def indent(adjust: Int): Unit = self.marginStack = adjust :: self.marginStack - override def toString(): String = stringBuilder.toString() + override def toString: String = stringBuilder.toString() def unindent(): Unit = self.marginStack = self.marginStack.drop(1) } diff --git a/zio-http/shared/src/main/scala/zio/http/codec/HeaderCodecs.scala b/zio-http/shared/src/main/scala/zio/http/codec/HeaderCodecs.scala index 68159c9582..a6ced4dec4 100644 --- a/zio-http/shared/src/main/scala/zio/http/codec/HeaderCodecs.scala +++ b/zio-http/shared/src/main/scala/zio/http/codec/HeaderCodecs.scala @@ -21,7 +21,7 @@ import scala.util.Try import zio.stacktracer.TracingImplicits.disableAutoTrace import zio.http.Header.HeaderType -import zio.http.{Header, MediaType} +import zio.http._ private[codec] trait HeaderCodecs { private[http] def headerCodec[A](name: String, value: TextCodec[A]): HeaderCodec[A] = diff --git a/zio-http/shared/src/main/scala/zio/http/codec/HttpContentCodec.scala b/zio-http/shared/src/main/scala/zio/http/codec/HttpContentCodec.scala index 60aa3af54b..0c92a45d89 100644 --- a/zio-http/shared/src/main/scala/zio/http/codec/HttpContentCodec.scala +++ b/zio-http/shared/src/main/scala/zio/http/codec/HttpContentCodec.scala @@ -11,7 +11,6 @@ import zio.schema.{DeriveSchema, Schema} import zio.http.Header.Accept.MediaTypeWithQFactor import zio.http._ -import zio.http.codec.internal.TextBinaryCodec import zio.http.internal.HeaderOps import zio.http.template._ @@ -326,9 +325,9 @@ object HttpContentCodec { val codec = HttpContentCodec.Choices( ListMap( MediaType.text.`plain` -> - BinaryCodecWithSchema(zio.http.codec.internal.TextBinaryCodec.fromSchema[A](schema), schema), + BinaryCodecWithSchema(http.codec.TextBinaryCodec.fromSchema[A](schema), schema), MediaType.application.`octet-stream` -> - BinaryCodecWithSchema(zio.http.codec.internal.TextBinaryCodec.fromSchema[A](schema), schema), + BinaryCodecWithSchema(http.codec.TextBinaryCodec.fromSchema[A](schema), schema), ), ) textCodecCache = textCodecCache + (schema -> codec) diff --git a/zio-http/shared/src/main/scala/zio/http/codec/PathCodec.scala b/zio-http/shared/src/main/scala/zio/http/codec/PathCodec.scala index 1829beaffc..d9b3a9384d 100644 --- a/zio-http/shared/src/main/scala/zio/http/codec/PathCodec.scala +++ b/zio-http/shared/src/main/scala/zio/http/codec/PathCodec.scala @@ -649,7 +649,7 @@ sealed trait PathCodec[A] extends codec.PathCodecPlatformSpecific { self => loop(self) } - override def toString(): String = render + override def toString: String = render final def transform[A2](f: A => A2)(g: A2 => A): PathCodec[A2] = PathCodec.TransformOrFail[A, A2](self, in => Right(f(in)), output => Right(g(output))) diff --git a/zio-http/shared/src/main/scala/zio/http/codec/QueryCodecs.scala b/zio-http/shared/src/main/scala/zio/http/codec/QueryCodecs.scala index a4260aea9d..aac9ce744c 100644 --- a/zio-http/shared/src/main/scala/zio/http/codec/QueryCodecs.scala +++ b/zio-http/shared/src/main/scala/zio/http/codec/QueryCodecs.scala @@ -15,14 +15,11 @@ */ package zio.http.codec -import zio.Chunk import zio.stacktracer.TracingImplicits.disableAutoTrace import zio.schema.Schema import zio.schema.annotation.simpleEnum -import zio.http.codec.internal.TextBinaryCodec - private[codec] trait QueryCodecs { def query[A](name: String)(implicit schema: Schema[A]): QueryCodec[A] = diff --git a/zio-http/shared/src/main/scala/zio/http/codec/internal/TextBinaryCodec.scala b/zio-http/shared/src/main/scala/zio/http/codec/TextBinaryCodec.scala similarity index 97% rename from zio-http/shared/src/main/scala/zio/http/codec/internal/TextBinaryCodec.scala rename to zio-http/shared/src/main/scala/zio/http/codec/TextBinaryCodec.scala index d3b203428a..cd552ad814 100644 --- a/zio-http/shared/src/main/scala/zio/http/codec/internal/TextBinaryCodec.scala +++ b/zio-http/shared/src/main/scala/zio/http/codec/TextBinaryCodec.scala @@ -1,4 +1,4 @@ -package zio.http.codec.internal +package zio.http.codec import java.time._ import java.util.{Currency, UUID} @@ -15,19 +15,19 @@ object TextBinaryCodec { private def errorCodec[A](schema: Schema[A]) = new BinaryCodec[A] { override def decode(whole: Chunk[Byte]): Either[DecodeError, A] = throw new IllegalArgumentException( - s"Schema $schema is not a primitive. Only primitive schemas are supported by TextCodec.", + s"Schema $schema is not supported by TextBinaryCodec.", ) override def streamDecoder: ZPipeline[Any, DecodeError, Byte, A] = throw new IllegalArgumentException( - s"Schema $schema is not a primitive. Only primitive schemas are supported by TextCodec.", + s"Schema $schema is not supported by TextBinaryCodec.", ) override def encode(value: A): Chunk[Byte] = throw new IllegalArgumentException( - s"Schema $schema is not a primitive. Only primitive schemas are supported by TextCodec.", + s"Schema $schema is not supported by TextBinaryCodec.", ) override def streamEncoder: ZPipeline[Any, Nothing, A, Byte] = throw new IllegalArgumentException( - s"Schema $schema is not a primitive. Only primitive schemas are supported by TextCodec.", + s"Schema $schema is not supported by TextBinaryCodec.", ) } diff --git a/zio-http/shared/src/main/scala/zio/http/codec/TextCodec.scala b/zio-http/shared/src/main/scala/zio/http/codec/TextCodec.scala index 41d06c0974..ee2cb9c704 100644 --- a/zio-http/shared/src/main/scala/zio/http/codec/TextCodec.scala +++ b/zio-http/shared/src/main/scala/zio/http/codec/TextCodec.scala @@ -69,7 +69,7 @@ object TextCodec { def isDefinedAt(value: String): Boolean = value == string - override def toString(): String = s"TextCodec.constant(${string})" + override def toString: String = s"TextCodec.constant(${string})" } case object StringCodec extends TextCodec[String] { @@ -81,7 +81,7 @@ object TextCodec { def isDefinedAt(value: String): Boolean = true - override def toString(): String = "TextCodec.string" + override def toString: String = "TextCodec.string" } case object IntCodec extends TextCodec[Int] { @@ -105,7 +105,7 @@ object TextCodec { defined && i >= 1 } - override def toString(): String = "TextCodec.int" + override def toString: String = "TextCodec.int" } case object LongCodec extends TextCodec[Long] { @@ -129,7 +129,7 @@ object TextCodec { defined && i >= 1 } - override def toString(): String = "TextCodec.long" + override def toString: String = "TextCodec.long" } case object BooleanCodec extends TextCodec[Boolean] { @@ -150,7 +150,7 @@ object TextCodec { valueLower == "no" || valueLower == "off" || valueLower == "yes" || valueLower == "on" } - override def toString(): String = "TextCodec.boolean" + override def toString: String = "TextCodec.boolean" } case object UUIDCodec extends TextCodec[UUID] { @@ -187,7 +187,7 @@ object TextCodec { defined && i == 36 } - override def toString(): String = "TextCodec.uuid" + override def toString: String = "TextCodec.uuid" } } diff --git a/zio-http/shared/src/main/scala/zio/http/codec/internal/BodyCodec.scala b/zio-http/shared/src/main/scala/zio/http/codec/internal/BodyCodec.scala index abf167ef39..c51a28a594 100644 --- a/zio-http/shared/src/main/scala/zio/http/codec/internal/BodyCodec.scala +++ b/zio-http/shared/src/main/scala/zio/http/codec/internal/BodyCodec.scala @@ -120,7 +120,7 @@ private[http] object BodyCodec { case Left(error) => ZIO.fail(error) case Right((_, BinaryCodecWithSchema(_, schema))) if schema == Schema[Unit] => ZIO.unit.asInstanceOf[IO[Throwable, A]] - case Right((_, bc @ BinaryCodecWithSchema(codec, schema))) => + case Right((_, bc @ BinaryCodecWithSchema(_, schema))) => field.asChunk.flatMap { chunk => ZIO.fromEither(bc.codec(config).decode(chunk)) }.flatMap(validateZIO(schema)) } } diff --git a/zio-http/shared/src/main/scala/zio/http/codec/internal/EncoderDecoder.scala b/zio-http/shared/src/main/scala/zio/http/codec/internal/EncoderDecoder.scala index 1178e67a12..705b432cbf 100644 --- a/zio-http/shared/src/main/scala/zio/http/codec/internal/EncoderDecoder.scala +++ b/zio-http/shared/src/main/scala/zio/http/codec/internal/EncoderDecoder.scala @@ -16,17 +16,14 @@ package zio.http.codec.internal -import scala.annotation.nowarn import scala.util.Try import zio._ -import zio.stream.ZStream - import zio.schema.codec.{BinaryCodec, DecodeError} import zio.schema.{Schema, StandardType} -import zio.http.Header.Accept.{MediaTypeWithQFactor, render} +import zio.http.Header.Accept.MediaTypeWithQFactor import zio.http._ import zio.http.codec.HttpCodec.Query.QueryType import zio.http.codec._ diff --git a/zio-http/shared/src/main/scala/zio/http/codec/internal/HaltException.scala b/zio-http/shared/src/main/scala/zio/http/codec/internal/HaltException.scala index 3614410962..08d6d8c2f5 100644 --- a/zio-http/shared/src/main/scala/zio/http/codec/internal/HaltException.scala +++ b/zio-http/shared/src/main/scala/zio/http/codec/internal/HaltException.scala @@ -19,6 +19,6 @@ package zio.http.codec.internal import scala.util.control.NoStackTrace import zio.stacktracer.TracingImplicits.disableAutoTrace -case object HaltException +private[codec] case object HaltException extends RuntimeException("This exception is used only for control flow purposes") with NoStackTrace diff --git a/zio-http/shared/src/main/scala/zio/http/endpoint/Endpoint.scala b/zio-http/shared/src/main/scala/zio/http/endpoint/Endpoint.scala index 9925811c24..786a149b36 100644 --- a/zio-http/shared/src/main/scala/zio/http/endpoint/Endpoint.scala +++ b/zio-http/shared/src/main/scala/zio/http/endpoint/Endpoint.scala @@ -23,11 +23,10 @@ import zio._ import zio.stream.ZStream -import zio.schema._ +import zio.schema.Schema import zio.http.Header.Accept.MediaTypeWithQFactor import zio.http._ -import zio.http.codec.HttpCodecType.{RequestType, ResponseType} import zio.http.codec._ import zio.http.endpoint.Endpoint.{OutErrors, defaultMediaTypes} @@ -258,7 +257,7 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType]( def implementHandler[Env](original: Handler[Env, Err, Input, Output])(implicit trace: Trace): Route[Env, Nothing] = { import HttpCodecError.asHttpCodecError - def authCodec(authType: AuthType): HttpCodec[RequestType, Unit] = authType match { + def authCodec(authType: AuthType): HttpCodec[HttpCodecType.RequestType, Unit] = authType match { case AuthType.None => HttpCodec.empty case AuthType.Basic => HeaderCodec.authorization.transformOrFail { diff --git a/zio-http/shared/src/main/scala/zio/http/endpoint/EndpointExecutor.scala b/zio-http/shared/src/main/scala/zio/http/endpoint/EndpointExecutor.scala index e044743eb0..f83c1eb6a6 100644 --- a/zio-http/shared/src/main/scala/zio/http/endpoint/EndpointExecutor.scala +++ b/zio-http/shared/src/main/scala/zio/http/endpoint/EndpointExecutor.scala @@ -20,7 +20,7 @@ import zio._ import zio.stacktracer.TracingImplicits.disableAutoTrace import zio.http._ -import zio.http.codec.{Alternator, CodecConfig, Combiner} +import zio.http.codec._ import zio.http.endpoint.internal.EndpointClient /** @@ -34,7 +34,7 @@ final case class EndpointExecutor[R, Auth]( authProvider: ZIO[R, Nothing, Auth], ) { private val metadata = { - implicit val trace0 = Trace.empty + implicit val trace0: Trace = Trace.empty zio.http.endpoint.internal .MemoizedZIO[Endpoint[_, _, _, _, _ <: AuthType], EndpointNotFound, EndpointClient[ Any, diff --git a/zio-http/shared/src/main/scala/zio/http/endpoint/EndpointLocator.scala b/zio-http/shared/src/main/scala/zio/http/endpoint/EndpointLocator.scala index 3fea0ae4c6..d39588d79b 100644 --- a/zio-http/shared/src/main/scala/zio/http/endpoint/EndpointLocator.scala +++ b/zio-http/shared/src/main/scala/zio/http/endpoint/EndpointLocator.scala @@ -43,7 +43,7 @@ trait EndpointLocator { self => } object EndpointLocator { def fromURL(url: URL)(implicit trace: Trace): EndpointLocator = new EndpointLocator { - val effect = ZIO.succeed(url) + private val effect = ZIO.succeed(url) def locate[P, A, E, B](api: Endpoint[P, A, E, B, _ <: AuthType])(implicit trace: Trace, diff --git a/zio-http/shared/src/main/scala/zio/http/endpoint/openapi/JsonSchema.scala b/zio-http/shared/src/main/scala/zio/http/endpoint/openapi/JsonSchema.scala index 930e038ff5..abd59326c0 100644 --- a/zio-http/shared/src/main/scala/zio/http/endpoint/openapi/JsonSchema.scala +++ b/zio-http/shared/src/main/scala/zio/http/endpoint/openapi/JsonSchema.scala @@ -1,21 +1,18 @@ package zio.http.endpoint.openapi import scala.annotation.{nowarn, tailrec} -import scala.util.chaining.scalaUtilChainingOps import zio._ import zio.json.ast.Json import zio.schema.Schema.CaseClass0 -import zio.schema.StandardType.Tags import zio.schema._ import zio.schema.annotation._ import zio.schema.codec._ import zio.schema.codec.json._ import zio.schema.validation._ -import zio.http.codec.{PathCodec, SegmentCodec, TextCodec} -import zio.http.endpoint.openapi.BoolOrSchema.SchemaWrapper +import zio.http.codec._ import zio.http.endpoint.openapi.JsonSchema.MetaData @nowarn("msg=possible missing interpolator") diff --git a/zio-http/shared/src/main/scala/zio/http/endpoint/openapi/OpenAPI.scala b/zio-http/shared/src/main/scala/zio/http/endpoint/openapi/OpenAPI.scala index 4f04d9e878..d9e57f5ef5 100644 --- a/zio-http/shared/src/main/scala/zio/http/endpoint/openapi/OpenAPI.scala +++ b/zio-http/shared/src/main/scala/zio/http/endpoint/openapi/OpenAPI.scala @@ -1315,7 +1315,7 @@ object OpenAPI { case "query" => Right(Query) case "header" => Right(Header) case "cookie" => Right(Cookie) - case value => Left(s"Invalid ApiKey.In $s") + case _ => Left(s"Invalid ApiKey.In $s") }, { case Query => Right("query") diff --git a/zio-http/shared/src/main/scala/zio/http/internal/BodyEncoding.scala b/zio-http/shared/src/main/scala/zio/http/internal/BodyEncoding.scala index 3b669b52be..65a8fe5320 100644 --- a/zio-http/shared/src/main/scala/zio/http/internal/BodyEncoding.scala +++ b/zio-http/shared/src/main/scala/zio/http/internal/BodyEncoding.scala @@ -20,8 +20,8 @@ import java.nio.charset.Charset import zio.http.{Body, Charsets} -trait BodyEncoding { +private[http] trait BodyEncoding { def fromCharSequence(charSequence: CharSequence, charset: Charset = Charsets.Http): Body } -object BodyEncoding extends BodyEncodingPlatformSpecific +private[http] object BodyEncoding extends BodyEncodingPlatformSpecific diff --git a/zio-http/shared/src/main/scala/zio/http/internal/CaseMode.scala b/zio-http/shared/src/main/scala/zio/http/internal/CaseMode.scala index 37c3abd686..2a58d6d5ab 100644 --- a/zio-http/shared/src/main/scala/zio/http/internal/CaseMode.scala +++ b/zio-http/shared/src/main/scala/zio/http/internal/CaseMode.scala @@ -16,7 +16,7 @@ package zio.http.internal -sealed trait CaseMode +private[http] sealed trait CaseMode object CaseMode { case object Sensitive extends CaseMode diff --git a/zio-http/shared/src/main/scala/zio/http/internal/QueryGetters.scala b/zio-http/shared/src/main/scala/zio/http/internal/QueryGetters.scala index 5acd2a7738..957098c37e 100644 --- a/zio-http/shared/src/main/scala/zio/http/internal/QueryGetters.scala +++ b/zio-http/shared/src/main/scala/zio/http/internal/QueryGetters.scala @@ -16,10 +16,6 @@ package zio.http.internal -import java.util - -import scala.jdk.CollectionConverters._ - import zio._ import zio.http._ diff --git a/zio-http/shared/src/main/scala/zio/http/template/Dom.scala b/zio-http/shared/src/main/scala/zio/http/template/Dom.scala index 056e4ceca6..64af836e92 100644 --- a/zio-http/shared/src/main/scala/zio/http/template/Dom.scala +++ b/zio-http/shared/src/main/scala/zio/http/template/Dom.scala @@ -21,7 +21,7 @@ import scala.collection.immutable.ListMap import zio.schema.Schema import zio.http.MediaType -import zio.http.codec.{BinaryCodecWithSchema, HttpContentCodec} +import zio.http.codec.{BinaryCodecWithSchema, HttpContentCodec, TextBinaryCodec} import zio.http.internal.OutputEncoder /** @@ -93,7 +93,7 @@ object Dom { HttpContentCodec( ListMap( MediaType.text.`html` -> - BinaryCodecWithSchema.fromBinaryCodec(zio.http.codec.internal.TextBinaryCodec.fromSchema(Schema[Dom])), + BinaryCodecWithSchema.fromBinaryCodec(TextBinaryCodec.fromSchema(Schema[Dom])), ), ) }