Crate gload

Source
Expand description

§gload

A client library for the Gemini network protocol, designed mainly for use in the gload CLI.

There are two functions, fetch and fetch_sync; each makes a TLS request to a Gemini capsule and returns the response. Their behavior is the same, except fetch_sync is not async and cannot be used in a tokio runtime.

§Example

use gload::{Request, fetch};
use mediatype::MediaType;
use url_macro::url;

let request = Request::new(url!("gemini://git.average.name/AverageHelper/gload")).unwrap();
let response = fetch(request, Default::default()).await.unwrap();

// Check the response status
assert!(response.is_successful()); // `true` if the status is 20

// Parse the response header
let meta = response.meta().unwrap(); // e.g. "text/gemini; charset=UTF-8; lang=en", always nonempty if `Some`
let mime_type = MediaType::parse(meta).unwrap();
assert_eq!(mime_type.essence().ty.as_str(), "text");
assert_eq!(mime_type.essence().subty.as_str(), "gemini");

// Read the response body
let body = response.body().unwrap(); // always non-empty if `Some`
let text = str::from_utf8(body).unwrap(); // e.g. "Hello, world!" with or without trailing newlines

There is also a sync API.

let response = fetch_sync(request, Default::default()).unwrap();

§Crate Features

The gload crate exposes only one build feature.

  • logging (enabled by default) — Enables logging features in the gload lib. This is always set on builds of the CLI binary, but may be disabled for the lib by using --no-default-features or setting default-features = false in Cargo.toml. Enabling this feature makes gload depend on the log crate and output interesting messages at debug! and trace! level. Also enables the logging feature on the rustls crate.

Re-exports§

pub use net::FetchOptions;
pub use net::fetch;
pub use net::fetch_sync;
pub use request::Request;
pub use response::Response;

Modules§

net
This software is licensed as described in the file LICENSE, which you should have received as part of this distribution.
request
This software is licensed as described in the file LICENSE, which you should have received as part of this distribution.
response
This software is licensed as described in the file LICENSE, which you should have received as part of this distribution.
tls
This software is licensed as described in the file LICENSE, which you should have received as part of this distribution.