aantron / hyper Goto Github PK
View Code? Open in Web Editor NEWOCaml Web client, composable with Dream [unannounced]
License: MIT License
OCaml Web client, composable with Dream [unannounced]
License: MIT License
I am using dream to call hyper to make requests to Turso over http. When I send get or post requests, I get this:
27.02.24 05:51:45.557 dream.log INFO REQ 1 GET /turso/get 127.0.0.1:46574 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTM6
27.02.24 05:51:45.635 dream.log WARN REQ 1 Aborted by: SSL connection() error: error:14:000126:SSL routines::unexpected eof while reading
27.02.24 05:51:45.635 dream.log WARN Raised by primitive operation at Ssl in file "src/ssl.ml", line 785, characters 14-33
27.02.24 05:51:45.635 dream.log WARN Called from Lwt_ssl.wrap_call in file "src/lwt_ssl.ml", line 47, characters 4-8
27.02.24 05:51:45.635 dream.log WARN Re-raised at Lwt_ssl.wrap_call in file "src/lwt_ssl.ml", line 57, characters 7-14
27.02.24 05:51:45.635 dream.log WARN Called from Lwt_unix.retry_syscall in file "src/unix/lwt_unix.cppo.ml", line 509, characters 13-24
27.02.24 05:51:45.635 dream.log WARN Re-raised at Hyper__http__Connect.alpn_https_tcp.(fun) in file "src/http/connect.ml", line 90, characte0
27.02.24 05:51:45.635 dream.log WARN Re-raised at Hyper__http__Connect.no_pool.(fun) in file "src/http/connect.ml", line 165, characters 2-85
27.02.24 05:51:45.635 dream.log WARN Re-raised at Hyper__logic__Redirect.follow_redirect.redirect_loop.(fun) in file "src/logic/redirect.ml"3
27.02.24 05:51:45.635 dream.log WARN Re-raised at Dune__exe__Turso.promise_get.(fun) in file "src/turso.ml", line 28, characters 4-325
27.02.24 05:51:45.635 dream.log WARN Re-raised at Dune__exe__Main.(fun) in file "src/main.ml", line 51, characters 12-114
27.02.24 05:51:45.635 dream.http ERROR REQ 1 SSL connection() error: error:14:000126:SSL routines::unexpected eof while reading
27.02.24 05:51:45.635 dream.http ERROR REQ 1 Raised at Stdlib__Map.Make.find in file "map.ml", line 141, characters 10-25
27.02.24 05:51:45.635 dream.http ERROR REQ 1 Called from Logs.Tag.find in file "src/logs.ml", line 154, characters 14-32
My router code looks like this:
let () =
run ~port:3000
@@ logger
@@ router [
get "/turso/get" (fun _ ->
let%lwt str = Turso.hrana_support in
str |> Dream.html
);
]
;;
Where my Turso module looks like this:
let url =
match Sys.getenv_opt "TURSO_URL" with
| Some value -> value
| None -> failwith "TURSO_URL environment variable must be set."
;;
let hrana_support =
let request =
Hyper.request ~method_:`GET @@ url ^ "/v2"
in
let%lwt response = Hyper.run request in
if Dream_pure.Message.status response = `OK then
Hyper.body response
else
let%lwt () = Dream_pure.Message.close (Dream_pure.Message.client_stream response) in
Lwt.fail (Hyper.Response response)
;;
The versions of my environment are:
Ocaml compiler: 5.1.1
openssl: 3.2.1
dune: 3.14
Let me know what more information is required. Thanks!
I saw that successfull is defined in dream like
type successful = [
| `OK
| `Created
| `Accepted
| `Non_Authoritative_Information
| `No_Content
| `Reset_Content
| `Partial_Content
]
for the simple get/post these should be considered as ok. right now 204 No_Content raises an error.
I tried this example : https://github.com/aantron/hyper/blob/master/example/2-post/post.ml
and also a simple program which only do a post request to a personal local server, i always get Fatal error: exception Unix.Unix_error(Unix.ECONNREFUSED, "connect", "")
. I tried with http://localhost:8080/
too.
The server listen on the good port, it works on my browser, my firewall is off, i don't understand why it doesn't work :/ any help ?
Again ๐ . However, for the client part of the HTTP protocol, the MirageOS is slightly more complex. Indeed, a connect
function which allocates a resource (such as a socket) is an anti-pattern for MirageOS due to one fact: the connect
function depends inherently to the implementation. For the MirageOS perspective, an application should not depend on a specific implementation and we mostly want to play with interfaces instead of their implementations (which depends on the target chosen by the user).
This is the reason of the conduit
existence and/or the mimic
existence. They want to hide the implementation-related connect
function into a Conduit.resolve
/Mimic.resolve
. Then, a ceremony is needed to explain to conduit
/mimic
which implementation you to use to connect
this kind of connection.
In the case of conduit
, you express that you want TCP 80
or TLS (TCP 443))
for instance regardless the implementation used then to give to your a Mirage_flow.S
- it can be lwt_ssl
+ lwt.unix
, ocaml-tls
+ lwt.unix
or ocaml-tls
+ mirage-tcpip
(or something else). However, we got many troubles to extend conduit
to some others protocols such as Git.
mimic
wants to replace conduit
by the extensible ability depending on what the user want. It's why it exists a Git client with mimic
and an HTTP client (with paf-cohttp
) with mimic
. But for more details about mimic
, please read the documentation: https://dinosaure.github.io/mimic/mimic/index.html
More concretely, a MirageOS compatibility expects, at least, one thing, an interface (like what provides hyper
) which should let the user to pass a ctx
(the conduit
context or the mimic
context). An high-level explanation about this context is available here: https://github.com/mmaker/ocaml-letsencrypt/blob/c07348604bb94eaab9522fe87e455bb729e5d1d8/src/hTTP_client.ml#L2-L24. Then, if we are able to initiate a connection via mimic
:
git-unix
does for instance) which permits to instantiate a Mirage_flow.S
used by the runtime loop then (for h2
or http/af
)mirage
to provide its own context depending on implementation chosen by the userThis was lost in a recent refactoring, and the tests are all running HTTPS on specified ports that they allocate, so they never caught the default was lost.
When running the following request:
let () =
let _ =
Lwt_main.run @@ Hyper.get "https://medium.com:443/feed/ahrefs/tagged/ocaml"
in
()
I'm seeing the following error:
Fatal error: exception SSL connection() error: error:0A000410:SSL routines::sslv3 alert handshake failure
I don't reproduce this error in any other domain and RSS feeds I've tried to query.
...or else Hyper interprets the response in an ugly way. In any case, Hyper's higher-level helpers should add the header and/or Hyper should document that the header might be required by servers.
This URL
https://login.microsoftonline.com:443/consumers/v2.0/.well-known/openid-configuration
results in 404 unless I patch hyper not to add Transfer-Encoding: Chunked
.
Something like User-Agent: hyper
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.