What is the proper way of serializing HTTP request headers (http::HeaderMap
) into JSON in Rust?
I am implementing an AWS Lambda function and I would like to have a simple echo function for debugging.
use lambda_http::{lambda, IntoResponse, Request};
use lambda_runtime::{error::HandlerError, Context};
use log::{self, info};
use simple_logger;
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
simple_logger::init_with_level(log::Level::Debug)?;
info!("Starting up...");
lambda!(handler);
return Ok(());
}
fn handler(req: Request, ctx: Context) -> Result<impl IntoResponse, HandlerError> {
Ok(format!("{}", req.headers()).into_response())
}
Is there an easy way to convert req.headers()
to JSON and return?