diff --git a/src/std/net/json-rpc-test.ss b/src/std/net/json-rpc-test.ss index cda0451d8..1e274e0f7 100644 --- a/src/std/net/json-rpc-test.ss +++ b/src/std/net/json-rpc-test.ss @@ -37,6 +37,9 @@ (def (q . a) (apply query http-method: http-method a)) (check (q "ping" '(42)) => '("pong" (42))) (check (q "add" '(1 2 3 4)) => 10) + (check (q "add" '("23" "19") + param-encoder: (cut map string->number <>) + result-decoder: number->string) => "42") (check-e (q "ping" 42) -32602) ;; invalid-params (check-e (q "meaning-of-life") -32601)) ;; method-not-found (test-case "basic handlers with POST" diff --git a/src/std/net/json-rpc.ss b/src/std/net/json-rpc.ss index 709d35171..b339160c8 100644 --- a/src/std/net/json-rpc.ss +++ b/src/std/net/json-rpc.ss @@ -138,8 +138,9 @@ log: (log #f) http-method: (http-method 'POST)) (def id (id-counter)) + (def encoded-params (param-encoder params)) (when log - (log [json-rpc: server-url method: method params: params id: id])) + (log [json-rpc: server-url method: method params: encoded-params id: id])) (def response-bytes (request-response-bytes (case http-method @@ -147,10 +148,10 @@ (let (data (try (json-object->bytes (json-rpc-request jsonrpc: json-rpc-version - method: method params: params id: id)) + method: method params: encoded-params id: id)) (catch (e) (raise/context - (MalformedRequest method: method params: params + (MalformedRequest method: method params: encoded-params message: (error-message e)))))) (http-post server-url auth: auth @@ -174,7 +175,7 @@ ((GET) (set! id (number->string id)) ;; GET method wants string id. (let* ((base64-params - (try (u8vector->base64-string (json-object->bytes params)) + (try (u8vector->base64-string (json-object->bytes encoded-params)) (catch (e) (raise/context (MalformedRequest method: method params: params