Browse Source

Add initial validator code for HTTP

tags/v0.1.0
Alex Williams 10 months ago
parent
commit
22b6403b07
Signed by: aw GPG Key ID: 19EE4AAA361A7E2C
8 changed files with 721 additions and 0 deletions
  1. +3
    -0
      .gitignore
  2. +14
    -0
      Cargo.lock
  3. +14
    -0
      Cargo.toml
  4. +11
    -0
      src/bin/validate.rs
  5. +533
    -0
      src/lib.rs
  6. +87
    -0
      src/protocols/http.rs
  7. +4
    -0
      src/protocols/mod.rs
  8. +55
    -0
      src/protocols/stomp.rs

+ 3
- 0
.gitignore View File

@ -0,0 +1,3 @@
target/
rust-1*
rustc-1*

+ 14
- 0
Cargo.lock View File

@ -0,0 +1,14 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "boawp-validator"
version = "0.1.0"
dependencies = [
"byteorder",
]
[[package]]
name = "byteorder"
version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"

+ 14
- 0
Cargo.toml View File

@ -0,0 +1,14 @@
[package]
name = "boawp-validator"
version = "0.1.0"
authors = ["Alexander Williams, On-Prem <license@on-premises.com>"]
edition = "2018"
license = "MIT"
description = "BOAWP data validation tool"
homepage = "https://boawp.org"
repository = "https://github.com/boawp/boawp-validator"
keywords = ["boawp", "validator", "tool", "decoder"]
publish = false
[dependencies]
byteorder = "1"

+ 11
- 0
src/bin/validate.rs View File

@ -0,0 +1,11 @@
use boawp_validator::*;
use std::{env, fs::File, io::Error, io::BufReader};
fn main() -> Result<(), Error> {
let args: Vec<String> = env::args().collect();
let file = File::open(&args[1])?;
let mut reader = BufReader::with_capacity(10, file);
let decoded = validate(&mut reader)?;
println!("Decoded: {:?}", decoded);
Ok(())
}

+ 533
- 0
src/lib.rs View File

@ -0,0 +1,533 @@
use byteorder::{BigEndian, ReadBytesExt};
use std::{io::ErrorKind, io::BufReader, io::Cursor, io::Error, io::Read, str::from_utf8, str::from_utf8_unchecked};
pub mod protocols;
// use the 'HTTP' protocol by default
use protocols::http::commands;
use protocols::http::header_names;
type HeaderBuffer<'a> = &'a mut Vec<u8>;
type HeaderLength<'a> = u8;
#[derive(Copy, Clone, Debug)]
pub struct Init {
name: char,
version: char,
lf: char,
}
#[derive(Copy, Clone, Debug)]
pub struct Fixed {
cmd: char,
hlength: u16,
blength: u32,
}
#[derive(Debug)]
pub struct Headers {
headers: Vec<(String, Header)>,
}
#[derive(Debug)]
pub struct Body {
body: Vec<u8>,
}
#[derive(Debug)]
pub struct Frame {
fixed: Fixed,
headers: Headers,
body: Body,
}
#[derive(Debug, PartialEq)]
pub enum Header {
Null,
Boolean(bool),
Integer(Integer),
String(String),
Hexadecimal(String),
Binary(Vec<u8>),
Header(Vec<(String, Header)>),
}
#[derive(Debug, PartialEq)]
pub enum Integer {
Zero(),
One(u8),
Two(i16),
Four(i32),
Eight(i64),
Sixteen(i128),
BigNum(Vec<u8>),
}
impl Header {
fn get_string(buffer: HeaderBuffer, vlength: HeaderLength) -> Result<String, Error> {
let res = String::from_utf8(Header::get_vec(buffer, vlength));
if let Ok(x) = res {
Ok(x)
} else {
Err(Error::new(ErrorKind::InvalidData, "Invalid UTF-8 string"))
}
}
fn get_integer(buffer: HeaderBuffer, vlength: HeaderLength) -> Result<Integer, Error> {
let mut reader = Cursor::new(Header::get_vec(buffer, vlength));
let int = match vlength {
0 => Integer::Zero(),
1 => Integer::One(reader.read_u8()?),
2 => Integer::Two(reader.read_i16::<BigEndian>()?),
4 => Integer::Four(reader.read_i32::<BigEndian>()?),
8 => Integer::Eight(reader.read_i64::<BigEndian>()?),
16 => Integer::Sixteen(reader.read_i128::<BigEndian>()?),
_ => Integer::BigNum(reader.into_inner()),
};
Ok(int)
}
fn get_hexadecimal(buffer: HeaderBuffer, vlength: HeaderLength) -> String {
Header::get_vec(buffer, vlength)
.iter()
.map(|b| format!("{:02x}", b))
.collect()
}
fn get_headers(buffer: HeaderBuffer, vlength: HeaderLength) -> Result<Vec<(String, Header)>, Error> {
Ok(decode_headers(&mut Header::get_vec(buffer, vlength))?)
}
fn get_vec(buffer: HeaderBuffer, vlength: HeaderLength) -> Vec<u8> {
buffer.drain(..vlength as usize).collect()
}
}
pub fn decode_headers(buf: HeaderBuffer) -> Result<Vec<(String, Header)>, Error> {
let mut buffer = buf;
let mut headers = Vec::with_capacity(buffer.len());
match buffer.len() {
1 => return Err(Error::new(ErrorKind::InvalidData, "Invalid headers length '1'")),
2 => return Err(Error::new(ErrorKind::InvalidData, "Invalid headers length '2'")),
3 => return Err(Error::new(ErrorKind::InvalidData, "Invalid headers length '3'")),
_ => {},
}
while buffer.len() > 3 {
let nlength = buffer.remove(0) as u8;
let nvalue = match nlength {
0 => {
return Err(Error::new(ErrorKind::InvalidData, "Invalid header name length"))
}
x if x as usize > buffer.len() => {
return Err(Error::new(ErrorKind::InvalidData, "Invalid header name length"))
}
x if buffer.len() - (x as usize) == 0 => {
return Err(Error::new(ErrorKind::InvalidData, "Invalid header name value '0'"));
}
x if buffer.len() - (x as usize) == 1 => {
return Err(Error::new(ErrorKind::InvalidData, "Invalid header name value '1'"));
}
_ => Header::get_vec(&mut buffer, nlength)
};
let vtype = buffer.remove(0) as char;
let vlength = buffer.remove(0) as u8;
if vlength as usize > buffer.len() {
return Err(Error::new(ErrorKind::InvalidData, "Invalid header value length"));
}
let nvalue_str = match nlength {
1 if header_names(nvalue[0]).is_empty() => {
return Err(Error::new(
ErrorKind::InvalidData,
"Unknown header name value",
))
}
1 => header_names(nvalue[0]).to_string(),
_ if from_utf8(&nvalue).is_err() => {
return Err(Error::new(
ErrorKind::InvalidData,
"Invalid header name UTF-8 encoding",
))
}
_ => unsafe { from_utf8_unchecked(&nvalue).to_string() },
};
match vtype {
'n' | 't' | 'f' if vlength > 0 => {
return Err(Error::new(
ErrorKind::InvalidData,
format!(
"Invalid header value length {} for type {}",
vlength, vtype as char
),
))
}
_ => {}
}
let hvalue = match vtype {
'n' => Header::Null,
't' => Header::Boolean(true),
'f' => Header::Boolean(false),
'i' => Header::Integer(Header::get_integer(&mut buffer, vlength)?),
's' => Header::String(Header::get_string(&mut buffer, vlength)?),
'x' => Header::Hexadecimal(Header::get_hexadecimal(&mut buffer, vlength)),
'b' => Header::Binary(Header::get_vec(&mut buffer, vlength)),
'h' => Header::Header(Header::get_headers(&mut buffer, vlength)?),
_ => return Err(Error::new(ErrorKind::InvalidData, "Unknown header value type")),
};
headers.push((nvalue_str, hvalue));
}
Ok(headers)
}
pub fn decode_fixed_header<R: Read>(reader: &mut R) -> Result<Fixed, Error> {
let mut buffer = [0; 1];
reader.read(&mut buffer)?;
let hlength = reader.read_u16::<BigEndian>()?;
let blength = reader.read_u32::<BigEndian>()?;
let fixed = Fixed {
cmd: buffer[0] as char,
hlength,
blength,
};
match fixed {
f if commands(f.cmd as u8).is_empty() => Err(Error::new(ErrorKind::InvalidData, "Unknown command")),
Fixed { cmd: '\n', hlength: 0, blength: 0 } => Ok(fixed),
Fixed { cmd: '\n', .. } => Err(Error::new(ErrorKind::InvalidData, "Invalid NOOP frame")),
Fixed { .. } => Ok(fixed),
}
}
pub fn decode_frame<R: Read>(reader: &mut R) -> Result<Frame, Error> {
// fixed header
let fixed = decode_fixed_header(reader)?;
// frame headers
let mut buffer = get_frame_data(reader, fixed.hlength as usize)?;
let headers = Headers { headers: decode_headers(&mut buffer)? };
// body
let body = Body { body: get_frame_data(reader, fixed.blength as usize)? };
let frame = Frame { fixed, headers, body };
Ok(frame)
}
pub fn decode_init<R: Read>(reader: &mut R) -> Result<Init, Error> {
let mut buffer = [0; 3];
reader.read(&mut buffer)?;
let init = Init {
name: buffer[0] as char,
version: buffer[1] as char,
lf: buffer[2] as char,
};
if let Init { name: 'B', version: '0', lf: '\n', .. } = init {
Ok(init)
} else {
Err(Error::new(ErrorKind::InvalidData, "Invalid protocol init string"))
}
}
pub fn validate<R: Read>(reader: &mut R) -> Result<(Init, Frame), Error> {
// protocol init
let init = decode_init(reader)?;
// frame
let frame = decode_frame(reader)?;
Ok((init, frame))
}
fn get_frame_data<R: Read>(r: &mut R, len: usize) -> Result<Vec<u8>, Error> {
let mut reader = BufReader::with_capacity(len, r);
let mut buffer: Vec<u8> = vec![0; len]; // allocated on the heap
reader.read(&mut buffer)?;
Ok(buffer)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn _get_static_commands() {
assert!(commands(10).len() > 0);
assert!(commands(33).len() > 0);
}
#[test]
fn _get_static_header_names() {
assert!(header_names(32).len() > 0);
assert!(header_names(65).len() > 0);
}
fn _decode_init() {
let x: [u8; 3] = [66, 48, 10];
let mut reader = BufReader::new(&x[..]);
let init = decode_init(&mut reader).unwrap();
assert_eq!(init.name, 'B');
assert_eq!(init.version, '0');
assert_eq!(init.lf, '\n');
}
#[test]
fn _decode_init_error1() {
let x: [u8; 3] = [65, 48, 10];
let mut reader = BufReader::new(&x[..]);
let res = decode_init(&mut reader);
assert!(res.is_err());
assert_eq!(res.unwrap_err().into_inner().unwrap().to_string(), "Invalid protocol init string");
}
#[test]
fn _decode_init_error2() {
let x: [u8; 3] = [66, 49, 10];
let mut reader = BufReader::new(&x[..]);
let res = decode_init(&mut reader);
assert!(res.is_err());
assert_eq!(res.unwrap_err().into_inner().unwrap().to_string(), "Invalid protocol init string");
}
#[test]
fn _decode_init_error3() {
let x: [u8; 3] = [66, 48, 11];
let mut reader = BufReader::new(&x[..]);
let res = decode_init(&mut reader);
assert!(res.is_err());
assert_eq!(res.unwrap_err().into_inner().unwrap().to_string(), "Invalid protocol init string");
}
#[test]
fn _decode_fixed_header() {
let x: [u8; 7] = [33, 0, 10, 0, 0, 127, 5];
let mut reader = BufReader::new(&x[..]);
let fixed = decode_fixed_header(&mut reader).unwrap();
assert_eq!(fixed.cmd, '!');
assert_eq!(fixed.hlength, 10);
assert_eq!(fixed.blength, 32517);
}
#[test]
fn _decode_fixed_header_noop() {
let x: [u8; 7] = [10, 0, 0, 0, 0, 0, 0];
let mut reader = BufReader::new(&x[..]);
let fixed = decode_fixed_header(&mut reader).unwrap();
assert_eq!(fixed.cmd, '\n');
assert_eq!(fixed.hlength, 0);
assert_eq!(fixed.blength, 0);
}
#[test]
fn _decode_fixed_header_error2() {
let x: [u8; 7] = [10, 0, 0, 0, 0, 0, 5];
let mut reader = BufReader::new(&x[..]);
let res = decode_fixed_header(&mut reader);
assert!(res.is_err());
assert_eq!(res.unwrap_err().into_inner().unwrap().to_string(), "Invalid NOOP frame");
}
#[test]
fn _decode_fixed_header_error3() {
let x: [u8; 7] = [10, 0, 10, 0, 0, 0, 0];
let mut reader = BufReader::new(&x[..]);
let res = decode_fixed_header(&mut reader);
assert!(res.is_err());
assert_eq!(res.unwrap_err().into_inner().unwrap().to_string(), "Invalid NOOP frame");
}
#[test]
fn _decode_fixed_header_error4() {
let x: [u8; 7] = [3, 0, 10, 0, 0, 0, 0];
let mut reader = BufReader::new(&x[..]);
let res = decode_fixed_header(&mut reader);
assert!(res.is_err());
assert_eq!(res.unwrap_err().into_inner().unwrap().to_string(), "Unknown command");
}
#[test]
fn _decode_frame_data() {
let x = vec![1, 70, 120, 4, 159, 134, 208, 129];
let mut reader = BufReader::new(&x[..]);
let res = get_frame_data(&mut reader, 8).unwrap();
assert_eq!(res, [1, 70, 120, 4, 159, 134, 208, 129]);
}
#[test]
fn _get_vec() {
let mut x = vec![1, 2, 3, 4];
let value = Header::get_vec(&mut x, 4);
assert_eq!(value, [1, 2, 3, 4]);
assert_eq!(x, []);
}
#[test]
fn _get_hexadecimal() {
let mut x = vec![66, 79, 65, 87, 80];
let value = Header::get_hexadecimal(&mut x, 5);
assert_eq!(value, "424f415750");
assert_eq!(x, []);
}
#[test]
fn _get_string() {
let mut x = vec![66, 79, 65, 87, 80];
let value = Header::get_string(&mut x, 5).unwrap();
assert_eq!(value, "BOAWP");
assert_eq!(x, []);
}
#[test]
fn _get_string_error() {
let mut x = vec![255, 255];
let value = Header::get_string(&mut x, 2);
assert!(value.is_err());
assert_eq!(value.unwrap_err().into_inner().unwrap().to_string(), "Invalid UTF-8 string");
}
#[test]
fn _get_integer0() {
let mut x = vec![];
let value = Header::get_integer(&mut x, 0).unwrap();
assert_eq!(value, Integer::Zero());
assert_eq!(x, []);
}
#[test]
fn _get_integer1() {
let mut x = vec![127];
let value = Header::get_integer(&mut x, 1).unwrap();
assert_eq!(value, Integer::One(127));
assert_eq!(x, []);
}
#[test]
fn _get_integer2() {
let mut x = vec![127, 127];
let value = Header::get_integer(&mut x, 2).unwrap();
assert_eq!(value, Integer::Two(32639));
assert_eq!(x, []);
}
#[test]
fn _get_integer4() {
let mut x = vec![127, 127, 127, 127];
let value = Header::get_integer(&mut x, 4).unwrap();
assert_eq!(value, Integer::Four(2139062143));
assert_eq!(x, []);
}
#[test]
fn _get_integer8() {
let mut x = vec![127, 127, 127, 127, 127, 127, 127, 127];
let value = Header::get_integer(&mut x, 8).unwrap();
assert_eq!(value, Integer::Eight(9187201950435737471));
assert_eq!(x, []);
}
#[test]
fn _get_integer16() {
let mut x = vec![127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127];
let value = Header::get_integer(&mut x, 16).unwrap();
assert_eq!(value, Integer::Sixteen(169473963133173273960190490760135540607));
assert_eq!(x, []);
}
#[test]
fn _get_integer_bignum() {
let mut x = vec![127, 127, 127, 127, 127, 127, 127, 127, 127, 127];
let value = Header::get_integer(&mut x, 10).unwrap();
assert_eq!(value, Integer::BigNum(vec![127, 127, 127, 127, 127, 127, 127, 127, 127, 127]));
assert_eq!(x, []);
}
#[test]
fn _decode_headers() {
let mut x = vec![1, 65, 115, 4, 72, 84, 84, 80, 1, 66, 105, 8, 255, 255, 255, 255, 255, 255, 127, 255, 1, 67, 110, 0, 1, 68, 116, 0, 1, 69, 102, 0, 1, 70, 120, 4, 159, 134, 208, 129, 9, 114, 101, 99, 117, 114, 115, 105, 118, 101, 104, 16, 1, 72, 120, 4, 159, 134, 208, 129, 1, 73, 115, 4, 116, 101, 115, 116, 4, 116, 101, 115, 116, 115, 0, 9, 114, 101, 99, 117, 114, 115, 105, 118, 101, 104, 16, 5, 104, 101, 108, 108, 111, 110, 0, 5, 119, 111, 114, 108, 100, 110, 0, 9, 109, 121, 45, 99, 117, 115, 116, 111, 109, 115, 4, 116, 101, 115, 116, 4, 97, 108, 101, 120, 110, 0, 11, 98, 105, 110, 97, 114, 121, 45, 116, 101, 120, 116, 98, 4, 115, 114, 113, 112];
let value = decode_headers(&mut x).unwrap();
assert_eq!(value[0], ("protocol".to_string(), Header::String("HTTP".to_string())));
assert_eq!(value[1], ("max-headers".to_string(), Header::Integer(Integer::Eight(-32769))));
assert_eq!(value[2], ("max-body".to_string(), Header::Null));
assert_eq!(value[3], ("max-value".to_string(), Header::Boolean(true)));
assert_eq!(value[4], ("max-int".to_string(), Header::Boolean(false)));
assert_eq!(value[5], ("null".to_string(), Header::Hexadecimal("9f86d081".to_string())));
assert_eq!(value[6], ("recursive".to_string(), Header::Header(vec![("false".to_string(), Header::Hexadecimal("9f86d081".to_string())), ("accept-version".to_string(), Header::String("test".to_string()))])));
assert_eq!(value[7], ("test".to_string(), Header::String("".to_string())));
assert_eq!(value[8], ("recursive".to_string(), Header::Header(vec![("hello".to_string(), Header::Null), ("world".to_string(), Header::Null)])));
assert_eq!(value[9], ("my-custom".to_string(), Header::String("test".to_string())));
assert_eq!(value[10], ("alex".to_string(), Header::Null));
assert_eq!(value[11], ("binary-text".to_string(), Header::Binary(vec![115, 114, 113, 112])));
}
#[test]
fn _decode_headers_error1() {
let mut x = vec![1];
let value = decode_headers(&mut x);
assert!(value.is_err());
assert_eq!(value.unwrap_err().into_inner().unwrap().to_string(), "Invalid headers length '1'");
}
#[test]
fn _decode_headers_error2() {
let mut x = vec![1, 2];
let value = decode_headers(&mut x);
assert!(value.is_err());
assert_eq!(value.unwrap_err().into_inner().unwrap().to_string(), "Invalid headers length '2'");
}
#[test]
fn _decode_headers_error3() {
let mut x = vec![1, 2, 3];
let value = decode_headers(&mut x);
assert!(value.is_err());
assert_eq!(value.unwrap_err().into_inner().unwrap().to_string(), "Invalid headers length '3'");
}
#[test]
fn _decode_headers_error4() {
let mut x = vec![0, 65, 65, 0];
let value = decode_headers(&mut x);
assert!(value.is_err());
assert_eq!(value.unwrap_err().into_inner().unwrap().to_string(), "Invalid header name length");
}
#[test]
fn _decode_headers_error5() {
let mut x = vec![1, 0, 0, 0];
let value = decode_headers(&mut x);
assert!(value.is_err());
assert_eq!(value.unwrap_err().into_inner().unwrap().to_string(), "Unknown header name value");
}
#[test]
fn _decode_headers_error6() {
let mut x = vec![2, 255, 255, 0, 0];
let value = decode_headers(&mut x);
assert!(value.is_err());
assert_eq!(value.unwrap_err().into_inner().unwrap().to_string(), "Invalid header name UTF-8 encoding");
}
#[test]
fn _decode_headers_error7() {
let mut x = vec![1, 65, 110, 1, 22];
let value = decode_headers(&mut x);
assert!(value.is_err());
assert_eq!(value.unwrap_err().into_inner().unwrap().to_string(), "Invalid header value length 1 for type n");
}
#[test]
fn _decode_headers_error8() {
let mut x = vec![1, 65, 116, 1, 22];
let value = decode_headers(&mut x);
assert!(value.is_err());
assert_eq!(value.unwrap_err().into_inner().unwrap().to_string(), "Invalid header value length 1 for type t");
}
#[test]
fn _decode_headers_error9() {
let mut x = vec![1, 65, 102, 1, 22];
let value = decode_headers(&mut x);
assert!(value.is_err());
assert_eq!(value.unwrap_err().into_inner().unwrap().to_string(), "Invalid header value length 1 for type f");
}
#[test]
fn _decode_headers_error10() {
let mut x = vec![1, 65, 0, 0];
let value = decode_headers(&mut x);
assert!(value.is_err());
assert_eq!(value.unwrap_err().into_inner().unwrap().to_string(), "Unknown header value type");
}
#[test]
fn _decode_headers_error11() {
let mut x = vec![5, 65, 104, 3];
let value = decode_headers(&mut x);
assert!(value.is_err());
assert_eq!(value.unwrap_err().into_inner().unwrap().to_string(), "Invalid header name length");
}
#[test]
fn _decode_headers_error12() {
let mut x = vec![2, 97, 98, 98];
let value = decode_headers(&mut x);
assert!(value.is_err());
assert_eq!(value.unwrap_err().into_inner().unwrap().to_string(), "Invalid header name value '1'");
}
#[test]
fn _decode_headers_error13() {
let mut x = vec![3, 97, 98, 98];
let value = decode_headers(&mut x);
assert!(value.is_err());
assert_eq!(value.unwrap_err().into_inner().unwrap().to_string(), "Invalid header name value '0'");
}
#[test]
fn _decode_headers_error14() {
let mut x = vec![3, 97, 98, 98, 104, 5];
let value = decode_headers(&mut x);
assert!(value.is_err());
assert_eq!(value.unwrap_err().into_inner().unwrap().to_string(), "Invalid header value length");
}
}

+ 87
- 0
src/protocols/http.rs View File

@ -0,0 +1,87 @@
// HTTP protocol
pub const fn commands<'a>(n: u8) -> &'a str {
match n {
// BOAWP
10 => "NOOP",
33 => "ERROR",
// HTTP
97 => "GET",
98 => "HEAD",
99 => "POST",
100 => "PUT",
101 => "DELETE",
102 => "CONNECT",
103 => "OPTIONS",
104 => "TRACE",
105 => "PATCH",
_ => "",
}
}
pub const fn header_names<'a>(n: u8) -> &'a str {
match n {
// BOAWP
32 => "noop",
65 => "protocol",
66 => "max-headers",
67 => "max-body",
68 => "max-value",
69 => "max-int",
70 => "null",
71 => "true",
72 => "false",
73 => "accept-version",
74 => "content-type",
75 => "content-encoding",
76 => "date",
77 => "host",
78 => "keepalive",
79 => "server",
80 => "timestamp",
81 => "user-agent",
// HTTP
82 => "accept-charset",
83 => "accept-encoding",
84 => "accept-language",
85 => "accept-ranges",
86 => "accept",
87 => "access-control-allow-origin",
88 => "age",
89 => "allow",
90 => "authorization",
48 => "cache-control",
49 => "content-disposition",
50 => "content-language",
51 => "content-length",
52 => "content-location",
53 => "content-range",
54 => "cookie",
55 => "etag",
56 => "expect",
57 => "expires",
97 => "from",
98 => "if-match",
99 => "if-modified-since",
100 => "if-none-match",
101 => "if-range",
102 => "if-unmodified-since",
103 => "last-modified",
104 => "link",
105 => "location",
106 => "max-forwards",
107 => "proxy-authenticate",
108 => "proxy-authorization",
109 => "range",
110 => "referer",
111 => "refresh",
112 => "retry-after",
113 => "set-cookie",
114 => "strict-transport-security",
115 => "transfer-encoding",
116 => "vary",
117 => "via",
118 => "www-authenticate",
_ => "",
}
}

+ 4
- 0
src/protocols/mod.rs View File

@ -0,0 +1,4 @@
// BOAWP registered protocols
pub mod http;
pub mod stomp;

+ 55
- 0
src/protocols/stomp.rs View File

@ -0,0 +1,55 @@
// STOMP protocol
pub const fn commands<'a>(n: u8) -> &'a str {
match n {
// BOAWP
10 => "NOOP",
33 => "ERROR",
// STOMP
97 => "CONNECT",
98 => "SEND",
99 => "SUBSCRIBE",
100 => "UNSUBSCRIBE",
101 => "ACK",
102 => "NACK",
103 => "BEGIN",
104 => "COMMIT",
105 => "ABORT",
106 => "DISCONNECT",
107 => "CONNECTED",
108 => "MESSAGE",
109 => "RECEIPT",
110 => "ERROR",
111 => "AUTH",
112 => "PING",
113 => "CHALLENGE",
114 => "PONG",
_ => "",
}
}
pub const fn header_names<'a>(n: u8) -> &'a str {
match n {
// BOAWP
32 => "noop",
65 => "protocol",
66 => "max-headers",
67 => "max-body",
68 => "max-value",
69 => "max-int",
70 => "null",
71 => "true",
72 => "false",
73 => "accept-version",
74 => "content-type",
75 => "content-encoding",
76 => "date",
77 => "host",
78 => "keepalive",
79 => "server",
80 => "timestamp",
81 => "user-agent",
// STOMP
_ => "",
}
}

Loading…
Cancel
Save