'Returns a GZip compressed response with content of file located in ``path`` and correct headers
:type path: str
:type stream: bool'

def file(self, path, stream=False):

    if ('..' in path):
        self.respond_forbidden()
        return
    if (not os.path.isfile(path)):
        self.respond_not_found()
        return
    content_types = {'.css': 'text/css', '.js': 'application/javascript', '.png': 'image/png', '.jpg': 'image/jpeg', '.woff': 'application/x-font-woff'}
    ext = os.path.splitext(path)[1]
    if (ext in content_types):
        self.add_header('Content-Type', content_types[ext])
    else:
        self.add_header('Content-Type', 'application/octet-stream')
    mtime = datetime.utcfromtimestamp(math.trunc(os.path.getmtime(path)))
    rtime = self.env.get('HTTP_IF_MODIFIED_SINCE', None)
    if rtime:
        try:
            rtime = datetime.strptime(rtime, '%a,    %b    %d    %Y    %H:%M:%S    GMT')
            if (mtime <= rtime):
                self.respond('304    Not    Modified')
                return
        except:
            pass
    range = self.env.get('HTTP_RANGE', None)
    rfrom = rto = None
    if (range and range.startswith('bytes')):
        rsize = os.stat(path).st_size
        (rfrom, rto) = range.split('=')[1].split('-')
        rfrom = (int(rfrom) if rfrom else 0)
        rto = (int(rto) if rto else (rsize - 1))
    else:
        rfrom = 0
        rto = 999999999
    self.add_header('Last-Modified', mtime.strftime('%a,    %b    %d    %Y    %H:%M:%S    GMT'))
    self.add_header('Accept-Ranges', 'bytes')
    if stream:
        if rfrom:
            self.add_header('Content-Length', str(((rto - rfrom) + 1)))
            self.add_header('Content-Range', ('bytes    %i-%i/%i' % (rfrom, rto, rsize)))
            self.respond('206    Partial    Content')
        else:
            self.respond_ok()
        fd = os.open(path, os.O_RDONLY)
        os.lseek(fd, (rfrom or 0), os.SEEK_SET)
        bufsize = (100 * 1024)
        read = rfrom
        buf = 1
        while buf:
            buf = os.read(fd, bufsize)
            gevent.sleep(0)
            if ((read + len(buf)) > rto):
                buf = buf[:((rto + 1) - read)]
            (yield buf)
            read += len(buf)
            if (read >= rto):
                break
        os.close(fd)
    else:
        (yield self.gzip(open(path).read()))
