Lines
0 %
Functions
use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
ResponseParserError,
};
pub struct UrlHandlers;
pub type UrlHandlersResponse = Vec<String>;
impl Command for UrlHandlers {
type Response = UrlHandlersResponse;
const COMMAND: &'static str = "urlhandlers";
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
debug_assert!(parts.next().is_none());
Ok((Request::UrlHandlers, ""))
}
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> {
let parts: Vec<_> = parts.into();
let mut url_handlers = Vec::new();
for (key, value) in parts.into_iter() {
if key != "handler" {
return Err(ResponseParserError::UnexpectedProperty(key));
let value = match value {
GenericResponseValue::Text(value) => value,
GenericResponseValue::Binary(_) => {
return Err(ResponseParserError::UnexpectedPropertyType(
"handler", "Binary",
))
url_handlers.push(value.to_string());
Ok(url_handlers)