Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_net/src/http/handler.rs

2.2 KiB, 48 runs

created by r1870400018:575, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1use crate::{
2 http::{
3 fields::HeaderFields,
4 msg::HttpMessage,
5 loc::HttpLocator,
6 },
7};
8
9use oxedyne_fe2o3_core::prelude::*;
10use oxedyne_fe2o3_iop_crypto::enc::Encrypter;
11use oxedyne_fe2o3_iop_db::api::Database;
12use oxedyne_fe2o3_iop_hash::api::Hasher;
13use oxedyne_fe2o3_jdat::id::NumIdDat;
14
15use std::{
16 net::SocketAddr,
17 sync::{
18 Arc,
19 RwLock,
20 },
21};
22
23
24pub trait WebHandler:
25 Clone
26 + std::fmt::Debug
27 + Send
28 + Sync
29{
30 /// Handle a `GET`.
31 ///
32 /// `peer` is the address the request arrived from. A handler that cannot
33 /// see who it is talking to cannot audit a failed login, attribute an
34 /// abusive request, or refuse one address while serving another -- so the
35 /// address is passed in rather than left to be reconstructed from headers
36 /// a client controls.
37 fn handle_get<
38 const SIDL: usize,
39 const UIDL: usize,
40 SID: NumIdDat<SIDL> + 'static,
41 UID: NumIdDat<UIDL> + 'static,
42 ENC: Encrypter,
43 KH: Hasher,
44 DB: Database<UIDL, UID, ENC, KH>,
45 >(
46 &self,
47 loc: HttpLocator,
48 response: Option<HttpMessage>,
49 body: Vec<u8>,
50 req_headers: Arc<HeaderFields>,
51 db: Option<(Arc<RwLock<DB>>, UID)>,
52 sid_opt: &Option<SID>,
53 peer: SocketAddr,
54 id: &String,
55 )
56 -> impl std::future::Future<Output = Outcome<Option<HttpMessage>>> + Send;
57
58 /// Handle a `POST`. See [`WebHandler::handle_get`] for `peer`.
59 fn handle_post<
60 const SIDL: usize,
61 const UIDL: usize,
62 SID: NumIdDat<SIDL> + 'static,
63 UID: NumIdDat<UIDL> + 'static,
64 ENC: Encrypter,
65 KH: Hasher,
66 DB: Database<UIDL, UID, ENC, KH>,
67 >(
68 &self,
69 loc: HttpLocator,
70 response: Option<HttpMessage>,
71 body: Vec<u8>,
72 req_headers: Arc<HeaderFields>,
73 db: Option<(Arc<RwLock<DB>>, UID)>,
74 sid_opt: &Option<SID>,
75 peer: SocketAddr,
76 id: &String,
77 )
78 -> impl std::future::Future<Output = Outcome<Option<HttpMessage>>> + Send;
79}