Browse Source

Send absolute URLs to servers

openbsd
Julien Blanchard 7 years ago
parent
commit
d977bae21d
  1. 2
      Cargo.lock
  2. 5
      src/content.rs
  3. 2
      src/history.rs
  4. 2
      src/link.rs
  5. 4
      src/main.rs

2
Cargo.lock generated

@ -20,7 +20,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "asuka"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"cursive 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",

5
src/content.rs

@ -5,7 +5,6 @@ use std::net::TcpStream;
pub fn get_data(url: &url::Url) -> Result<String, String> {
let host = url.host_str().unwrap();
let path = url.path();
let urlf = format!("{}:1965", host);
let mut builder = TlsConnector::builder();
@ -21,8 +20,8 @@ pub fn get_data(url: &url::Url) -> Result<String, String> {
match mstream {
Ok(mut stream) => {
let url_with_path = format!("{}\r\n", path);
stream.write_all(url_with_path.as_bytes()).unwrap();
let url = format!("{}\r\n", url);
stream.write_all(url.as_bytes()).unwrap();
let mut res = vec![];
stream.read_to_end(&mut res).unwrap();
Ok(String::from_utf8_lossy(&res).to_string())

2
src/history.rs

@ -25,7 +25,7 @@ pub fn get_current_host() -> Option<String> {
match history.last() {
Some(current_url) => {
match current_url.host_str() {
Some(host) => Some(host.to_owned()),
Some(host) => Some(String::from(host)),
None => None
}
}

2
src/link.rs

@ -15,7 +15,7 @@ pub enum Link {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ParseError;
const LINK_REGEX: &str = r"^=>\s(\S*)\s*(.*)?$";
const LINK_REGEX: &str = r"^=>\s?(\S*)\s*(.*)?$";
impl FromStr for Link {
type Err = ParseError;

4
src/main.rs

@ -154,8 +154,8 @@ fn draw_content(s: &mut Cursive, url: Url, content: String) {
match link {
Link::Http(_url, label) => {
let mut formatted = StyledString::new();
let gopher_label = format!("[WWW] {}", label);
formatted.append(StyledString::styled(gopher_label, Effect::Italic));
let www_label = format!("[WWW] {}", label);
formatted.append(StyledString::styled(www_label, Effect::Italic));
main_view.add_item(formatted, String::from("0"))
},

Loading…
Cancel
Save