Skip to content

Commit

Permalink
Create a headers module
Browse files Browse the repository at this point in the history
  • Loading branch information
connorslade committed Sep 24, 2023
1 parent 18b15f1 commit 7f85102
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 40 deletions.
43 changes: 13 additions & 30 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,21 @@

[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=394493528&machine=basicLinux32gb&location=EastUs&devcontainer_path=.devcontainer%2Fdevcontainer.json)

## Basic
## Applications

Basic examples give you a nice and simple first look into using afire.
Run `cargo r --example basic` to use the example picker menu thing.
You can also run a specific example with `cargo r --example basic -- <EXAMPLE_NAME>`.
The source code for each basic example can be found within the `basic` subdirectory in a file with the same name as the example.
### [Basic](basic)

| Name | Description |
| ------------------------------ | ---------------------------------------------------------------------- |
| basic | Start a basic web server that serves static text. |
| serve_file | Serve a file from the local file system. |
| routing | Learn about routing priority and create a 404 page |
| data | Send data to server with a Query String, Path parameters and Form Data |
| header | Make and Read Headers to send extra data |
| path_param | Use path parameters on a route |
| state | Add a server-wide state and use stateful routes |
| cookie | Read and Write cookies to the client |
| error_handling | Catch panics in routes and middleware |
| serve_static | Staticky serve a whole directory |
| middleware (show state access) | Use Middleware to log requests and modify responses |
| logging | Log requests to a file or console |
| rate_limit | Add a rate limit to your server |
| threading | Use a thread pool to handle requests |
| trace | Use afire's built-in logging system |
Shows the very basics of afire:

## Application
- Creating routes
- Creating and using Middleware
- Server state
- Accepting JSON requests
- Accepting
- Responding with JSOn

These are more complete examples, still not a full web app through.
For more complete web apps you can reference the [Things Built with afire](https://connorcode.com/writing/afire#things-built-with-afire) section on my website.
To run these application examples you can use this command `cargo r --example application_<EXAMPLE_NAME>`.
### [Pastebin](paste_bin)

| Name | Description |
| ---------- | --------------------------------------------------- |
| paste_bin | A very simple in memory paste bin system |
| quote_book | A delightfully 90s website to store and view quotes |
A simple pastebin, but a more complete example.
Shows how to use a database, render templates, create api routes, accept form data, handle shutdowns, and more.
I have actually made a real pastebin with afire ([plaster-box](https://github.com/Basicprogrammer10/plaster-box)), but because I started on it so long ago I prefer some of the practices used in this example.
2 changes: 1 addition & 1 deletion examples/paste_bin/src/routes/post_paste.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::error;

use afire::{
extensions::{RedirectResponse, RouteShorthands},
header::Vary,
headers::Vary,
route::RouteContext,
Content, Context, HeaderName, Query, Server, Status,
};
Expand Down
2 changes: 1 addition & 1 deletion lib/extensions/redirect.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Shorthand methods for sending redirects.

use crate::{header::Location, Context, Status};
use crate::{headers::Location, Context, Status};

/// Types of redirects that can be sent.
/// This type can be passed to [`RedirectResponse::redirect_type`] to send a redirect with a specific status code, or to the plain [`Context::header`] where you will need to manually define the 'Location' header.
Expand Down
2 changes: 1 addition & 1 deletion lib/extensions/serve_static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{borrow::Cow, fs::File, sync::Arc};

use crate::{
error::{HandleError, Result},
header::ContentType,
headers::ContentType,
middleware::{MiddleResult, Middleware},
Error, HeaderName, Request, Response, Status,
};
Expand Down
2 changes: 1 addition & 1 deletion lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub use self::{
cookie::{Cookie, SetCookie},
error::Error,
header::{Header, HeaderName},
http::{cookie, header, multipart},
http::{cookie, header, headers, multipart},
method::Method,
middleware::Middleware,
proto::{server_sent_events, websocket},
Expand Down
2 changes: 1 addition & 1 deletion lib/proto/http/content_type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{header::ContentType, Header};
use crate::{headers::ContentType, Header};

use super::mime::{self, Mime};

Expand Down
4 changes: 1 addition & 3 deletions lib/proto/http/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

use std::{
borrow::Cow,
fmt::{self, Display},
fmt::{self},
ops::{Deref, DerefMut},
};

Expand All @@ -41,10 +41,8 @@ use crate::{
};

mod header_name;
mod impls;

pub use header_name::HeaderName;
pub use impls::*;

/// Http header.
/// Has a name and a value.
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions lib/proto/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod content_type;
pub mod cookie;
pub mod date;
pub mod header;
pub mod headers;
pub mod method;
pub mod mime;
pub mod multipart;
Expand Down
2 changes: 1 addition & 1 deletion lib/proto/server_sent_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use std::{
use crate::{
context::ContextFlag,
error::Result,
header::{CacheControl, ContentType},
headers::{CacheControl, ContentType},
internal::sync::{ForceLockMutex, SingleBarrier},
Context, Error, Header, Request, Response,
};
Expand Down
2 changes: 1 addition & 1 deletion lib/proto/websocket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use crate::{
consts::BUFF_SIZE,
context::ContextFlag,
error::Result,
header::Connection,
headers::Connection,
internal::{
encoding::{base64, sha1},
sync::ForceLockMutex,
Expand Down

0 comments on commit 7f85102

Please sign in to comment.