コード例 #1
0
ファイル: httpserver.py プロジェクト: hubo1016/vlcp
 def main():
     om = HttpRequestEvent.createMatcher(None, b"*", b"OPTIONS")
     dm = HttpRequestEvent.createMatcher()
     while True:
         yield (om, dm)
         if not self.apiroutine.event.canignore:
             self.apiroutine.event.canignore = True
             if self.apiroutine.matcher is om:
                 self.apiroutine.subroutine(options(self.apiroutine.event), False)
             else:
                 self.apiroutine.subroutine(default404(self.apiroutine.event), False)
コード例 #2
0
ファイル: httpserver.py プロジェクト: sinofeng/vlcp
 async def main():
     om = HttpRequestEvent.createMatcher(None, b'*', b'OPTIONS')
     dm = HttpRequestEvent.createMatcher()
     while True:
         ev, m = await M_(om, dm)
         if not ev.canignore:
             ev.canignore = True
             if m is om:
                 self.apiroutine.subroutine(options(ev), False)
             else:
                 self.apiroutine.subroutine(default404(ev), False)
コード例 #3
0
 def main():
     om = HttpRequestEvent.createMatcher(None, b'*', b'OPTIONS')
     dm = HttpRequestEvent.createMatcher()
     while True:
         yield (om, dm)
         if not self.apiroutine.event.canignore:
             self.apiroutine.event.canignore = True
             if self.apiroutine.matcher is om:
                 self.apiroutine.subroutine(
                     options(self.apiroutine.event), False)
             else:
                 self.apiroutine.subroutine(
                     default404(self.apiroutine.event), False)
コード例 #4
0
ファイル: http.py プロジェクト: marviniter/vlcp
 def rewrite(self, path, method = None, keepresponse = True):
     "Rewrite this request to another processor. Must be called before header sent"
     if self._sendHeaders:
         raise HttpProtocolException('Cannot modify response, headers already sent')
     if getattr(self.event, 'rewritedepth', 0) >= getattr(self.protocol, 'rewritedepthlimit', 32):
         raise HttpRewriteLoopException
     newpath = urljoin(quote_from_bytes(self.path).encode('ascii'), path)
     if newpath == self.fullpath or newpath == self.originalpath:
         raise HttpRewriteLoopException
     extraparams = {}
     if keepresponse:
         if hasattr(self, 'status'):
             extraparams['status'] = self.status
         extraparams['sent_headers'] = self.sent_headers
         extraparams['sent_cookies'] = self.sent_cookies
     r = HttpRequestEvent(self.host,
                            newpath,
                            self.method if method is None else method,
                            self.connection,
                            self.connmark,
                            self.xid,
                            self.protocol,
                            headers = self.headers,
                            headerdict = self.headerdict,
                            setcookies = self.setcookies,
                            stream = self.inputstream,
                            rewritefrom = self.fullpath,
                            originalpath = self.originalpath,
                            rewritedepth = getattr(self.event, 'rewritedepth', 0) + 1,
                            **extraparams
                            )
     for m in self.connection.waitForSend(r):
         yield m
     self._sendHeaders = True
     self.outputstream = None
コード例 #5
0
ファイル: http.py プロジェクト: marviniter/vlcp
 def routeevent(self, path, routinemethod, container = None, host = None, vhost = None, method = [b'GET', b'HEAD']):
     '''
     Route specified path to a routine factory
     :param path: path to match, can be a regular expression 
     :param routinemethod: factory function routinemethod(event), event is the HttpRequestEvent
     :param container: routine container. If None, default to self for bound method, or event.connection if not 
     :param host: if specified, only response to request to specified host
     :param vhost: if specified, only response to request to specified vhost.
                   If not specified, response to dispatcher default vhost.
     :param method: if specified, response to specified methods
     '''
     regm = re.compile(path + b'$')
     if vhost is None:
         vhost = self.vhost
     if container is None:
         container = getattr(routinemethod, '__self__', None)
     def ismatch(event):
         # Check vhost
         if vhost is not None and getattr(event.createby, 'vhost', '') != vhost:
             return False
         # First parse the path
         # RFC said we should accept absolute path
         psplit = urlsplit(event.path)
         if psplit.path[:1] != b'/':
             # For security reason, ignore unrecognized path
             return False
         if psplit.netloc and host is not None and host != psplit.netloc:
             # Maybe a proxy request, ignore it
             return False
         if getattr(event.createby, 'unquoteplus', True):
             realpath = unquote_plus_to_bytes(psplit.path)
         else:
             realpath = unquote_to_bytes(psplit.path)
         m = regm.match(realpath)
         if m is None:
             return False
         event.realpath = realpath
         event.querystring = psplit.query
         event.path_match = m
         return True
     def func(event, scheduler):
         try:
             if event.canignore:
                 # Already processed
                 return
             event.canignore = True
             c = event.connection if container is None else container
             c.subroutine(routinemethod(event), False)
         except:
             pass
     for m in method:
         self.registerHandler(HttpRequestEvent.createMatcher(host, None, m, _ismatch = ismatch), func)
コード例 #6
0
ファイル: testhttpserver.py プロジェクト: sinofeng/vlcp
 async def main(self):
     request = HttpRequestEvent.createMatcher()
     while True:
         ev = await request
         ev.canignore = True
         self.subroutine(self.handlehttp(ev))
コード例 #7
0
ファイル: testhttpserver.py プロジェクト: dq5070410/vlcp
 def main(self):
     request = HttpRequestEvent.createMatcher()
     while True:
         yield (request,)            
         self.event.canignore = True
         self.subroutine(self.handlehttp(self.event))
コード例 #8
0
ファイル: testhttpserver.py プロジェクト: vtanrun/vlcp
 def main(self):
     request = HttpRequestEvent.createMatcher()
     while True:
         yield (request,)            
         self.event.canignore = True
         self.subroutine(self.handlehttp(self.event))