fn parse(&self, bytes: Vec<u8>) {
        let byte_buffer = std::str::from_utf8(bytes.as_slice()).unwrap();
        log::trace!("{} received: {} bytes {}", self.logtag, byte_buffer.len(), byte_buffer);

        let mut headers = [httparse::EMPTY_HEADER; 16];
        let mut req = httparse::Request::new(&mut headers);
        let res = req.parse(bytes.as_slice()).unwrap();
        if let httparse::Status::Complete(req_len) = res {
            if req.method.is_none() {
                return;
            }
            let body = std::str::from_utf8(&bytes[req_len ..]).unwrap();
            let method = req.method.take().unwrap();
            // broswsers love to ask for all kinds of stuff, we'll not allow it
            if let Some(path) = req.path {
                if path != "/" {
                    log::debug!("{} received path={}, responding 404", self.logtag, path);
                    self.send_zero_len_response("404 Not Found");
                    return;
                }
            }
            // periodic get is a keep-alive
            match method {
                "GET" if self.is_send_form() => self.send_response(None),
                "GET" => self.send_zero_len_response("200 OK"),
                "POST" => match body {
                    "Alice=Init" => self.send_response(Some(AliceState::Init)),
                    "Alice=Start" => self.send_response(Some(AliceState::Start)),
                    "Alice=Stop" => self.send_response(Some(AliceState::Stop)),
                    "Alice=Bye" => self.send_response(Some(AliceState::Bye)),
                    _ => (),
                },
                _ => (),
            }
        }
    }
// This isn't the best of parsers, but its good enough
This isn't the best of parsers, but its good enough
This isn ' t the best of parsers but its good enough
fn parse(&self, bytes: Vec<u8>) {
        let byte_buffer = std::str::from_utf8(bytes.as_slice()).unwrap();
        log::trace!("{} received: {} bytes {}", self.logtag, byte_buffer.len(), byte_buffer);
        let mut headers = [httparse::EMPTY_HEADER; 16];
        let mut req = httparse::Request::new(&mut headers);
        let res = req.parse(bytes.as_slice()).unwrap();
        if let httparse::Status::Complete(req_len) = res {
            if req.method.is_none() {
                return;
            }
            let body = std::str::from_utf8(&bytes[req_len ..]).unwrap();
            let method = req.method.take().unwrap();
            // broswsers love to ask for all kinds of stuff, we'll not allow it
            if let Some(path) = req.path {
                if path != "/" {
                    log::debug!("{} received path={}, responding 404", self.logtag, path);
                    self.send_zero_len_response("404 Not Found");
                    return;
                }
            }
            // periodic get is a keep-alive
            match method {
                "GET" if self.is_send_form() => self.send_response(None),
                "GET" => self.send_zero_len_response("200 OK"),
                "POST" => match body {
                    "Alice=Init" => self.send_response(Some(AliceState::Init)),
                    "Alice=Start" => self.send_response(Some(AliceState::Start)),
                    "Alice=Stop" => self.send_response(Some(AliceState::Stop)),
                    "Alice=Bye" => self.send_response(Some(AliceState::Bye)),
                    _ => (),
                },
                _ => (),
            }
        }
    }
fn parse ( & self , bytes : Vec < u8 > ) { let byte_buffer = std :: str :: from_utf8 ( bytes . as_slice ( ) ) . unwrap ( ) ; log :: trace ! ( " " self logtag byte_buffer len ( ) byte_buffer ) ; let mut headers = [ httparse :: EMPTY_HEADER ; 16 ] ; let mut req = httparse :: Request :: new ( & mut headers ) ; let res = req . parse ( bytes . as_slice ( ) ) . unwrap ( ) ; if let httparse :: Status :: Complete ( req_len ) = res { if req . method . is_none ( ) { return ; } let body = std :: str :: from_utf8 ( & bytes [ req_len .. ] ) . unwrap ( ) ; let method = req . method . take ( ) . unwrap ( ) ; // broswsers love to ask for all kinds of stuff, we'll not allow it if let Some ( path ) = req . path { if path != " " { log :: debug ! ( " " self logtag path ) ; self . send_zero_len_response ( " " ) ; return ; } } // periodic get is a keep-alive match method { " " if self . is_send_form ( ) => self . send_response ( None ) , " " => self . send_zero_len_response ( " " ) , " " => match body { " " => self . send_response ( Some ( AliceState :: Init ) ) , " " => self . send_response ( Some ( AliceState :: Start ) ) , " " => self . send_response ( Some ( AliceState :: Stop ) ) , " " => self . send_response ( Some ( AliceState :: Bye ) ) , _ => ( ) , } , _ => ( ) , } } }
This isn't the best of parsers, but its good enough
This isn ' t the best of parsers but its good enough
&self
bytes
Vec<u8>