Skip to content

Commit

Permalink
std/net/json-rpc: fix param-encoder (#938)
Browse files Browse the repository at this point in the history
  • Loading branch information
fare authored Sep 28, 2023
1 parent 09b3397 commit e816ec3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/std/net/json-rpc-test.ss
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions src/std/net/json-rpc.ss
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,20 @@
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
((POST) ;; POST is the recommended http-method, and the only one supported by many servers.
(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
Expand All @@ -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
Expand Down

0 comments on commit e816ec3

Please sign in to comment.