Commit 33848ae3 authored by Andreas Jung's avatar Andreas Jung

regex, ready for Medusa migration

parent 518cee1f
...@@ -104,7 +104,7 @@ changes from Medusa's http_server ...@@ -104,7 +104,7 @@ changes from Medusa's http_server
""" """
import sys import sys
import regex import re
import string import string
import os import os
import types import types
...@@ -131,8 +131,8 @@ from medusa import logger ...@@ -131,8 +131,8 @@ from medusa import logger
register_subsystem('ZServer HTTPServer') register_subsystem('ZServer HTTPServer')
CONTENT_LENGTH = regex.compile('Content-Length: \([0-9]+\)',regex.casefold) CONTENT_LENGTH = re.compile('Content-Length: ([0-9]+)',re.I)
CONNECTION = regex.compile ('Connection: \(.*\)', regex.casefold) CONNECTION = re.compile('Connection: (.*)', re.I)
# maps request some headers to environment variables. # maps request some headers to environment variables.
# (those that don't start with 'HTTP_') # (those that don't start with 'HTTP_')
...@@ -141,6 +141,14 @@ header2env={'content-length' : 'CONTENT_LENGTH', ...@@ -141,6 +141,14 @@ header2env={'content-length' : 'CONTENT_LENGTH',
'connection' : 'CONNECTION_TYPE', 'connection' : 'CONNECTION_TYPE',
} }
# stolen from Medusa
def get_header (head_reg, lines, group=1):
for line in lines:
if head_reg.match (line):
return head_reg.group(group)
return ''
class zhttp_collector: class zhttp_collector:
def __init__(self, handler, request, size): def __init__(self, handler, request, size):
self.handler = handler self.handler = handler
...@@ -201,11 +209,11 @@ class zhttp_handler: ...@@ -201,11 +209,11 @@ class zhttp_handler:
uri_base=uri_base[:-1] uri_base=uri_base[:-1]
self.uri_base=uri_base self.uri_base=uri_base
uri_regex='%s.*' % self.uri_base uri_regex='%s.*' % self.uri_base
self.uri_regex = regex.compile(uri_regex) self.uri_regex = re.compile(uri_regex)
def match(self, request): def match(self, request):
uri = request.uri uri = request.uri
if self.uri_regex.match(uri) == len(uri): if self.uri_regex.match(uri):
return 1 return 1
else: else:
return 0 return 0
......
...@@ -104,7 +104,7 @@ changes from Medusa's http_server ...@@ -104,7 +104,7 @@ changes from Medusa's http_server
""" """
import sys import sys
import regex import re
import string import string
import os import os
import types import types
...@@ -131,8 +131,8 @@ from medusa import logger ...@@ -131,8 +131,8 @@ from medusa import logger
register_subsystem('ZServer HTTPServer') register_subsystem('ZServer HTTPServer')
CONTENT_LENGTH = regex.compile('Content-Length: \([0-9]+\)',regex.casefold) CONTENT_LENGTH = re.compile('Content-Length: ([0-9]+)',re.I)
CONNECTION = regex.compile ('Connection: \(.*\)', regex.casefold) CONNECTION = re.compile('Connection: (.*)', re.I)
# maps request some headers to environment variables. # maps request some headers to environment variables.
# (those that don't start with 'HTTP_') # (those that don't start with 'HTTP_')
...@@ -141,6 +141,14 @@ header2env={'content-length' : 'CONTENT_LENGTH', ...@@ -141,6 +141,14 @@ header2env={'content-length' : 'CONTENT_LENGTH',
'connection' : 'CONNECTION_TYPE', 'connection' : 'CONNECTION_TYPE',
} }
# stolen from Medusa
def get_header (head_reg, lines, group=1):
for line in lines:
if head_reg.match (line):
return head_reg.group(group)
return ''
class zhttp_collector: class zhttp_collector:
def __init__(self, handler, request, size): def __init__(self, handler, request, size):
self.handler = handler self.handler = handler
...@@ -201,11 +209,11 @@ class zhttp_handler: ...@@ -201,11 +209,11 @@ class zhttp_handler:
uri_base=uri_base[:-1] uri_base=uri_base[:-1]
self.uri_base=uri_base self.uri_base=uri_base
uri_regex='%s.*' % self.uri_base uri_regex='%s.*' % self.uri_base
self.uri_regex = regex.compile(uri_regex) self.uri_regex = re.compile(uri_regex)
def match(self, request): def match(self, request):
uri = request.uri uri = request.uri
if self.uri_regex.match(uri) == len(uri): if self.uri_regex.match(uri):
return 1 return 1
else: else:
return 0 return 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment