rainmaker_components/http/
base.rs1use std::net::{IpAddr, Ipv4Addr};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4pub enum HttpMethod {
5 GET,
6 POST,
7}
8
9#[derive(Debug)]
10pub struct HttpRequest {
11 pub(crate) method: HttpMethod,
12 pub(crate) data: Vec<u8>,
14 pub(crate) url: String,
15}
16
17impl HttpRequest {
18 pub fn method(&self) -> HttpMethod {
19 self.method
20 }
21
22 pub fn data(&mut self) -> Vec<u8> {
23 self.data.clone()
24 }
25
26 pub fn url(&self) -> String {
27 self.url.clone()
28 }
29}
30
31#[derive(Debug)]
32pub struct HttpResponse {
33 data: Vec<u8>,
34}
35
36impl HttpResponse {
37 pub fn from_bytes<D>(inp: D) -> Self
38 where
39 D: Into<Vec<u8>>,
40 {
41 HttpResponse { data: inp.into() }
42 }
43
44 pub fn get_bytes_vectored(&self) -> Vec<u8> {
45 self.data.clone()
46 }
47}
48
49#[derive(Debug)]
50pub struct HttpConfiguration {
51 pub port: u16,
52 pub addr: IpAddr,
53}
54
55impl Default for HttpConfiguration {
56 fn default() -> Self {
57 HttpConfiguration {
58 #[cfg(target_os = "espidf")]
59 port: 80,
60 #[cfg(target_os = "linux")]
62 port: 8080,
63 addr: IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
64 }
65 }
66}
67
68pub struct HttpServer<T>(pub(crate) T);