-- Leo's gemini proxy
-- Connecting to typed-hole.org:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
commit 992aca0d44f49b2826003ab20fcbdd83548ceb80
Author: Julien Blanchard <julien@sideburns.eu>
Date: Thu Jan 2 18:36:48 2020 +0100
Fix gopher URLs, add a / where needed
diff --git a/src/gopher/client.rs b/src/gopher/client.rs
index 36b307d..894b083 100644
--- a/src/gopher/client.rs
+++ b/src/gopher/client.rs
@@ -1,6 +1,6 @@
+use percent_encoding::percent_decode;
use std::io::{Read, Write};
use std::net::TcpStream;
-use percent_encoding::percent_decode;
use crate::Protocol;
@@ -11,9 +11,11 @@ pub fn get_data<T: Protocol>(url: T) -> Result<(Option<Vec<u8>>, Vec<u8>), Strin
match TcpStream::connect(&urlf) {
Ok(mut stream) => {
+ let path = url.path().to_string().split_off(1);
+
let mut url = match url.query() {
- Some(query) => format!("{}?{}\r\n", url.path(), query),
- None => format!("{}\r\n", url.path())
+ Some(query) => format!("{}?{}\n", path, query),
+ None => format!("{}\n", path),
};
let url = if url.starts_with("/0/") || url.starts_with("/1/") {
@@ -23,6 +25,7 @@ pub fn get_data<T: Protocol>(url: T) -> Result<(Option<Vec<u8>>, Vec<u8>), Strin
};
let url = percent_decode(url.as_bytes()).decode_utf8().unwrap();
+
stream.write_all(url.as_bytes()).unwrap();
let mut res = vec![];
stream.read_to_end(&mut res).unwrap();
diff --git a/src/gopher/link.rs b/src/gopher/link.rs
index 7785575..4f91e6a 100644
--- a/src/gopher/link.rs
+++ b/src/gopher/link.rs
@@ -26,11 +26,23 @@ impl FromStr for Link {
let host = els.next();
if let Some(host) = host {
- if let Some(path) = path {
+ if let Some(p) = path {
let mut text = String::from(label);
text.remove(0);
- let url = Url::parse(&format!("gopher://{}{}", host, path)).unwrap();
- Ok(Link::Gopher(url, text))
+
+ let path = if p.starts_with('/') {
+ p.to_string()
+ } else {
+ format!("/{}", p)
+ };
+
+ match Url::parse(&format!("gopher://{}{}", host, path)) {
+ Ok(url) => Ok(Link::Gopher(url, text)),
+ Err(e) => {
+ println!("ERR {:?}", e);
+ Err(ParseError)
+ }
+ }
} else {
Err(ParseError)
}
@@ -48,7 +60,7 @@ impl FromStr for Link {
let url = String::from(url);
match make_link(url, label) {
Some(link) => Ok(link),
- None => Err(ParseError)
+ None => Err(ParseError),
}
} else {
Err(ParseError)
@@ -63,7 +75,7 @@ impl FromStr for Link {
match make_link(url, label) {
Some(link) => Ok(link),
- None => Err(ParseError)
+ None => Err(ParseError),
}
} else {
Err(ParseError)
---
Served by Pollux Gemini Server.
-- Response ended
-- Page fetched on Sun May 19 05:27:36 2024