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

Document HttpClient usage with encoder/decoder and proper disposal #397

Open
asarkar opened this issue Jul 24, 2018 · 0 comments
Open

Document HttpClient usage with encoder/decoder and proper disposal #397

asarkar opened this issue Jul 24, 2018 · 0 comments
Labels
type/documentation A documentation update

Comments

@asarkar
Copy link

asarkar commented Jul 24, 2018

It's unclear how encoder/decoder (or codecs as known pre Netty 5) are to be used with HttpClient. It's also unclear how and when to properly dispose a HttpClientResponse. Consider the following Kotlin client code:

return response
  .flatMap {
      val statusCode = it.status().code()
      when (statusCode) {
          in 200..399 -> {
              // this ain't exactly reactive, but will do
              it.receive()
                .aggregate()
                .asString(StandardCharsets.UTF_8)
                .flatMap {
                    it.let {
                        val tree = objectMapper.readTree(it)
                        val status = tree.path("Outcome").textValue()
                        when (status) {
                            "Success" -> {
                                // parse response
                            }
                            else -> Mono.error(IOException("Server returned error: $status"))
                        }
                    }
                }
          }
          else -> Mono.error(IOException("Server returned HTTP status code: $statusCode"))
      }
  }
  .doOnError { it.printStackTrace() }
  .blockOptional(Duration.ofSeconds(10L))
  .orElseGet { Collections.emptyList() }

It's not exactly pretty due to deep nesting, which could be avoided if I could somehow register success and error handlers (based on response status). Also, the response is never disposed, which could lead to resource leak.

There is no documentation on HttpClient usage or best practices, and yes, I've looked at HttpClientTest.java before opening this issue. I understand that Spring WebClient might address these concerns, but WebClient isn't a standalone module, and I don't need the additional baggage that comes with WebFlux otherwise.

@smaldini smaldini added this to the 0.8.x Backlog milestone Aug 14, 2018
@smaldini smaldini added the type/documentation A documentation update label Aug 14, 2018
@smaldini smaldini modified the milestones: 0.8.x Backlog, 0.9.x Backlog Feb 7, 2019
@violetagg violetagg modified the milestones: 0.9.x Maintenance Backlog, 1.0.0 Backlog Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/documentation A documentation update
Projects
None yet
Development

No branches or pull requests

3 participants