Repository: plotly/dash
File: dash/dash.py (Python)

Code before:
    # Serve the JS bundles for each package
    def serve_component_suites(self, package_name, path_in_package_dist):
        path_in_package_dist, has_fingerprint = check_fingerprint(
            path_in_package_dist
        )

        if package_name not in self.registered_paths:
            raise exceptions.DependencyException(
                "Error loading dependency.\n"
                '"{}" is not a registered library.\n'
                "Registered libraries are: {}".format(
                    package_name, list(self.registered_paths.keys())
                )
            )

        if path_in_package_dist not in self.registered_paths[package_name]:
            raise exceptions.DependencyException(
                '"{}" is registered but the path requested is not valid.\n'
                'The path requested: "{}"\n'
                "List of registered paths: {}".format(
                    package_name, path_in_package_dist, self.registered_paths
                )
            )

        resource_path = os.path.dirname(sys.modules[package_name].__file__)
        full_path = os.path.join(resource_path, path_in_package_dist)

        (mimetype, _) = mimetypes.guess_type(full_path)

        package = sys.modules[package_name]
        self.logger.debug(
            "serving -- package: %s[%s] resource: %s => location: %s",
            package_name,
            package.__version__,
            path_in_package_dist,
            package.__path__,
        )

        response = flask.Response(
            pkgutil.get_data(package_name, path_in_package_dist),
            mimetype=mimetype,
        )

        if has_fingerprint:
            # Fingerprinted resources are good forever (1 year)
            # No need for ETag as the fingerprint changes with each build
            response.cache_control.max_age = 31536000  # 1 year
        else:
            # Non-fingerprinted resources are given an ETag that
            # will be used / check on future requests
            response.add_etag()

Review comment (suggestion):
Will update this implementation to get the mapped mimetype from the `mimetypes` mapping instead of requiring the fullpath.

Code after:
        )

        response = flask.Response(
            pkgutil.get_data(package_name, path_in_pkg), mimetype=mimetype
        )

        if has_fingerprint:
            # Fingerprinted resources are good forever (1 year)
            # No need for ETag as the fingerprint changes with each build
            response.cache_control.max_age = 31536000  # 1 year
        else:
            # Non-fingerprinted resources are given an ETag that
            # will be used / check on future requests
            response.add_etag()
            tag = response.get_etag()[0]

            request_etag = flask.request.headers.get("If-None-Match")

            if '"{}"'.format(tag) == request_etag:
                response = flask.Response(None, status=304)

        return response

    def index(self, *args, **kwargs):  # pylint: disable=unused-argument
        scripts = self._generate_scripts_html()
        css = self._generate_css_dist_html()
        config = self._generate_config_html()
        metas = self._generate_meta_html()
        renderer = self._generate_renderer()
        title = getattr(self, "title", "Dash")

        if self._favicon:
            favicon_mod_time = os.path.getmtime(
                os.path.join(self.config.assets_folder, self._favicon)
            )
            favicon_url = self.get_asset_url(self._favicon) + "?m={}".format(
                favicon_mod_time
            )
        else:
            favicon_url = "{}_favicon.ico?v={}".format(
                self.config.requests_pathname_prefix, __version__
            )

        favicon = format_tag(
            "link",
            {"rel": "icon", "type": "image/x-icon", "href": favicon_url},
            opened=True,
        )

        index = self.interpolate_index(
            metas=metas,