-- Leo's gemini proxy
-- Connecting to typed-hole.org:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
commit 7f50a34f8511a22683c880cb0b1dc869c764eb5a
Author: Julien Blanchard <julien@sideburns.eu>
Date: Fri Jan 17 16:32:36 2020 +0100
[gopher] show selector in URL bar, some fixes
diff --git a/src/gopher/client.rs b/src/gopher/client.rs
index 36833b3..ec4afb3 100644
--- a/src/gopher/client.rs
+++ b/src/gopher/client.rs
@@ -22,20 +22,15 @@ pub fn get_data<T: Protocol>(url: T) -> Result<(Option<Vec<u8>>, Vec<u8>), Strin
match socket {
Some(socket) => match TcpStream::connect_timeout(&socket, Duration::new(5, 0)) {
Ok(mut stream) => {
- let mut url_s = url.path().to_string();
- let path = if url_s.starts_with('/') {
- url_s.split_off(1)
- } else {
- url_s
- };
+ let path = url.path().to_string();
let mut url = match url.query() {
Some(query) => format!("{}?{}\n", path, query),
None => format!("{}\n", path),
};
- let url = if url.starts_with("0/") || url.starts_with("1/") {
- url.split_off(1)
+ let url = if url.starts_with("/0/") || url.starts_with("/1/") {
+ url.split_off(2)
} else {
url
};
diff --git a/src/gopher/link.rs b/src/gopher/link.rs
index e9eb5ea..2e2a352 100644
--- a/src/gopher/link.rs
+++ b/src/gopher/link.rs
@@ -29,7 +29,7 @@ impl FromStr for Link {
if let Some(host) = host {
if let Some(p) = path {
let mut text = String::from(label);
- text.remove(0);
+ let selector = text.remove(0);
let path = if p.starts_with('/') {
p.to_string()
@@ -38,7 +38,7 @@ impl FromStr for Link {
};
if let Some(port) = port {
- match Url::parse(&format!("gopher://{}:{}{}", host, port, path)) {
+ match Url::parse(&format!("gopher://{}:{}/{}{}", host, port, selector, path)) {
Ok(url) => Ok(Link::Gopher(url, text)),
Err(e) => {
println!("ERR {:?}", e);
@@ -62,7 +62,8 @@ impl FromStr for Link {
if let Some(url) = url {
let mut label = String::from(label);
label.remove(0);
- let url = String::from(url);
+ let mut url = String::from(url);
+ let url = url.split_off(4);
match make_link(url, label) {
Some(link) => Ok(link),
None => Err(ParseError),
diff --git a/src/gopher/parser.rs b/src/gopher/parser.rs
index 107deba..d2076ad 100644
--- a/src/gopher/parser.rs
+++ b/src/gopher/parser.rs
@@ -1,5 +1,5 @@
-use std::str::FromStr;
use crate::colors::*;
+use std::str::FromStr;
pub enum TextElement {
@@ -17,27 +17,32 @@ impl FromStr for TextElement {
// Parses a &str into an instance of 'TextElement'
fn from_str(line: &str) -> Result<TextElement, ParseError> {
- if line.starts_with('0') || line.starts_with('1') {
- Ok(TextElement::LinkItem(colors::cleanup(line)))
- } else if line.starts_with('i') {
- let mut els = line.split('\t');
- let text = els.next().expect("");
- let mut text = String::from(text);
- text.remove(0);
- Ok(TextElement::Text(colors::colorize(&text)))
- } else if line.starts_with('h') {
- Ok(TextElement::ExternalLinkItem(colors::cleanup(line)))
- } else if line.starts_with('I') {
- let mut els = line.split('\t');
- let text = els.next().expect("");
- let mut text = String::from(text);
- text.remove(0);
- Ok(TextElement::Image(colors::cleanup(&text)))
- } else if line.contains("://") {
- if line.contains("gopher://") {
- Ok(TextElement::LinkItem(String::from(line)))
- } else if line.contains("http://") || line.contains("https://") {
- Ok(TextElement::ExternalLinkItem(String::from(line)))
+ let els = line.split('\t');
+ if els.count() >= 2 {
+ if line.starts_with('0') || line.starts_with('1') {
+ Ok(TextElement::LinkItem(colors::cleanup(line)))
+ } else if line.starts_with('i') {
+ let mut els = line.split('\t');
+ let text = els.next().expect("");
+ let mut text = String::from(text);
+ text.remove(0);
+ Ok(TextElement::Text(colors::colorize(&text)))
+ } else if line.starts_with('h') {
+ Ok(TextElement::ExternalLinkItem(colors::cleanup(line)))
+ } else if line.starts_with('I') {
+ let mut els = line.split('\t');
+ let text = els.next().expect("");
+ let mut text = String::from(text);
+ text.remove(0);
+ Ok(TextElement::Image(colors::cleanup(&text)))
+ } else if line.contains("://") {
+ if line.contains("gopher://") {
+ Ok(TextElement::LinkItem(String::from(line)))
+ } else if line.contains("http://") || line.contains("https://") {
+ Ok(TextElement::ExternalLinkItem(String::from(line)))
+ } else {
+ Ok(TextElement::Text(colors::colorize(line)))
+ }
} else {
Ok(TextElement::Text(colors::colorize(line)))
}
---
Served by Pollux Gemini Server.
-- Response ended
-- Page fetched on Sun May 19 04:56:58 2024