nickva commented on code in PR #5326: URL: https://github.com/apache/couchdb/pull/5326#discussion_r1821384658
########## src/chttpd/src/chttpd.erl: ########## @@ -431,6 +431,34 @@ handle_req_after_auth(HandlerKey, HttpReq) -> {HttpReq, catch_error(HttpReq, ErrorType, Error, Stack)} end. +nonce(MochiReq) -> + case MochiReq:get_header_value("X-Couch-Request-ID") of + undefined -> + new_nonce(); + Value -> + case re:run(Value, nonce_regex(), [{capture, none}]) of + match -> + Value; + nomatch -> + new_nonce() + end + end. + +new_nonce() -> + couch_util:to_hex(crypto:strong_rand_bytes(5)). + +nonce_regex() -> + Key = chttpd_request_id_regex, + Regex = config:get("chttpd", "request_id_regex", "^[a-zA-Z0-9-_]{1,64}+$"), Review Comment: Wonder how dynamic this pattern needs to be `[a-zA-Z0-9-_]{1,64}+` seems good enough for a general pattern. Maybe just hard-code it and make the start_link put it in the persistent_term? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@couchdb.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org