Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LinkedHttpContentReader Read Limits #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

er1c
Copy link
Contributor

@er1c er1c commented Dec 1, 2018

This is a preview PR, but largely done - I might add another test or two, and then I need to go through the PR with a finer grain comb.

It adds additional support for maxLength limits in LinkedHttpContentReader and also introduces a MaxLengthStrategy parameter for controlling how the server should respond to the limit.

The added test includes an example usage:

      val res: Future[Response] = request.content.writeToFile(file, OneMB, LinkedHttpContentReader.MaxLengthStrategy.DiscardAndThrowException).map { _ =>
        Response.Ok(file.length.toString)
      }.recoverWith {
        case ex: LinkedHttpContentReader.MaxLengthException => Future.successful(Response.plain(Status.REQUEST_ENTITY_TOO_LARGE, "413 Request Entity Too Large"))
      }

This allow custom responses in case the upload is too large.

I also added support to the HttpClient and HttpServer for requesting and handle Expect: 100-continue patterns

Example:

> POST /webcat30/v1/services/htmlToPdf?fileName=bosch-1234.pdf HTTP/1.1
> Host: webservice-preprod.tecalliance.services
> User-Agent: curl/7.54.0
> Accept: */*
> X-API-Key: 2BeBXg64EewdEsApWYJpK76jWDY7w4L6ZNx1gkSPH3SpLkySKMnX
> Content-Type: text/html
> Content-Length: 522759
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
} [16384 bytes data]
* We are completely uploaded and fine

The same exception LinkedHttpContentReader.MaxLengthException will get thrown early (before all of the content is read) if the Content-Length is part of an Expect: 100-continue request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant