This function is only for testing purposes. It starts a local httpuv server to echo the request body and content type in the response.
curl_echo(handle, port = find_port(), progress = interactive(), file = NULL)
find_port(range = NULL)
if(require('httpuv')){
h <- new_handle(url = 'https://hb.cran.dev/post')
handle_setform(h, foo = "blabla", bar = charToRaw("test"),
myfile = form_file(system.file("DESCRIPTION"), "text/description"))
# Echo the POST request data
formdata <- curl_echo(h)
# Show the multipart body
cat(rawToChar(formdata$body))
# Parse multipart
webutils::parse_http(formdata$body, formdata$content_type)
}
#> Loading required package: httpuv
#> --------------------------36c8d91a3a48d134
#> Content-Disposition: form-data; name="foo"
#>
#> blabla
#> --------------------------36c8d91a3a48d134
#> Content-Disposition: form-data; name="bar"
#>
#> test
#> --------------------------36c8d91a3a48d134
#> Content-Disposition: form-data; name="myfile"; filename="DESCRIPTION"
#> Content-Type: text/description
#>
#> Package: base
#> Version: 4.4.1
#> Priority: base
#> Title: The R Base Package
#> Author: R Core Team and contributors worldwide
#> Maintainer: R Core Team <do-use-Contact-address@r-project.org>
#> Contact: R-help mailing list <r-help@r-project.org>
#> Description: Base R functions.
#> License: Part of R 4.4.1
#> Suggests: methods
#> Enhances: chron, date, round
#> Built: R 4.4.1; ; 2024-08-22 01:53:23 UTC; unix
#>
#> --------------------------36c8d91a3a48d134--
#> $foo
#> $foo$value
#> [1] 62 6c 61 62 6c 61
#>
#> $foo$content_disposition
#> [1] "form-data"
#>
#> $foo$name
#> [1] "foo"
#>
#>
#> $bar
#> $bar$value
#> [1] 74 65 73 74
#>
#> $bar$content_disposition
#> [1] "form-data"
#>
#> $bar$name
#> [1] "bar"
#>
#>
#> $myfile
#> $myfile$value
#> [1] 50 61 63 6b 61 67 65 3a 20 62 61 73 65 0a 56 65 72 73 69 6f 6e 3a 20 34 2e
#> [26] 34 2e 31 0a 50 72 69 6f 72 69 74 79 3a 20 62 61 73 65 0a 54 69 74 6c 65 3a
#> [51] 20 54 68 65 20 52 20 42 61 73 65 20 50 61 63 6b 61 67 65 0a 41 75 74 68 6f
#> [76] 72 3a 20 52 20 43 6f 72 65 20 54 65 61 6d 20 61 6e 64 20 63 6f 6e 74 72 69
#> [101] 62 75 74 6f 72 73 20 77 6f 72 6c 64 77 69 64 65 0a 4d 61 69 6e 74 61 69 6e
#> [126] 65 72 3a 20 52 20 43 6f 72 65 20 54 65 61 6d 20 3c 64 6f 2d 75 73 65 2d 43
#> [151] 6f 6e 74 61 63 74 2d 61 64 64 72 65 73 73 40 72 2d 70 72 6f 6a 65 63 74 2e
#> [176] 6f 72 67 3e 0a 43 6f 6e 74 61 63 74 3a 20 52 2d 68 65 6c 70 20 6d 61 69 6c
#> [201] 69 6e 67 20 6c 69 73 74 20 3c 72 2d 68 65 6c 70 40 72 2d 70 72 6f 6a 65 63
#> [226] 74 2e 6f 72 67 3e 0a 44 65 73 63 72 69 70 74 69 6f 6e 3a 20 42 61 73 65 20
#> [251] 52 20 66 75 6e 63 74 69 6f 6e 73 2e 0a 4c 69 63 65 6e 73 65 3a 20 50 61 72
#> [276] 74 20 6f 66 20 52 20 34 2e 34 2e 31 0a 53 75 67 67 65 73 74 73 3a 20 6d 65
#> [301] 74 68 6f 64 73 0a 45 6e 68 61 6e 63 65 73 3a 20 63 68 72 6f 6e 2c 20 64 61
#> [326] 74 65 2c 20 72 6f 75 6e 64 0a 42 75 69 6c 74 3a 20 52 20 34 2e 34 2e 31 3b
#> [351] 20 3b 20 32 30 32 34 2d 30 38 2d 32 32 20 30 31 3a 35 33 3a 32 33 20 55 54
#> [376] 43 3b 20 75 6e 69 78 0a
#>
#> $myfile$content_disposition
#> [1] "form-data"
#>
#> $myfile$content_type
#> [1] "text/description"
#>
#> $myfile$name
#> [1] "myfile"
#>
#> $myfile$filename
#> [1] "DESCRIPTION"
#>
#>