Пример #1
0
def getStaticPath(cfg, reqdata):
	return httputil.getRelativePath(cfg['staticurl'],
					reqdata['request-fullpath'])
Пример #2
0
def gather_reqdata(environ):
	cfg = environ['dwiki.cfg']
	webserv = environ['dwiki.web']
	logger = environ['dwiki.logger']

	reqdata = {}
	reqdata['server-name'] = getHost(environ)
	reqdata['server-schemaname'] = getHostSchemaKey(environ)
	if environ.get('HTTPS') == "on":
		reqdata['server-url'] = "https://%s" % reqdata['server-name']
		reqdata['server-schemakey'] = ".https"
	else:
		reqdata['server-url'] = "http://%s" % reqdata['server-name']
		reqdata['server-schemakey'] = ""

	# Break the request URI apart, and decode anything in the
	# query string.
	base = httputil.urlFromEnv(environ)
	reqdata['request-fullpath'] = rawurl = base
	qstr = environ.get('QUERY_STRING', None)

	# Query string decode. Note that even after decoding the query
	# string, we may not have a view.
	v = None
	if qstr:
		v, qdict = httputil.parseQueryStringView(qstr)
		# We clean utm_* parameters here so that we do not
		# generate error messages about them. Sigh.
		# We do not log a message about them.
		if clean_utm(qdict):
			reqdata[':utm:redirect'] = True
		if qdict and not v:
			v = webserv.guess_view(qdict)
			if not v:
				logger.error("unknown parameters in GET: '%s'" % qstr)
				reqdata[':kill:request'] = True
	if v:
		reqdata['view'] = v
		reqdata['view:set'] = True
		# Set the parameter dictionary from allowed URL query
		# parameters.
		plist = webserv.view_param_list(v, environ['REQUEST_METHOD'])
		if qdict and plist:
			paramdict = {}
			#for k in plist:
			#	paramdict[k] = qdict[k]
			for k in qdict.keys():
				if k in plist:
					paramdict[k] = qdict[k]
				else:
					# WHOOP WHOOP.
					logger.error("Invalid GET '%s' parameter '%s=%s'" % (v, k, qdict[k]))
					# We should abort. But at least we
					# log now.
					reqdata[':kill:request'] = True
			if paramdict:
				reqdata['view-dict'] = qdict
	else:
		reqdata['view'] = "normal"

	# If the query does not seem to be at or below our
	# root URL, we do not set the query reqdata variable.
	# This will be detected later and cause us to bail
	# out.
	# (It is not a fatal error now because the URL path
	#  may be one that is handled by a non-HTML-view
	#  thing.)
	query = httputil.getRelativePath(cfg['rooturl'], rawurl)
	if query is not None:
		reqdata['query'] = query

	# Set us up the cookie(s).
	# The cookie comes in as a header 'Cookie:', with all of
	# the cookie values in it.
	if 'HTTP_COOKIE' in environ:
		c = Cookie.SimpleCookie()
		try:
			c.load(environ['HTTP_COOKIE'])
			reqdata['cookie'] = c
		except Cookie.CookieError as e:
			logger.error("Invalid Cookie header: %s: %s" % (repr(environ['HTTP_COOKIE']), str(e)))
	# HTTP command:
	reqdata['http-command'] = environ['REQUEST_METHOD']
	# And version. Anything we don't know about is assumed to
	# be at least 1.1 capable. If you are lying to us, you may
	# lose.
	reqdata['http-version'] = environ['SERVER_PROTOCOL']
	# Remote IP address. (So far no one cares about the remote port.)
	reqdata['remote-ip'] = environ['REMOTE_ADDR']

	return reqdata