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

Add {Required,Optional}RequestBody readers. #81

Merged
merged 4 commits into from
Nov 24, 2014

Conversation

BenWhitehead
Copy link
Contributor

No description provided.

@coveralls
Copy link

Coverage Status

Coverage decreased (-13.91%) when pulling cd05029 on BenWhitehead:request-body-readers into 7af5168 on finagle:master.

object RequiredBody {

/**
* Creates a ''RequestReader'' that reads the required required body
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"... required required body ..."

@vkostyukov
Copy link
Collaborator

This is pretty cool Ben @BenWhitehead! Could you please all add a couple of unit tests to keep the coverage rate at a good level?

@BenWhitehead
Copy link
Contributor Author

Thanks for the review, I'll incorporate your feedback and add some tests this afternoon.

/**
* A required request body that is interpreted as an ''Array[Byte]''
*/
object RequiredBody {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, can't we just do object RequiredBody extends RequestReader ... to use it like:

val r = for {
  body <- RequiredBody
}

instead of:

val r = for {
  body <- RequiredBody()
}

and the same for OptionalBody, RequiredStringBody and OptionalStringBody.

*/
def apply() = for {
body <- RequiredBody()
} yield { new String(body, "UTF-8") }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm not sure we need these parenthesis here. You can do yield new String(...).

* Update readers to directly extend RequestReader for easier use.
* Update readers to minimize code duplication
* Cleanup a few stylistic issues
@coveralls
Copy link

Coverage Status

Coverage increased (+0.53%) when pulling a2b5213 on BenWhitehead:request-body-readers into 7af5168 on finagle:master.

@BenWhitehead
Copy link
Contributor Author

Feedback incorporated and I've added unit tests.

object RequiredBody extends RequestReader[Array[Byte]] {

/**
* Creates a ''RequestReader'' that reads the required body
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this paragraph up to object RequiredBody? It's no longer true for apply method.

@vkostyukov
Copy link
Collaborator

Ben @BenWhitehead, the tests look cool, thanks a lot! Sorry for being picky regarding the code style I'm just trying to keep it as uniform and similar as possible. I'm also realised that we need new exception here: BodyNotFound.

Update comment for body readers.
Update contributor name.
Clean up some minor nitpick items.
@BenWhitehead
Copy link
Contributor Author

@vkostyukov I made the requested updates.

No worries about being picky, I tend to expect it when contributing to a new code base.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.53%) when pulling f918bb8 on BenWhitehead:request-body-readers into 7af5168 on finagle:master.

it should "produce an error if the body is empty" in {
val request: HttpRequest = requestWithBody("")
val futureResult: Future[String] = RequiredStringBody(request)
intercept[ValidationFailed] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did it pass if we are raising a BodyNotFound exception?

@vkostyukov
Copy link
Collaborator

It's actually failed: https://travis-ci.org/finagle/finch/builds/41930575. Don't know why Travis reported success.

@BenWhitehead
Copy link
Contributor Author

Doh, knew I forgot something.

Fixed the expected exceptions. All tests pass now.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.53%) when pulling bc3e2eb on BenWhitehead:request-body-readers into 7af5168 on finagle:master.

@vkostyukov
Copy link
Collaborator

Thanks Ben @BenWhitehead! This is awesome!

vkostyukov added a commit that referenced this pull request Nov 24, 2014
Add {Required,Optional}RequestBody readers.
@vkostyukov vkostyukov merged commit 7ecc5a3 into finagle:master Nov 24, 2014
@BenWhitehead BenWhitehead deleted the request-body-readers branch February 2, 2015 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants