https://github.com/JuliaWeb/LibCURL.jl
Julia wrapper for libcurl
https://github.com/JuliaWeb/LibCURL.jl
Last synced: 2 months ago
JSON representation
Julia wrapper for libcurl
- Host: GitHub
- URL: https://github.com/JuliaWeb/LibCURL.jl
- Owner: JuliaWeb
- License: other
- Created: 2013-03-18T04:21:34.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2026-04-03T12:46:27.000Z (2 months ago)
- Last Synced: 2026-04-03T17:26:18.670Z (2 months ago)
- Language: Julia
- Homepage:
- Size: 183 KB
- Stars: 35
- Watchers: 11
- Forks: 30
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-julia-security - LibCURL.jl - Julia wrapper for libcurl, useful for custom HTTP request crafting. (Web Security / HTTP and Web Frameworks)
README
LibCURL.jl
==========
*Julia wrapper for libCURL*
[](https://github.com/JuliaWeb/LibCURL.jl/actions/workflows/ci.yml)
[](https://codecov.io/github/JuliaWeb/LibCURL.jl)
---
This is a simple Julia wrapper around http://curl.haxx.se/libcurl/ generated using [Clang.jl](https://github.com/ihnorton/Clang.jl). Please see the [libcurl API documentation](https://curl.haxx.se/libcurl/c/) for help on how to use this package.
### Example (fetch a URL)
```julia
using LibCURL
# init a curl handle
curl = curl_easy_init()
# set the URL and request to follow redirects
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com")
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1)
# setup the callback function to recv data
function curl_write_cb(curlbuf::Ptr{Cvoid}, s::Csize_t, n::Csize_t, p_ctxt::Ptr{Cvoid})
sz = s * n
data = Array{UInt8}(undef, sz)
ccall(:memcpy, Ptr{Cvoid}, (Ptr{Cvoid}, Ptr{Cvoid}, UInt64), data, curlbuf, sz)
println("recd: ", String(data))
sz::Csize_t
end
c_curl_write_cb = @cfunction(curl_write_cb, Csize_t, (Ptr{Cvoid}, Csize_t, Csize_t, Ptr{Cvoid}))
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, c_curl_write_cb)
# execute the query
res = curl_easy_perform(curl)
println("curl url exec response : ", res)
# retrieve HTTP code
http_code = Array{Clong}(undef, 1)
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, http_code)
println("httpcode : ", http_code)
# release handle
curl_easy_cleanup(curl)
```
### Binaries
This package uses the [LibCURL_jll](https://github.com/JuliaBinaryWrappers/libCURL_jll.jl) binary package to install compiled libCURL binaries on all supported platforms. The following products are defined in the jll
* `libcurl`: A `LibraryProduct` referencing the shared library
* `curl`: An `ExecutableProduct` referencing the binary
This package also uses the [MozillaCACerts_jll](https://github.com/JuliaBinaryWrappers/MozillaCACerts_jll.jl) package to supply the Mozilla CA root certificate bundle. Note that the `cacert` symbol is re-exported from this package for ease of use.
* `cacert`: A `FileProduct` referencing the Mozilla CA certificate bundle
### SSL certificates
Making SSL/TLS connections usually needs access to a CA certificate to validate peers. The Mozilla CA bundle can be used via this package. To use this certificate bundle, set the following option:
```julia
curl_easy_setopt(curl, CURLOPT_CAINFO, LibCURL.cacert)
```