Browse Source

Interpret requests

master
Garrit Franke 4 years ago
parent
commit
d85229ae1e
  1. 61
      Cargo.lock
  2. 1
      Cargo.toml
  3. 15
      src/main.rs

61
Cargo.lock generated

@ -1,5 +1,66 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "idna"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9"
dependencies = [
"matches",
"unicode-bidi",
"unicode-normalization",
]
[[package]]
name = "matches"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
[[package]]
name = "percent-encoding"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
name = "taurus"
version = "0.0.1"
dependencies = [
"url",
]
[[package]]
name = "tinyvec"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "238ce071d267c5710f9d31451efec16c5ee22de34df17cc05e56cbc92e967117"
[[package]]
name = "unicode-bidi"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
dependencies = [
"matches",
]
[[package]]
name = "unicode-normalization"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fb19cf769fa8c6a80a162df694621ebeb4dafb606470b2b2fce0be40a98a977"
dependencies = [
"tinyvec",
]
[[package]]
name = "url"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb"
dependencies = [
"idna",
"matches",
"percent-encoding",
]

1
Cargo.toml

@ -7,3 +7,4 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
url = "2.1.1"

15
src/main.rs

@ -1,6 +1,9 @@
extern crate url;
use std::io::Read;
use std::io::Write;
use std::net::TcpListener;
use url::Url;
fn main() {
// 1965 is the standard port for gemini
@ -18,8 +21,16 @@ fn main() {
println!("Could not read from stream: {}", e)
}
if let Err(e) = stream.write(b"HELLO") {
println!("Could not write to stream: {}", e);
let mut raw_request = String::from_utf8_lossy(&buffer[..]).to_mut().to_owned();
if raw_request.starts_with("gemini://") {
raw_request.push_str("gemini://");
}
if let Ok(request) = Url::parse(&raw_request) {
if let Err(e) = stream.write(request.path().as_bytes()) {
println!("Could not write to stream: {}", e);
}
}
}
}

Loading…
Cancel
Save