-
Notifications
You must be signed in to change notification settings - Fork 70
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
Fix to send empty body, and consume it #522
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9719cfd
Fix to send empty body, and consume it
daddykotex 1d87c20
Add a e2e test for exercising http client/server
daddykotex 3f2e8bf
Cats 3 only
daddykotex 0b666ae
Include the test...
daddykotex cfb1161
Remove Klesili when unused
daddykotex 3680c3e
Use IO.stub instead of `???`
daddykotex 9962f80
Use a val instead of a def
daddykotex b699d7a
Keep the show instance for error tests
daddykotex f2b721f
Merge remote-tracking branch 'origin/series/0.17' into dfrancoeur/515…
daddykotex d1b21f0
Compile the codec before building the function
daddykotex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
modules/http4s/test/src-jvm-ce3/smithy4s/http4s/Http4sEmberPizzaClientSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright 2021-2022 Disney Streaming | ||
* | ||
* Licensed under the Tomorrow Open Source Technology License, Version 1.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://disneystreaming.github.io/TOST-1.0.txt | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package smithy4s.http4s | ||
|
||
import cats.effect.IO | ||
import cats.effect.Resource | ||
import cats.effect.syntax.resource._ | ||
import cats.implicits._ | ||
import com.comcast.ip4s._ | ||
import com.comcast.ip4s.Port | ||
import org.http4s.ember.client.EmberClientBuilder | ||
import org.http4s.ember.server.EmberServerBuilder | ||
import org.http4s.HttpApp | ||
import org.http4s.Uri | ||
import smithy4s.example._ | ||
import smithy4s.example.PizzaAdminService | ||
import weaver._ | ||
|
||
object Http4sEmberPizzaClientSpec extends IOSuite { | ||
type Res = PizzaAdminService[IO] | ||
|
||
override def sharedResource: Resource[IO, Res] = { | ||
SimpleRestJsonBuilder | ||
.routes(dummyImpl) | ||
.resource | ||
.flatMap(r => retryResource(server(r.orNotFound))) | ||
.flatMap { port => makeClient(port) } | ||
} | ||
|
||
def makeClient(port: Int): Resource[IO, PizzaAdminService[IO]] = | ||
EmberClientBuilder.default[IO].build.flatMap { client => | ||
SimpleRestJsonBuilder(PizzaAdminService) | ||
.client(client) | ||
.uri(Uri.unsafeFromString(s"http://localhost:$port")) | ||
.resource | ||
} | ||
|
||
def server(app: HttpApp[IO]): Resource[IO, Int] = | ||
cats.effect.std.Random | ||
.scalaUtilRandom[IO] | ||
.flatMap(_.betweenInt(50000, 60000)) | ||
.toResource | ||
.flatMap(port => | ||
Port | ||
.fromInt(port) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. haven't checked but wouldn't you be able to bind to |
||
.toRight(new Exception(s"Invalid port: $port")) | ||
.liftTo[IO] | ||
.toResource | ||
) | ||
.flatMap { port => | ||
EmberServerBuilder | ||
.default[IO] | ||
.withHost(host"localhost") | ||
.withPort(port) | ||
.withHttpApp(app) | ||
.build | ||
.map(_ => port.value) | ||
} | ||
|
||
test("empty body") { client => | ||
(client.book("name") *> client.book("name2")).as(success) | ||
} | ||
|
||
private val dummyImpl = new PizzaAdminService[IO]() { | ||
// format: off | ||
override def addMenuItem(restaurant: String, menuItem: MenuItem): IO[AddMenuItemResult] = IO.stub | ||
override def getMenu(restaurant: String): IO[GetMenuResult] = IO.stub | ||
override def version(): IO[VersionOutput] = IO.stub | ||
override def health(query: Option[String]): IO[HealthResponse] = IO.pure(HealthResponse("good")) | ||
override def headerEndpoint(uppercaseHeader: Option[String], capitalizedHeader: Option[String], lowercaseHeader: Option[String], mixedHeader: Option[String]): IO[HeaderEndpointData] = IO.stub | ||
override def roundTrip(label: String, header: Option[String], query: Option[String], body: Option[String]): IO[RoundTripData] = IO.stub | ||
override def getEnum(aa: TheEnum): IO[GetEnumOutput] = IO.stub | ||
override def getIntEnum(aa: EnumResult): IO[GetIntEnumOutput] = IO.stub | ||
override def customCode(code: Int): IO[CustomCodeOutput] = IO.stub | ||
override def book(name: String, town: Option[String]): IO[BookOutput] = IO.pure(BookOutput("name")) | ||
// format: on | ||
} | ||
|
||
def retryResource[A]( | ||
resource: Resource[IO, A], | ||
max: Int = 10 | ||
): Resource[IO, A] = | ||
if (max <= 0) resource | ||
else resource.orElse(retryResource(resource, max - 1)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this not only apply to methods like PUT and POST?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a good question, let me see what facilities exists here to distinguish what method allow or not bodies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in ember:
Noticed that here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it annoys me that I can't find a public equivalent for this and avoid copy/pasting that method Set out of ember :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.putHeaders(`Content-Length`.zero)
might be another workaround. And I think this is ok for GET requests. IDK YMMV.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, an issue or PR to fix this would be great. Seems like we just need to add a boolean to
Method
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
happy to open it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the discussions in the PR, I think this should be merged as in. I'm not sure there can be an always accurate way of telling whether a particular method should have a body or not.
Considering it works for our current use cases, we should move forward with it. If we get and issue later on that sending and empty body is problematic under certain situation, we should revisit.