diff options
| author | Teddy Wing | 2018-11-11 00:39:19 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2018-11-11 00:39:19 +0100 | 
| commit | 0d1fea0bfa49b69b93c8b93fd895e084eade153f (patch) | |
| tree | 8e92a2c62dbe3bb7b2b67659ff67a9ee6d18c256 /license-generator | |
| parent | d52c89089623d511f5059bcfc36b3a6e424d3bcb (diff) | |
| download | dome-key-web-0d1fea0bfa49b69b93c8b93fd895e084eade153f.tar.bz2 | |
main(): Add request logging
Log incomming requests to the program's log file.
Remove the 500 error when failing to read stdin to a string. I think it
should be safe to ignore that error. Now that I think about it, we
should be logging it though.
Diffstat (limited to 'license-generator')
| -rw-r--r-- | license-generator/src/main.rs | 44 | 
1 files changed, 27 insertions, 17 deletions
| diff --git a/license-generator/src/main.rs b/license-generator/src/main.rs index 477ebf4..8636055 100644 --- a/license-generator/src/main.rs +++ b/license-generator/src/main.rs @@ -19,6 +19,27 @@ use license_generator::purchaser::Purchaser;  use license_generator::request;  use license_generator::response; +fn log_request(req: &fastcgi::Request, post_params: &str) { +    info!( +        "{method} {path} {query} - {protocol} - {user_agent} - {remote_addr} | {forwarded_for} / {post_params}", +        method = req.param("REQUEST_METHOD") +            .unwrap_or("REQUEST_METHOD".into()), +        path = req.param("SCRIPT_NAME") +            .unwrap_or("SCRIPT_NAME".into()), +        query = req.param("QUERY_STRING") +            .unwrap_or("QUERY_STRING".into()), +        protocol = req.param("SERVER_PROTOCOL") +            .unwrap_or("SERVER_PROTOCOL".into()), +        user_agent = req.param("HTTP_USER_AGENT") +            .unwrap_or("HTTP_USER_AGENT".into()), +        remote_addr = req.param("REMOTE_ADDR") +            .unwrap_or("REMOTE_ADDR".into()), +        forwarded_for = req.param("HTTP_X_FORWARDED_FOR") +            .unwrap_or("HTTP_X_FORWARDED_FOR".into()), +        post_params = post_params, +    ); +} +  fn main() -> Result<()> {      let log_file_path = env::var("LOG_FILE")          .chain_err(|| "LOG_FILE environment variable not found")?; @@ -49,6 +70,11 @@ fn main() -> Result<()> {      }      fastcgi::run(|mut req| { +        let mut params = String::new(); +        req.stdin().read_to_string(&mut params).unwrap_or(0); + +        log_request(&req, ¶ms); +          match req.param("REQUEST_METHOD") {              Some(method) => {                  if method != "POST" { @@ -73,23 +99,7 @@ fn main() -> Result<()> {              },          }; -        let mut stdin = String::new(); -        match req.stdin().read_to_string(&mut stdin) { -            Ok(_) => (), -            Err(e) => { -                error!("{}", e); - -                response::set_500(&mut req.stdout()).unwrap_or(()); -                write!(&mut req.stdout(), "Content-Type: text/plain - -500 Internal Server Error") -                    .unwrap_or(()); - -                return; -            }, -        } - -        let is_verified = match request::verified(&stdin) { +        let is_verified = match request::verified(¶ms) {              Ok(v) => v,              Err(e) => {                  error!("{}", e); | 
