Introduce get_query_mode() and simplied process_endpoint(). #857