Repository: locustio/locust
File: locust/web.py (Python)

Code before:

            Arguments:
            suggest_filename_prefix: Prefix of the filename to suggest for saving the download.
            Will be appended with timestamp.
            """
            host = self.environment.host or "no host"
            return (
                f"Locust - {format_safe_timestamp(self.environment.stats.start_time)} - "
                + f"{self.environment.locustfile} - {host} - {suggest_filename_prefix}.csv"
            )

        def _download_csv_response(csv_data: str, filename_prefix: str) -> Response:
            """Generate csv file download response with 'csv_data'.

            Arguments:
            csv_data: CSV header and data rows.
            filename_prefix: Prefix of the filename to suggest for saving the download. Will be appended with timestamp.
            """

            response = make_response(csv_data)
            response.headers["Content-type"] = "text/csv"
            response.headers["Content-disposition"] = (
                f"attachment;filename={_download_csv_suggest_file_name(filename_prefix)}"
            )
            return response

        @app.route("/stats/requests/csv")
        @self.auth_required_if_enabled
        def request_stats_csv() -> Response:
            data = StringIO()
            writer = csv.writer(data)
            self.stats_csv_writer.requests_csv(writer)
            return _download_csv_response(data.getvalue(), "requests")

        @app.route("/stats/requests_full_history/csv")
        @self.auth_required_if_enabled
        def request_stats_full_history_csv() -> Response:
            options = self.environment.parsed_options
            if options and options.stats_history_enabled and isinstance(self.stats_csv_writer, StatsCSVFileWriter):
                return send_file(
                    os.path.abspath(self.stats_csv_writer.stats_history_file_name()),
                    mimetype="text/csv",
                    as_attachment=True,
                    download_name=_download_csv_suggest_file_name("requests_full_history"),
                    etag=True,
                    max_age=0,
                    conditional=True,
                    last_modified=None,
                )

            return make_response("Error: Server was not started with option to generate full history.", 404)

Review comment (suggestion):
I don't know under which scenario there won't be a host, but maybe in the case that there isn't a host we could exclude it?

Perhaps also consider using an underscore to separate the words as we had before? `Locust_starttime_locustfile_host.html`? Spaces aren't necessarily friendly on all systems

Code after:

        @app.route("/stats/reset")
        @self.auth_required_if_enabled
        def reset_stats() -> str:
            environment.events.reset_stats.fire()
            if environment.runner is not None:
                environment.runner.stats.reset_all()
                environment.runner.exceptions = {}
            return "ok"

        @app.route("/stats/report")
        @self.auth_required_if_enabled
        def stats_report() -> Response:
            theme = request.args.get("theme", "")
            res = get_html_report(
                self.environment,
                show_download_link=not request.args.get("download"),
                theme=theme,
            )
            if request.args.get("download"):
                res = app.make_response(res)
                host = f"_{self.environment.host}" if self.environment.host else ""
                res.headers["Content-Disposition"] = (
                    f"attachment;filename=Locust_{format_safe_timestamp(self.environment.stats.start_time)}_"
                    + f"{self.environment.locustfile}{host}.html"
                )
            return res

        def _download_csv_suggest_file_name(suggest_filename_prefix: str) -> str:
            """Generate csv file download attachment filename suggestion.

            Arguments:
            suggest_filename_prefix: Prefix of the filename to suggest for saving the download.
            Will be appended with timestamp.
            """
            host = f"_{self.environment.host}" if self.environment.host else ""
            return (
                f"Locust_{format_safe_timestamp(self.environment.stats.start_time)}_"
                + f"{self.environment.locustfile}{host}_{suggest_filename_prefix}.csv"
            )

        def _download_csv_response(csv_data: str, filename_prefix: str) -> Response:
            """Generate csv file download response with 'csv_data'.

            Arguments:
            csv_data: CSV header and data rows.
            filename_prefix: Prefix of the filename to suggest for saving the download. Will be appended with timestamp.
            """

            response = make_response(csv_data)
            response.headers["Content-type"] = "text/csv"