Skip to content

Commit

Permalink
No parameters for POST
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Corry committed Mar 7, 2024
1 parent f6671b2 commit 96e1fc6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/client.toit
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ class Client:
The $method is usually one of $GET, $POST, $PUT, $DELETE.
The returned $RequestOutgoing should be sent with $RequestOutgoing.send.
The $parameters argument is used to encode parameters in the request path.
It should not be used for a $POST request. See instead $post_form, which
encodes the parameters in the body as expected for a POST request.
*/
new_request method/string -> RequestOutgoing
--host/string
Expand All @@ -178,6 +182,7 @@ class Client:
--parameters/Map?=null
--headers/Headers?=null
--use_tls/bool?=null:
if method == POST and parameters: throw "INVALID_ARGUMENT"
parsed := parse_ host port path use_tls parameters --web_socket=false
request := null
try_to_reuse_ parsed: | connection |
Expand Down Expand Up @@ -425,11 +430,10 @@ class Client:
--port/int?=null
--path/string="/"
--headers/Headers?=null
--parameters/Map?=null
--content_type/string?=null
--follow_redirects/bool=true
--use_tls/bool?=null:
parsed := parse_ host port path use_tls parameters --web_socket=false
parsed := parse_ host port path use_tls null --web_socket=false
return post_ data parsed --headers=headers --content_type=content_type --follow_redirects=follow_redirects

parse_ uri/string --web_socket/bool -> ParsedUri_:
Expand Down Expand Up @@ -536,12 +540,11 @@ class Client:
--port/int?=null
--path/string="/"
--headers/Headers?=null
--parameters/Map?=null
--follow_redirects/bool=true
--use_tls/bool?=null:
// TODO(florian): we should create the json dynamically.
encoded := json.encode object
parsed := parse_ host port path use_tls parameters --web_socket=false
parsed := parse_ host port path use_tls null --web_socket=false
return post_ encoded parsed --headers=headers --content_type="application/json" --follow_redirects=follow_redirects

/**
Expand Down Expand Up @@ -588,10 +591,9 @@ class Client:
--port/int?=null
--path/string="/"
--headers/Headers?=null
--parameters/Map?=null
--follow_redirects/bool=true
--use_tls/bool?=null:
parsed := parse_ host port path use_tls parameters --web_socket=false
parsed := parse_ host port path use_tls null --web_socket=false
return post_form_ map parsed --headers=headers --follow_redirects=follow_redirects

url_encode_ map/Map -> ByteArray:
Expand Down

0 comments on commit 96e1fc6

Please sign in to comment.