Skip to content

Commit

Permalink
Merge pull request #1892 from lloydmeta/feature/parameterise-entityli…
Browse files Browse the repository at this point in the history
…miter

Parameterize EntityLimiter
  • Loading branch information
aeons committed May 30, 2018
2 parents 76c98e9 + af44108 commit 66a31ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Expand Up @@ -2,7 +2,9 @@ package org.http4s
package server
package middleware

import cats.data.Kleisli
import fs2._

import scala.util.control.NoStackTrace

object EntityLimiter {
Expand All @@ -11,11 +13,11 @@ object EntityLimiter {

val DefaultMaxEntitySize: Long = 2L * 1024L * 1024L // 2 MB default

def apply[F[_]](
@deprecatedName('service) routes: HttpRoutes[F],
limit: Long = DefaultMaxEntitySize): HttpRoutes[F] =
routes.local { req: Request[F] =>
req.withBodyStream(req.body.through(takeLimited(limit)))
def apply[F[_], G[_], B](
@deprecatedName('service) http: Kleisli[F, Request[G], B],
limit: Long = DefaultMaxEntitySize): Kleisli[F, Request[G], B] =
Kleisli { req =>
http(req.withBodyStream(req.body.through(takeLimited(limit))))
}

private def takeLimited[F[_]](n: Long): Pipe[F, Byte, Byte] =
Expand Down
1 change: 1 addition & 0 deletions website/src/hugo/content/changelog.md
Expand Up @@ -35,6 +35,7 @@ it.
* Generalize `AutoSlash` middleware to work on `Kleisli[F, Request[G], B]` given `MonoidK[F]` and `Functor[G]`. [#1885](https://github.com/http4s/http4s/pull/1885)
* Generalize `CORS` middleware to work on `Http[F, G]` given `Applicative[F]` and `Functor[G]`. [#1889](https://github.com/http4s/http4s/pull/1889)
* Generalize `ChunkAggegator` middleware to work on `Kleisli[F, A, Response[G]]` given `G ~> F`, `FlatMap[F]`, and `Sync[G]`. [#1886](https://github.com/http4s/http4s/pull/1886)
* Generalize `EntityLimiter` middleware to work on `Kleisli[F, Request[G], B]`. [#1892](https://github.com/http4s/http4s/pull/1892)
* Rename `RequestLogger.apply0` and `ResponseLogger.apply0` to `RequestLogger.apply` and `ResponseLogger.apply`. [#1837](https://github.com/http4s/http4s/pull/1837)
* Move `org.http4s.server.ServerSoftware` to `org.http4s.ServerSoftware` [#1884](https://github.com/http4s/http4s/pull/1884)
* Dependency upgrades:
Expand Down

0 comments on commit 66a31ce

Please sign in to comment.