Device Detection and IP Intelligence for the 51Degrees Pipeline, in Rust

ipi-web-getting-started-onprem.rs File Reference

Classes

struct  DataFileNotes
 What the page shows about the data file, read once when the engine is built. More...

Functions

pub struct DataFileNotes build_app (data_file:&std::path::Path, share_usage:bool,) -> anyhow::Result<(Router, DataFileNotes)>
 Build the on-premise web application router plus the data-file notes.
pub fn run (options:Options) -> anyhow::Result<()>
 Serve the example page over TCP until interrupted.
fn store_notes (notes:DataFileNotes)
 Record the notes for the running server to show on each page.
fn current_notes () -> DataFileNotes
 The notes recorded by [store_notes], or empty notes if none.
async fn home (Query(params):Query< std::collections::HashMap< String, String > >, result:FiftyOneResult,) -> Html< String >
 The home-page handler: render the weighted server-side IP-intelligence results, the evidence table, the IP look-up form, the location map, the free-tier data-file warnings and which properties need the Enterprise data file.
fn main () -> anyhow::Result<()>
fn test_app () -> Option< Router >
 Build the app for the test, skipping when no data file is available.
async fn get (app:Router, uri:&str) -> Response
 Drive one GET request through a clone of the app and return the response.
async fn body_string (response:Response) -> String
 Read a response body to an owned UTF-8 string.
fn server_starts_and_serves_page_and_client_script ()

Variables

mod web_support
const CONTACT_US_URL
 Where to ask about a copy of the Enterprise data file, as the console output links it when the server starts.
pub struct DataFileNotes PathBuf
 Options that drive [run].
pub struct DataFileNotes SocketAddr
 The socket address the server binds to.
pub warnings
 The standard free-tier and stale-file warnings.
pub pub available
 The properties the data file carries.
static NOTES
mod tests

Function Documentation

◆ body_string()

async fn body_string ( response:Response ) -> String

Read a response body to an owned UTF-8 string.

◆ build_app()

pub struct DataFileNotes build_app ( data_file:&std::path::Path ,
share_usage:bool  ) -> anyhow::Result<(Router, DataFileNotes)>

Build the on-premise web application router plus the data-file notes.

The engine is built once so its data-file warnings (free tier, and over 30 days old) can be read with [examples_shared::check_data_file] and shown on the page, along with the properties the data file carries, which say which rows need the Enterprise data file. The very same engine instance is then used as an application element of the web pipeline. Usage sharing is added first (REQUIRED for a web example).

share_usage is true when the binary serves the page. The tests pass false, so a test run sends nothing to 51Degrees.

◆ current_notes()

fn current_notes ( ) -> DataFileNotes

The notes recorded by [store_notes], or empty notes if none.

◆ get()

async fn get ( app:Router ,
uri:& str ) -> Response

Drive one GET request through a clone of the app and return the response.

A clone is used (cloning a Router is cheap, sharing the same Arc elements) so the owning app the caller holds outlives the request. With usage sharing on, the app wraps a blocking reqwest client whose backing runtime must not be dropped from inside an async context, so keeping the owning app in the synchronous test body lets its final drop happen outside the runtime.

◆ home()

async fn home ( Query(params):Query< std::collections::HashMap< String, String > > ,
result:FiftyOneResult  ) -> Html< String >

The home-page handler: render the weighted server-side IP-intelligence results, the evidence table, the IP look-up form, the location map, the free-tier data-file warnings and which properties need the Enterprise data file.

◆ main()

fn main ( ) -> anyhow::Result<()>

◆ run()

pub fn run ( options:Options ) -> anyhow::Result<()>

Serve the example page over TCP until interrupted.

◆ server_starts_and_serves_page_and_client_script()

fn server_starts_and_serves_page_and_client_script ( )

◆ store_notes()

fn store_notes ( notes:DataFileNotes )

Record the notes for the running server to show on each page.

◆ test_app()

fn test_app ( ) -> Option< Router >

Build the app for the test, skipping when no data file is available.

The test pins the ASN tier so it always exercises the small, current, always-loadable 4.5 ASN file, independent of whether the production Enterprise share happens to be mounted on the build machine. The binary itself uses IpiTier::default(), the Enterprise file or the Lite file.

Variable Documentation

◆ available

pub pub available

The properties the data file carries.

◆ CONTACT_US_URL

const CONTACT_US_URL

Where to ask about a copy of the Enterprise data file, as the console output links it when the server starts.

◆ NOTES

NOTES
static

◆ PathBuf

use std::path::PathBuf

Options that drive [run].

The path to the on-premise .ipi data file.

◆ SocketAddr

use std::net::SocketAddr

The socket address the server binds to.

Client-side evidence: gather the birth date from client-side JavaScript.

◆ tests

mod tests
Initial value:
{
use super::*

◆ warnings

pub warnings

The standard free-tier and stale-file warnings.

◆ web_support

mod web_support