@@ -50,6 +50,41 @@ pub fn merge_schema(a: &mut Value, b: &Value) {
5050 }
5151}
5252
53+ /// Merge schema and update some keys
54+ ///
55+ /// This is a thin wrapper around `merge_schema` that additionally:
56+ /// 1. Copies the value of the header key `requested-with-ajax` (all lower-case) into the
57+ /// variants `Requested-With-Ajax` (Pascal-Case) and `REQUESTED-WITH-AJAX` (upper-case),
58+ /// or vice-versa, depending on which variant is present in the incoming schema.
59+ /// 2. Overwrites the top-level `version` field with the compile-time constant `VERSION`.
60+ ///
61+ /// The three header variants are created so that downstream code can read the header
62+ /// regardless of the casing rules enforced by the environment (HTTP servers, proxies, etc.).
63+ ///
64+ /// # Arguments
65+ /// * `a` – the target `Value` (must be an `Object`) that will receive the merge result.
66+ /// * `b` – the source `Value` (must be an `Object`) whose contents are merged into `a`.
67+ ///
68+ pub fn update_schema ( a : & mut Value , b : & Value ) {
69+ merge_schema ( a, b) ;
70+
71+ // Different environments may ignore or add capitalization in headers
72+ let headers = & b[ "data" ] [ "CONTEXT" ] [ "HEADERS" ] ;
73+ if headers. get ( "requested-with-ajax" ) . is_some ( ) {
74+ a[ "data" ] [ "CONTEXT" ] [ "HEADERS" ] [ "Requested-With-Ajax" ] = b[ "data" ] [ "CONTEXT" ] [ "HEADERS" ] [ "requested-with-ajax" ] . clone ( ) ;
75+ a[ "data" ] [ "CONTEXT" ] [ "HEADERS" ] [ "REQUESTED-WITH-AJAX" ] = b[ "data" ] [ "CONTEXT" ] [ "HEADERS" ] [ "requested-with-ajax" ] . clone ( ) ;
76+ } else if headers. get ( "Requested-With-Ajax" ) . is_some ( ) {
77+ a[ "data" ] [ "CONTEXT" ] [ "HEADERS" ] [ "requested-with-ajax" ] = b[ "data" ] [ "CONTEXT" ] [ "HEADERS" ] [ "Requested-With-Ajax" ] . clone ( ) ;
78+ a[ "data" ] [ "CONTEXT" ] [ "HEADERS" ] [ "REQUESTED-WITH-AJAX" ] = b[ "data" ] [ "CONTEXT" ] [ "HEADERS" ] [ "Requested-With-Ajax" ] . clone ( ) ;
79+ } else if headers. get ( "REQUESTED-WITH-AJAX" ) . is_some ( ) {
80+ a[ "data" ] [ "CONTEXT" ] [ "HEADERS" ] [ "requested-with-ajax" ] = b[ "data" ] [ "CONTEXT" ] [ "HEADERS" ] [ "REQUESTED-WITH-AJAX" ] . clone ( ) ;
81+ a[ "data" ] [ "CONTEXT" ] [ "HEADERS" ] [ "Requested-With-Ajax" ] = b[ "data" ] [ "CONTEXT" ] [ "HEADERS" ] [ "REQUESTED-WITH-AJAX" ] . clone ( ) ;
82+ }
83+
84+ // Update version
85+ a[ "version" ] = VERSION . to_string ( ) . to_string ( ) . into ( ) ;
86+ }
87+
5388/// Extract same level blocks positions.
5489///
5590/// ```text
0 commit comments