-
Notifications
You must be signed in to change notification settings - Fork 15
/
http2.clj
36 lines (31 loc) · 2.06 KB
/
http2.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
;; Copyright © 2019 State Street Bank and Trust Company. All rights reserved
;;
;; SPDX-License-Identifier: Apache-2.0
(ns protojure.grpc.client.providers.http2
"Implements the [GRPC-HTTP2](https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md) protocol for clients"
(:require [protojure.internal.grpc.client.providers.http2.core :as core]
[protojure.internal.grpc.client.providers.http2.jetty :as jetty]
[protojure.grpc.codec.compression :refer [builtin-codecs]]
[promesa.core :as p]
[lambdaisland.uri :as lambdaisland]
[clojure.tools.logging :as log]))
(defn connect
"
Connects the client to a [GRPC-HTTP2](https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md) compatible server
#### Parameters
A map with the following entries:
| Value | Type | Default | Description |
|--------------------|----------|-------------------------------------------------------------------------------------|
| **uri** | _String_ | n/a | The URI of the GRPC server |
| **codecs** | _map_ | [[protojure.grpc.codec.core/builtin-codecs]] | Optional custom codecs |
| **content-coding** | _String_ | nil | The encoding to use on request data |
| **max-frame-size** | _UInt32_ | 16384 | The maximum HTTP2 DATA frame size |
#### Return value
A promise that, on success, evaluates to an instance of [[api/Provider]].
_(api/disconnect)_ should be used to release any resources when the connection is no longer required.
"
[{:keys [uri codecs content-coding max-frame-size] :or {codecs builtin-codecs max-frame-size 16384} :as params}]
(log/debug "Connecting with GRPC-HTTP2:" params)
(let [{:keys [host port]} (lambdaisland/uri uri)]
(-> (jetty/connect {:host host :port (Integer/parseInt port)})
(p/then #(core/->Http2Provider % uri codecs content-coding max-frame-size)))))