fn populate_json(value: &mut Json, context: &Context) {
    // create the regexes once
    lazy_static! {
        static ref RE_REQ_HEADER: Regex = Regex::new(r"%\{REQUEST_HEADER\((.*)\)}" ).unwrap();
        static ref RE_RES_HEADER: Regex = Regex::new(r"%\{RESPONSE_HEADER\((.*)\)}" ).unwrap();
    }

    match value {
        Json::Array(arr) => {
            for v in arr {
                populate_json(v, &context);
            }
        }
        Json::Object(obj) => {
            for (_, v) in obj {
                populate_json(v, &context);
            }
        }
        Json::String(s) => {
            match s.as_str() {
                "%{UUID()}" => *s = uuid(),
                "%{DURATION(NS)}" => *s = duration(context.start, context.end, "ns").unwrap(),
                "%{DURATION(MS)}" => *s = duration(context.start, context.end, "ms").unwrap(),
                "%{DURATION(S)}" => *s = duration(context.start, context.end, "s").unwrap(),
                "%{METHOD}" => *s = context.req_head.method.to_string(),
                "%{URI}" => *s = context.req_head.uri.to_string(),
                "%{STATUS_CODE}" => *value = Json::Number(Number::from(context.res_head.status.as_u16())),
                _ => {
                    // To handle HTTP headers, we need to use the regexes. Since the key cannot be
                    // known ahead of time.
                    match RE_REQ_HEADER.captures(s) {
                        Some(cap) => {
                            *s = header(context.req_head.headers(), &cap[1]);
                        }
                        None => {}
                    };
                    match RE_RES_HEADER.captures(s) {
                        Some(cap) => {
                            *s = header(context.res_head.headers(), &cap[1]);
                        }
                        None => {}
                    };
                }
            }
        }
        _ => (),
    }
}
/// Populate the JSON with the context information. Some of the fields may have values that need to
/// be calculated at runtime.
Populate the JSON with the context information. Some of the fields may have values that need to
be calculated at runtime.
Populate the JSON with the context information . Some of the fields may have values that need to be calculated at runtime .
fn populate_json(value: &mut Json, context: &Context) {
    // create the regexes once
    lazy_static! {
        static ref RE_REQ_HEADER: Regex = Regex::new(r"%\{REQUEST_HEADER\((.*)\)}" ).unwrap();
        static ref RE_RES_HEADER: Regex = Regex::new(r"%\{RESPONSE_HEADER\((.*)\)}" ).unwrap();
    }
    match value {
        Json::Array(arr) => {
            for v in arr {
                populate_json(v, &context);
            }
        }
        Json::Object(obj) => {
            for (_, v) in obj {
                populate_json(v, &context);
            }
        }
        Json::String(s) => {
            match s.as_str() {
                "%{UUID()}" => *s = uuid(),
                "%{DURATION(NS)}" => *s = duration(context.start, context.end, "ns").unwrap(),
                "%{DURATION(MS)}" => *s = duration(context.start, context.end, "ms").unwrap(),
                "%{DURATION(S)}" => *s = duration(context.start, context.end, "s").unwrap(),
                "%{METHOD}" => *s = context.req_head.method.to_string(),
                "%{URI}" => *s = context.req_head.uri.to_string(),
                "%{STATUS_CODE}" => *value = Json::Number(Number::from(context.res_head.status.as_u16())),
                _ => {
                    // To handle HTTP headers, we need to use the regexes. Since the key cannot be
                    // known ahead of time.
                    match RE_REQ_HEADER.captures(s) {
                        Some(cap) => {
                            *s = header(context.req_head.headers(), &cap[1]);
                        }
                        None => {}
                    };
                    match RE_RES_HEADER.captures(s) {
                        Some(cap) => {
                            *s = header(context.res_head.headers(), &cap[1]);
                        }
                        None => {}
                    };
                }
            }
        }
        _ => (),
    }
}
fn populate_json ( value : & mut Json , context : & Context ) { // create the regexes once lazy_static ! { static ref RE_REQ_HEADER Regex Regex new ( r"%\{REQUEST_HEADER\((.*)\)}" ) unwrap ( ) static ref RE_RES_HEADER Regex Regex new ( r"%\{RESPONSE_HEADER\((.*)\)}" ) unwrap ( ) } match value { Json :: Array ( arr ) => { for v in arr { populate_json ( v , & context ) ; } } Json :: Object ( obj ) => { for ( _ , v ) in obj { populate_json ( v , & context ) ; } } Json :: String ( s ) => { match s . as_str ( ) { " " => * s = uuid ( ) , " " => * s = duration ( context . start , context . end , " " ) . unwrap ( ) , " " => * s = duration ( context . start , context . end , " " ) . unwrap ( ) , " " => * s = duration ( context . start , context . end , " " ) . unwrap ( ) , " " => * s = context . req_head . method . to_string ( ) , " " => * s = context . req_head . uri . to_string ( ) , " " => * value = Json :: Number ( Number :: from ( context . res_head . status . as_u16 ( ) ) ) , _ => { // To handle HTTP headers, we need to use the regexes. Since the key cannot be // known ahead of time. match RE_REQ_HEADER . captures ( s ) { Some ( cap ) => { * s = header ( context . req_head . headers ( ) , & cap [ 1 ] ) ; } None => { } } ; match RE_RES_HEADER . captures ( s ) { Some ( cap ) => { * s = header ( context . res_head . headers ( ) , & cap [ 1 ] ) ; } None => { } } ; } } } _ => ( ) , } }
Populate the JSON with the context information.
Populate the JSON with the context information .
value
&mut Json
context
&Context
value
&mut Json
context
&Context