protected function attachFile($event, $req, $res, $path, $size)
    {        
        $range = null;
        $event->sender->setAttribute('accept-range', null);
        
        if($req->headers->has('Range')) {            
            list($range[0], $range[1]) = explode('-', str_ireplace('bytes=', '', $req->headers->get('Range')));
            if(!$range[0]) $range[0] = 0;
            if(!$range[1]) $range[1] = $size-1;
            
            if($range[1] <$range[0]) {
                $res->statusCode = 416;
                return false;
            }
        }
        
        
        $info = [
            'name' => $path,
            'range' => $range,
        ];
        
        $event->sender->addFileHandler($this->fileKey, fopen($path, 'r'));        
        
        if(!$event->sender->getFileHandler($this->fileKey)) {
            Yii::error("cannot open $path", 'beyod\http');
            throw new \Exception("Server internal error", 503);
        }
        
        if($range) {
            $event->sender->setAttribute('accept-range', $range);
            $res->headers->set('Content-Length', $range[1]-$range[0]+1);
            $res->headers->set('Content-Range', 'bytes '.($range[0]).'-'.($range[1]).'/'.$size);
            fseek($event->sender->getFileHandler($this->fileKey) , $range[0]);
            $res->statusCode = 206;
        }
        
        return true;
    }