node: http2 for JSON-RPC API (#33812)
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Keeper Build (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

The reasoning for using the cleartext format here is that the JSON-RPC
API is internal only. Providers which expose it publicly already put it
behind a proxy which handles also the encryption.
This commit is contained in:
Sina M 2026-02-12 10:33:12 +01:00 committed by GitHub
parent 9426444825
commit f2869793df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 0 deletions

View file

@ -138,6 +138,9 @@ func (h *httpServer) start() error {
// Initialize the server.
h.server = &http.Server{Handler: h}
h.server.Protocols = new(http.Protocols)
h.server.Protocols.SetHTTP1(true)
h.server.Protocols.SetUnencryptedHTTP2(true)
if h.timeouts != (rpc.HTTPTimeouts{}) {
CheckTimeouts(&h.timeouts)
h.server.ReadTimeout = h.timeouts.ReadTimeout

View file

@ -593,6 +593,38 @@ func TestHTTPWriteTimeout(t *testing.T) {
})
}
func TestHTTP2H2C(t *testing.T) {
srv := createAndStartServer(t, &httpConfig{}, false, &wsConfig{}, nil)
defer srv.stop()
// Create an HTTP/2 cleartext client.
transport := &http.Transport{}
transport.Protocols = new(http.Protocols)
transport.Protocols.SetUnencryptedHTTP2(true)
client := &http.Client{Transport: transport}
body := strings.NewReader(`{"jsonrpc":"2.0","id":1,"method":"rpc_modules","params":[]}`)
resp, err := client.Post("http://"+srv.listenAddr(), "application/json", body)
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
t.Fatalf("expected status 200, got %d", resp.StatusCode)
}
if resp.Proto != "HTTP/2.0" {
t.Fatalf("expected HTTP/2.0, got %s", resp.Proto)
}
result, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(result), "jsonrpc") {
t.Fatalf("unexpected response: %s", result)
}
}
func apis() []rpc.API {
return []rpc.API{
{