1 // Copyright 2024 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 /// # Http Proxy Rewriter 16 17 #[cfg(test)] 18 mod tests { 19 use httparse::Header; 20 21 #[test] rewrite_test()22 fn rewrite_test() { 23 let mut headers = [httparse::EMPTY_HEADER; 64]; 24 let _ = rewrite(&mut headers); 25 } 26 rewrite(headers: &mut [Header]) -> Result<(), Box<dyn std::error::Error>>27 fn rewrite(headers: &mut [Header]) -> Result<(), Box<dyn std::error::Error>> { 28 let mut req = httparse::Request::new(headers); 29 30 let buf = b"GET /index.html HTTP/1.1\r\nHost"; 31 assert!(req.parse(buf)?.is_partial()); 32 33 // a partial request, so we try again once we have more data 34 let buf = b"GET /index.html HTTP/1.1\r\nHost: example.domain\r\n\r\n"; 35 assert!(req.parse(buf)?.is_complete()); 36 37 println!("headers: {:?}", req.headers); 38 println!("request: {:?}", req); 39 Ok(()) 40 } 41 } 42