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

cohttp-eio: add Client.make_generic and HTTPS support #1002

Merged
merged 3 commits into from
Oct 27, 2023

Conversation

talex5
Copy link
Contributor

@talex5 talex5 commented Oct 25, 2023

#984 (comment) said:

I aim at merging this and mefyl/ocaml-cohttp@eio...talex5:ocaml-cohttp:eio-tls as they are now though (perhaps with some more explanations on how to do tls properly), release a new beta release and see if there are comments

However, the TLS support wasn't included in the end, so I'm opening a separate PR for it here.

/cc @SGrondin

This is to allow other resolution systems in future.
The new `Client.make_generic` allows the user to provide their own
function for resolving URIs to flows.

The convenience wrapper `make` now taken an `https` argument,
which is a function that can be used to wrap raw sockets with a TLS
library.

The `client_tls.ml` example shows how to use this with tls-eio.
@@ -1,9 +1,29 @@
open Eio.Std
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 avoid opening here, and leave Eio.Switch below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be a bit ugly - several other places would get a fair bit longer too.

@mseri
Copy link
Collaborator

mseri commented Oct 25, 2023

Thanks! Just in time, I was getting ready to release the new beta :)

uses [net] to make connections.
https:
(Uri.t -> [ `Generic ] Eio.Net.stream_socket_ty r -> _ Eio.Flow.two_way)
option ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
option ->
->

Since it is no longer optional, why not dropping the option from the signature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https support is optional (you don't have to use it); see #984 (comment):

I don’t have too strong of an opinion, I think the optional is cleaner but perhaps https is so pervasive nowadays that it is good to keep it explicit instead.

Copy link
Member

@samoht samoht Oct 26, 2023

Choose a reason for hiding this comment

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

if the plan is to have a separate cohttp-eio-tls package I suggest making the parameter optional - otherwise it's a bit clumsy for HTTP calls to have to thread that ~https:None parameter everwhere.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I agree. I was recalling what we had discussed incorrectly

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this signature ok as is, or do we need to change https into ?https?

Copy link
Member

Choose a reason for hiding this comment

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

I think I would prefer ?https but I also understand the rationale to keep it explicit as the error mode (the call will just hang) is not great right now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's leave it as is. We can make it optional in due course once there is the tls package if we can think of a better way to deal with it

in
Eio.Switch.run @@ fun sw ->
let resp, body =
Client.get ~sw client (Uri.of_string "https://example.com")
Copy link
Member

Choose a reason for hiding this comment

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

I am a bit sad with the amount of boilerplate we have to come up to do a simple https call. Could we somehow ship a default authenticator as well? The current API doesn't look very simple to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't ship a default authenticator without adding extra dependencies to cohttp-eio. The plan is to have another package for that later (either cohttp-eio-tls, or maybe something conduit-like); this PR is just making that possible.

Copy link
Collaborator

@mseri mseri Oct 26, 2023

Choose a reason for hiding this comment

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

I think we could merge this and release it as beta, so that people can test it out in the meantime and inform possible api refinements. But I agree with @samoht, and I think it would be nice to have cohttp-eio-tls before we release the new stable 6.0.0

Copy link
Member

Choose a reason for hiding this comment

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

That sounds like a good plan. I'm already using that PR in a project of mine and it's working great 👍 Thanks for this!

@mseri mseri merged commit d4fe19b into mirage:master Oct 27, 2023
17 of 19 checks passed
mseri added a commit to mseri/opam-repository that referenced this pull request Oct 27, 2023
CHANGES:

- cohttp-eio: Complete rewrite to follow common interfaces and behaviors. (mefyl mirage/ocaml-cohttp#984)
- cohttp-eio: Add Client.make_generic and HTTPS support. (talex5 mirage/ocaml-cohttp#1002)
mseri added a commit to mseri/opam-repository that referenced this pull request Oct 27, 2023
CHANGES:

- cohttp-eio: Complete rewrite to follow common interfaces and behaviors. (mefyl mirage/ocaml-cohttp#984)
- cohttp-eio: Add Client.make_generic and HTTPS support. (talex5 mirage/ocaml-cohttp#1002)
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.

3 participants