fn handle_reports(mut req: Request) -> Result<(), Error> {
    // Parse the beacon reports from the request JSON body using serde_json.
    // If successful, bind the reports to the `reports` variable,
    // optionally transform and typecheck the payload, and log.
    let reports = req.take_body_json::<Vec<Report<ReportBody>>>()?;

    // Extract information about the client from the downstream request,
    // such as the User-Agent and IP address.
    let client_user_agent = req.get_header_str(header::USER_AGENT).unwrap_or("");
    let client_ip = req.get_client_ip_addr().expect("should have client IP");

    // Construct a new `ClientData` structure from the IP and User Agent.
    let client_data = ClientData::new(client_ip, client_user_agent)?;

    // Generate a list of reports to be logged by mapping over each raw beacon
    // payload, merging it with the `ClientData` from above and transform it
    // to a `LogLine`.
    // We assume that the input is an array, to allow the client to sent multiple
    // reports at once. This is always the case for reports sent out-of-band
    // through the Reporting API, e.g., network errors, CSP violations, browser
    // interventions, and feature policy violations.
    let logs: Vec<LogLine<ReportBody>> = reports
        .into_iter()
        .map(|report| LogLine::new(report, client_data.clone()))
        .filter_map(Result::ok)
        .collect();

    // Create a handle to the upstream logging endpoint that we want to emit
    // the reports to.
    let mut endpoint = Endpoint::from_name("reports");

    // Loop over each log line serializing it back to JSON and write it to
    // the logging endpoint.
    for log in logs.iter() {
        serde_json::to_writer(&mut endpoint, &log)?;
    }

    Ok(())
}
/// Handle reports.
///
/// It attempts to extract the beacon reports from the POST request body and maps
/// over each report adding additional information before emitting a log line
/// to the `reports` logging endpoint if valid.
Handle reports.
It attempts to extract the beacon reports from the POST request body and maps
over each report adding additional information before emitting a log line
to the `reports` logging endpoint if valid.
Handle reports . It attempts to extract the beacon reports from the POST request body and maps over each report adding additional information before emitting a log line to the ` reports ` logging endpoint if valid .
fn handle_reports(mut req: Request) -> Result<(), Error> {
    // Parse the beacon reports from the request JSON body using serde_json.
    // If successful, bind the reports to the `reports` variable,
    // optionally transform and typecheck the payload, and log.
    let reports = req.take_body_json::<Vec<Report<ReportBody>>>()?;
    // Extract information about the client from the downstream request,
    // such as the User-Agent and IP address.
    let client_user_agent = req.get_header_str(header::USER_AGENT).unwrap_or("");
    let client_ip = req.get_client_ip_addr().expect("should have client IP");
    // Construct a new `ClientData` structure from the IP and User Agent.
    let client_data = ClientData::new(client_ip, client_user_agent)?;
    // Generate a list of reports to be logged by mapping over each raw beacon
    // payload, merging it with the `ClientData` from above and transform it
    // to a `LogLine`.
    // We assume that the input is an array, to allow the client to sent multiple
    // reports at once. This is always the case for reports sent out-of-band
    // through the Reporting API, e.g., network errors, CSP violations, browser
    // interventions, and feature policy violations.
    let logs: Vec<LogLine<ReportBody>> = reports
        .into_iter()
        .map(|report| LogLine::new(report, client_data.clone()))
        .filter_map(Result::ok)
        .collect();
    // Create a handle to the upstream logging endpoint that we want to emit
    // the reports to.
    let mut endpoint = Endpoint::from_name("reports");
    // Loop over each log line serializing it back to JSON and write it to
    // the logging endpoint.
    for log in logs.iter() {
        serde_json::to_writer(&mut endpoint, &log)?;
    }
    Ok(())
}
fn handle_reports ( mut req : Request ) -> Result < ( ) , Error > { // Parse the beacon reports from the request JSON body using serde_json. // If successful, bind the reports to the `reports` variable, // optionally transform and typecheck the payload, and log. let reports = req . take_body_json :: < Vec < Report < ReportBody > > > ( ) ? ; // Extract information about the client from the downstream request, // such as the User-Agent and IP address. let client_user_agent = req . get_header_str ( header :: USER_AGENT ) . unwrap_or ( " " ) ; let client_ip = req . get_client_ip_addr ( ) . expect ( " " ) ; // Construct a new `ClientData` structure from the IP and User Agent. let client_data = ClientData :: new ( client_ip , client_user_agent ) ? ; // Generate a list of reports to be logged by mapping over each raw beacon // payload, merging it with the `ClientData` from above and transform it // to a `LogLine`. // We assume that the input is an array, to allow the client to sent multiple // reports at once. This is always the case for reports sent out-of-band // through the Reporting API, e.g., network errors, CSP violations, browser // interventions, and feature policy violations. let logs : Vec < LogLine < ReportBody > > = reports . into_iter ( ) . map ( | report | LogLine :: new ( report , client_data . clone ( ) ) ) . filter_map ( Result :: ok ) . collect ( ) ; // Create a handle to the upstream logging endpoint that we want to emit // the reports to. let mut endpoint = Endpoint :: from_name ( " " ) ; // Loop over each log line serializing it back to JSON and write it to // the logging endpoint. for log in logs . iter ( ) { serde_json :: to_writer ( & mut endpoint , & log ) ? ; } Ok ( ( ) ) }
Handle reports.
Handle reports .
req
Request