-
Notifications
You must be signed in to change notification settings - Fork 310
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
Make AbstractCurlBackend async friendly #2012
Conversation
core/src/main/scalanative/sttp/client4/curl/AbstractCurlBackend.scala
Outdated
Show resolved
Hide resolved
/** A request-specific context, with allocated zones and headers. */ | ||
private class Context() { | ||
val zone: Zone = Zone.open() | ||
var headers: CurlList = _ |
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.
instead of var
s, mabye we can prepare the headers/multiPartHeaders parameters in send
, and then create an (immutable) instance of Context
? E.g. case class Context(zone: Zone, headers: Option[CurlList], multiPartHeaders: Seq[CurlList])
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.
A bit tricky to do, since setRequestBody
is setting up the multi part headers as it goes through the multipart body. I can on the other hand just exposes a addHeader
function to create a header that gets cleared when the context is closed.
core/src/main/scalanative/sttp/client4/curl/AbstractCurlBackend.scala
Outdated
Show resolved
Hide resolved
core/src/main/scalanative/sttp/client4/curl/AbstractCurlBackend.scala
Outdated
Show resolved
Hide resolved
Thanks for the PR! :) I left some comments/questions inline |
(sorry wrong button ;) ) |
val curl = CurlApi.init | ||
if (verbose) { | ||
curl.option(Verbose, parameter = true) | ||
} | ||
if (request.tags.nonEmpty) { | ||
monad.error(new UnsupportedOperationException("Tags are not supported")) | ||
return monad.error(new UnsupportedOperationException("Tags are not supported")) |
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.
nice catch! :)
Thank you! Do you need a release with these changes, or will you continue working on an async curl backend? |
Thanks!
Not yet, as I am waiting for scala-native 0.5 and everything else to fall into place ;)
I have a prototype over at https://github.com/natsukagami/sttp/tree/curl-async-gears , but as the branch name suggests, it currently depends on gears stuff and serves mostly as a demonstration that it's possible. I might come back and write a proper backend later :D |
I see, thanks for the info, I'll be on the lookout for more PRs then :) |
Just some structural changes to make implementing an async Curl backend (e.g. with
curl_multi_*
) possible asa subclass of
AbstractCurlBackend
.Mainly:
CurlHandle -> F[CurlCode]
method,performCurl
. This can be done withcurl_multi_*
instead of just
curl_easy_perform
. Also seems to be the only thing needed to be changed.We might have to change
curl.option
calls as well, if we want to properly handle them as monadic calls.Before submitting pull request:
sbt compile
sbt compileDocs
sbt test
sbt scalafmt