-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using CurlHTTP | ||
|
||
const colors = [:light_red, :light_green, :light_yellow] | ||
function make_handler(i::Int) | ||
return ch -> Base.printstyled("Handle $i: ", String(take!(ch)), "\n"; color=colors[i]) | ||
end | ||
|
||
pool = map(1:3) do i | ||
curl = CurlEasy(url="https://postman-echo.com/post?val=$i", method=CurlHTTP.POST) | ||
requestBody = """{"testName":"test_multiPOST","value":$i}""" | ||
|
||
curl.userdata[:index] = i # userdata is a Dict to store anything you want | ||
curl.userdata[:channel] = Channel(make_handler(i), Inf) | ||
|
||
CurlHTTP.curl_setup_request(curl, requestBody, ["Content-Type: application/json"]; | ||
data_channel = curl.userdata[:channel] | ||
) | ||
return curl | ||
end | ||
|
||
# Set up tasks to handle the data channels before calling curl_execute | ||
|
||
multi = CurlMulti(pool) | ||
res = curl_execute(multi) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using CurlHTTP | ||
|
||
const NoBody = "" | ||
|
||
curl = CurlEasy( | ||
url="https://postman-echo.com/get?foo=bar&baz=zod", | ||
method=CurlHTTP.GET, | ||
) | ||
|
||
databuffer = UInt8[] | ||
|
||
res, http_status, errormessage = curl_execute(curl, NoBody, ["X-Custom-Header: ding"]) do d | ||
append!(databuffer, d) | ||
end | ||
|
||
data = JSON3.read(databuffer, Dict{String, Any}) | ||
|
||
|
||
# We can reuse this connection | ||
res, http_status, errormessage = curl_execute(curl, NoBody, ["X-Custom-Header: ding2"]; url="https://postman-echo.com/get?foo=bear&baz=zeroed") | ||
data = JSON3.read(curl.userdata[:databuffer], Dict{String, Any}) | ||
|
||
curl_cleanup(curl) # Optional - will run on finalizer |