Initial commit

This commit is contained in:
g1n 2021-07-09 05:23:09 +00:00
commit ebdd92c64c
4 changed files with 53 additions and 0 deletions

14
.gitignore vendored Normal file
View File

@ -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

9
Cargo.toml Normal file
View File

@ -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
README.md Normal file
View File

30
src/main.rs Normal file
View File

@ -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();
}