1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! A crate for dealing with the Gemini (and Mercury) protocol
//!
//! This crate is split into four parts:
//! - [`gemtext`]
//! - [`url`]
//! - [`protocol`]
//! - [`request`]
//!
//! The [`gemtext`] module is used purely for the parsing of gemtext.
//! The [`protocol`] module is used for accessing and parsing various structures to implement the
//! gemini protocol. This module does not use networking
//! The [`request`] module is used for actually making requests using [`std::net`]. This can be
//! disabled by disabling the feature flag `net`.
//! The [`url`] module is used for manipulating URLs and only contains the areas of the URL specification
//! that Gemini requires.
//!
//! # Example
//! ```no_run
//! use gmi::*;
//! use std::convert::TryFrom;
//! fn main() -> Result<(), request::RequestError> {
//! let test_url = "gemini://gemini.circumlunar.space";
//! let mut test_url = url::Url::try_from(test_url).unwrap();
//! println!("Making response with URL: {}", test_url);
//! loop {
//! let response = request::make_request(&test_url)?;
//! match response.status {
//! protocol::StatusCode::Redirect(c) => {
//! println!("Redirect! Code: {} with meta {}", c, response.meta);
//! test_url = url::Url::try_from(response.meta.as_str()).unwrap();
//! println!("New URL: {}", test_url);
//! }
//! protocol::StatusCode::Success(c) => {
//! println!("Success! Code: {} with MIME type: {}", c, response.meta);
//! println!("{}", String::from_utf8_lossy(&response.data));
//! break;
//! },
//! s => panic!("Unknown status code: {:?}", s),
//! }
//! }
//!
//! return Ok(())
//! }
//! ```
/*
#[cfg(test)]
mod tests {
#[test]
fn test() {
use std::io::prelude::*;
let mut stream = std::net::TcpStream::connect("oppen.digital:1963").unwrap();
stream.write(b"mercury://oppen.digital/index.gmi").unwrap();
let mut stream_data = [0;1024];
stream.read(&mut stream_data).unwrap();
let resp = crate::req_resp::Response::parse_string(&stream_data).unwrap();
panic!("{}", String::from_utf8_lossy(&resp.data).into_owned());
}
}
*/