def answer_request(self, sendData):
        global g_stopEvent
        global g_downloader
        try:

            #Pull apart request path
            request_path=self.path[1:]       
            request_path=re.sub(r"\?.*","",request_path)
            #If a request to stop is sent, shut down the proxy

            if request_path.lower()=="stop":# all special web interfaces here
                sys.exit()
                return
            if request_path.lower()=="favicon.ico":
                print 'dont have no icone here, may be in future'
                self.wfile.close()
                return


            (url,proxy,use_proxy_for_chunks,maxbitrate,simpledownloader, auth,streamtype)=self.decode_url(request_path)
            print 'simpledownloaderxxxxxxxxxxxxxxx',simpledownloader
            if streamtype=='' or streamtype==None or streamtype=='none': streamtype='HDS'
            
            if streamtype=='HDS':

                print 'Url received at proxy',url,proxy,use_proxy_for_chunks,maxbitrate


                #Send file request
                #self.handle_send_request(download_id,file_url, file_name, requested_range,download_mode ,keep_file,connections)
                
                downloader=None
                #downloader=g_downloader
                
                if not downloader or downloader.live==True or  not (downloader.init_done and downloader.init_url ==url):
                    downloader=F4MDownloader()
                    if not downloader.init(self.wfile,url,proxy,use_proxy_for_chunks,g_stopEvent,maxbitrate,auth):
                        print 'cannot init'
                        return
                    g_downloader=downloader
                    print 'init...' 
                
                enableSeek=False
                requested_range=self.headers.getheader("Range")
                if requested_range==None: requested_range=""
                srange, erange=(None,None)
                
                
                            
                if downloader.live==False and len(requested_range)>0 and not requested_range=="bytes=0-0": #we have to stream?
                    enableSeek=True
                    (srange, erange) = self.get_range_request(requested_range, downloader.total_frags)
                

                print 'PROXY DATA',downloader.live,enableSeek,requested_range,downloader.total_frags,srange, erange
                enableSeek=False ##disabled for time being, couldn't find better way to handle
                
                framgementToSend=0
                inflate=1815002#(6526684-466/3)#*373/downloader.total_frags# 4142*1024*243/8/40 #1#1024*1024
                if enableSeek:
                    #rtype="video/x-flv" #just as default
                    self.send_response(206)
                    rtype="flv-application/octet-stream"  #default type could have gone to the server to get it.
                    self.send_header("Content-Type", rtype)
                    self.send_header("Accept-Ranges","bytes")
                    print 'not LIVE,enable seek',downloader.total_frags
                    
                    totalsize=downloader.total_frags*inflate
                    
                    framgementToSend=1#downloader.total_frags
                    erange=srange+framgementToSend*inflate
                    if erange>=totalsize:
                        erange=totalsize-1
                    
    #                crange="bytes "+str(srange)+"-" +str(int(downloader.total_frags-1))+"/"+str(downloader.total_frags)#recalculate crange based on srange, portionLen and content_size 
    #                crange="bytes "+str(srange)+"-" +str(int(totalsize-1))+"/"+str(totalsize)#recalculate crange based on srange, portionLen and content_size 
                    crange="bytes "+str(srange)+"-" +str(int(erange))+"/*"#+str(totalsize)#recalculate crange based on srange, portionLen and content_size 
                    print srange/inflate,erange/inflate,totalsize/inflate
                    self.send_header("Content-Length", str(totalsize))
                    self.send_header("Content-Range",crange)
                    etag=self.generate_ETag(url)
                    self.send_header("ETag",etag)
                    print crange
                    self.send_header("Last-Modified","Wed, 21 Feb 2000 08:43:39 GMT")
                    self.send_header("Cache-Control","public, must-revalidate")
                    self.send_header("Cache-Control","no-cache")
                    self.send_header("Pragma","no-cache")
                    self.send_header("features","seekable,stridable")
                    self.send_header("client-id","12345")
                    self.send_header("Connection", 'close')
                else:
                    self.send_response(200)
                    rtype="flv-application/octet-stream"  #default type could have gone to the server to get it.
                    self.send_header("Content-Type", rtype)
                    srange=None
                    
            elif streamtype=='SIMPLE' or simpledownloader :
                downloader=interalSimpleDownloader();
                if not downloader.init(self.wfile,url,proxy,g_stopEvent,maxbitrate):
                    print 'cannot init'
                    return
                srange,framgementToSend=(None,None)
                self.send_response(200)
                rtype="flv-application/octet-stream"  #default type could have gone to the server to get it.
                self.send_header("Content-Type", rtype)
                srange=None
            elif streamtype=='HLS' or simpledownloader :
                downloader=HLSDownloader()
                if not downloader.init(self.wfile,url,proxy,use_proxy_for_chunks,g_stopEvent,maxbitrate,auth):
                    print 'cannot init'
                    return
                    
                srange,framgementToSend=(None,None)
                self.send_response(200)
                rtype="flv-application/octet-stream"  #default type could have gone to the server to get it.
                self.send_header("Content-Type", rtype)
                srange=None
            

            #rtype="flv-application/octet-stream"  #default type could have gone to the server to get it. 
            #self.send_header("Content-Type", rtype)    
               
            self.end_headers()
            if not srange==None:
                srange=srange/inflate
             
            if sendData:
                downloader.keep_sending_video(self.wfile,srange,framgementToSend)
                #runningthread=thread.start_new_thread(downloader.download,(self.wfile,url,proxy,use_proxy_for_chunks,))
                print 'srange,framgementToSend',srange,framgementToSend
                #runningthread=thread.start_new_thread(downloader.keep_sending_video,(self.wfile,srange,framgementToSend,))
                
                xbmc.sleep(500)
                while not downloader.status=="finished":
                    xbmc.sleep(200);


        except:
            #Print out a stack trace
            traceback.print_exc()
            g_stopEvent.set()
            self.send_response(404)
            #Close output stream file
            self.wfile.close()
            return

        #Close output stream file
        self.wfile.close()
        return
dataset/ETHPy150Open mrknow/filmkodi/plugin.video.specto/resources/lib/libraries/f4mproxy/F4mProxy.py/MyHandler.answer_request/original