-- Leo's gemini proxy
-- Connecting to typed-hole.org:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
commit 8b0cadf34db9cc45b393da1cdb9ab106226771f0
Author: Julien Blanchard <julien@sideburns.eu>
Date: Mon Aug 12 11:20:38 2019 +0200
Add final statuses
diff --git a/src/header.rs b/src/header.rs
deleted file mode 100644
index f57293c..0000000
--- a/src/header.rs
+++ /dev/null
@@ -1,37 +0,0 @@
-extern crate regex;
-use regex::Regex;
-
-use std::str::FromStr;
-
-#[derive(Debug)]
-pub struct Header {
- code: i16,
- meta: String,
-}
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
-pub struct ParseError;
-
-const HEADER_REGEX: &str = r"^(\d{1,3})[ \t](.*)$";
-
-impl FromStr for Header {
- type Err = ParseError;
-
- // Parses a &str into an instance of 'Header'
- fn from_str(line: &str) -> Result<Self, Self::Err> {
- let header_regexp = Regex::new(HEADER_REGEX).unwrap();
-
- match header_regexp.captures(&line) {
- Some(caps) => {
- let code_str = caps.get(1).map_or("", |m| m.as_str());
- let meta_str = caps.get(2).map_or("", |m| m.as_str());
-
- let code: i16 = code_str.parse().expect("2");
- let meta = meta_str.to_string();
-
- Ok(Header { code, meta })
- }
- None => Err(ParseError),
- }
- }
-}
diff --git a/src/main.rs b/src/main.rs
index 22171e5..2685e91 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -15,8 +15,8 @@ use cursive::Cursive;
use std::str::FromStr;
use url::Url;
-mod header;
-use header::Header;
+mod status;
+use status::Status;
mod link;
use link::Link;
@@ -142,8 +142,8 @@ fn draw_content(s: &mut Cursive, url: Url, content: String) {
container.set_title(url.as_str());
main_view.clear();
- match Header::from_str(content.lines().next().unwrap()) {
- Ok(_header) => {}
+ match Status::from_str(content.lines().next().unwrap()) {
+ Ok(_status) => {}
Err(_) => {}
}
diff --git a/src/status.rs b/src/status.rs
new file mode 100644
index 0000000..11fa614
--- /dev/null
+++ b/src/status.rs
@@ -0,0 +1,84 @@
+extern crate regex;
+use regex::Regex;
+
+use std::str::FromStr;
+
+#[derive(Debug)]
+pub enum Status {
+ Input(String),
+ Success(String),
+ SuccessEndOfClientCertificateSession(String),
+ RedirectTemporary(String),
+ RedirectPermanent(String),
+ TemporaryFailure(String),
+ ServerUnavailable(String),
+ CGIError(String),
+ ProxyError(String),
+ SlowDown(String),
+ PermanentFailure(String),
+ NotFound(String),
+ Gone(String),
+ ProxyRequestRefused(String),
+ BadRequest(String),
+ ClientCertificateRequired(String),
+ TransientCertificateRequired(String),
+ AuthorisedCertificatedRequired(String),
+ CertificateNotAccepted(String),
+ FutureCertificateRejected(String),
+ ExpiredCertificateRejected(String),
+ Unknown(String),
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
+pub struct ParseError;
+
+const STATUS_REGEX: &str = r"^(\d{1,3})[ \t](.*)$";
+
+impl FromStr for Status {
+ type Err = ParseError;
+
+ // Parses a &str into an instance of 'Header'
+ fn from_str(line: &str) -> Result<Self, Self::Err> {
+ let status_regexp = Regex::new(STATUS_REGEX).unwrap();
+
+ match status_regexp.captures(&line) {
+ Some(caps) => {
+ let code_str = caps.get(1).map_or("", |m| m.as_str());
+ let meta_str = caps.get(2).map_or("", |m| m.as_str());
+
+ let code: i16 = code_str.parse().expect("2");
+ let meta = meta_str.to_string();
+
+ Ok(make_status(code, meta))
+ }
+ None => Err(ParseError),
+ }
+ }
+}
+
+fn make_status(code: i16, meta: String) -> Status {
+ match code {
+ 10 => Status::Input(meta),
+ 20 => Status::Success(meta),
+ 21 => Status::SuccessEndOfClientCertificateSession(meta),
+ 30 => Status::RedirectTemporary(meta),
+ 31 => Status::RedirectPermanent(meta),
+ 40 => Status::TemporaryFailure(meta),
+ 41 => Status::ServerUnavailable(meta),
+ 42 => Status::CGIError(meta),
+ 43 => Status::ProxyError(meta),
+ 44 => Status::SlowDown(meta),
+ 50 => Status::PermanentFailure(meta),
+ 51 => Status::NotFound(meta),
+ 52 => Status::Gone(meta),
+ 53 => Status::ProxyRequestRefused(meta),
+ 59 => Status::BadRequest(meta),
+ 60 => Status::ClientCertificateRequired(meta),
+ 61 => Status::TransientCertificateRequired(meta),
+ 62 => Status::AuthorisedCertificatedRequired(meta),
+ 63 => Status::CertificateNotAccepted(meta),
+ 64 => Status::FutureCertificateRejected(meta),
+ 65 => Status::ExpiredCertificateRejected(meta),
+ _ => Status::Unknown(meta)
+ }
+}
---
Served by Pollux Gemini Server.
-- Response ended
-- Page fetched on Sun May 19 11:24:18 2024