Initial commit
This commit is contained in:
commit
ebdd92c64c
|
@ -0,0 +1,14 @@
|
|||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
debug/
|
||||
target/
|
||||
|
||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||
Cargo.lock
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "gytheio"
|
||||
version = "0.1.0"
|
||||
authors = ["g1n <g1n@ttm.sh>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
|
@ -0,0 +1,30 @@
|
|||
use std::fs;
|
||||
use std::io::prelude::*;
|
||||
use std::net::TcpListener;
|
||||
use std::net::TcpStream;
|
||||
|
||||
fn main() {
|
||||
let listener = TcpListener::bind("127.0.0.1:3000").unwrap();
|
||||
|
||||
for stream in listener.incoming() {
|
||||
let stream = stream.unwrap();
|
||||
handle_connection(stream);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_connection(mut stream: TcpStream) {
|
||||
let mut buffer = [0; 1024];
|
||||
|
||||
stream.read(&mut buffer).unwrap();
|
||||
|
||||
let contents = fs::read_to_string("index.gmi").unwrap();
|
||||
let response = format!(
|
||||
"2 text/gemini\r\n{}",
|
||||
contents
|
||||
);
|
||||
|
||||
stream.write(response.as_bytes()).unwrap();
|
||||
stream.flush().unwrap();
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue