Skip to content

Commit 124e097

Browse files
author
Boleslav Březovský
committed
FEAT: Updated to latest version
1 parent c59b72e commit 124e097

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

http-tools.red

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ make-url: function [
157157
set value set-word! (append args rejoin [form value #"="])
158158
set value [any-word! | any-string! | number!] (
159159
if word? value [value: get :value]
160-
append args rejoin [value #"&"]
160+
append args rejoin [percent/encode form value #"&"]
161161
)
162162
]
163163
]
@@ -193,13 +193,17 @@ send-request: function [
193193
] [
194194
if verbose [
195195
print ["SEND-REQUEST to" link ", method:" method]
196+
print ["header:" mold args]
196197
]
197198
header: copy #() ; NOTE: CLEAR causes crash later!!!
198199
if with [extend header args]
199200
if auth [
201+
if verbose [print [auth-type mold auth-data]]
200202
switch auth-type [
201203
Basic [
202-
Authorization: (rejoin [auth-type space enbase rejoin [first auth-data #":" second auth-data]])
204+
extend header compose [
205+
Authorization: (rejoin [auth-type space enbase rejoin [first auth-data #":" second auth-data]])
206+
]
203207
]
204208
OAuth [
205209
; TODO: OAuth 1 (see Twitter API)
@@ -212,15 +216,20 @@ send-request: function [
212216
]
213217
]
214218
]
215-
data: reduce [method body-of header]
219+
; Make sure all values are strings
220+
body: body-of header
221+
forall body [body: next body body/1: form body/1]
222+
data: reduce [method body]
216223
; if content [append data content]
217-
unless content [content: ""]
224+
if any [
225+
not content
226+
method = 'GET
227+
] [content: ""]
218228
append data content
219229
if verbose [
220230
print [
221231
"Link:" link newline
222232
"Data:" mold data newline
223-
"print here"
224233
]
225234
]
226235
reply: write/info link data
@@ -304,7 +313,7 @@ percent: context [
304313
reserved-chars: union charset "!*'();:@&=+$,/?#[]" charset "%" ; RFCs are stupid
305314
unreserved-chars: charset [#"A" - #"Z" #"a" - #"z" #"0" - #"9" "-_.~"]
306315
encode: function [
307-
string [string!]
316+
string [any-string!]
308317
] [
309318
value: none
310319
chars: unreserved-chars

0 commit comments

Comments
 (0)