changeset 4177:632696c3c78d

Replaced calls to setHttpHeader
author Florian Krupicka <florian.krupicka@googlemail.com>
date Wed, 18 Jun 2008 16:00:34 +0200
parents 85884c67228d
children e24aa7996f9f
files MoinMoin/Page.py MoinMoin/auth/http.py MoinMoin/session.py
diffstat 3 files changed, 17 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Wed Jun 18 00:28:07 2008 +0200
+++ b/MoinMoin/Page.py	Wed Jun 18 16:00:34 2008 +0200
@@ -964,23 +964,23 @@
             offer a dialogue to save it to disk (used by Save action).
         """
         request = self.request
-        request.setHttpHeader("Content-type: text/plain; charset=%s" % config.charset)
+        request.response.mimetype = 'text/plain'
         if self.exists():
             # use the correct last-modified value from the on-disk file
             # to ensure cacheability where supported. Because we are sending
             # RAW (file) content, the file mtime is correct as Last-Modified header.
-            request.setHttpHeader("Status: 200 OK")
-            request.setHttpHeader("Last-Modified: %s" % util.timefuncs.formathttpdate(os.path.getmtime(self._text_filename())))
+            request.response.status_code = 200
+            request.response.last_modified = os.path.getmtime(self._text_filename())
             text = self.encodeTextMimeType(self.body)
             #request.setHttpHeader("Content-Length: %d" % len(text))  # XXX WRONG! text is unicode obj, but we send utf-8!
             if content_disposition:
                 # TODO: fix the encoding here, plain 8 bit is not allowed according to the RFCs
                 # There is no solution that is compatible to IE except stripping non-ascii chars
                 filename_enc = "%s.txt" % self.page_name.encode(config.charset)
-                request.setHttpHeader('Content-Disposition: %s; filename="%s"' % (
-                                      content_disposition, filename_enc))
+                dispo_string = '%s; filename="%s"' % (content_disposition, filename_enc)
+                request.response.headers.add('Content-Disposition', dispo_string)
         else:
-            request.setHttpHeader('Status: 404 NOTFOUND')
+            request.response.status_code = 404
             text = u"Page %s not found." % self.page_name
 
         request.write(text)
--- a/MoinMoin/auth/http.py	Wed Jun 18 00:28:07 2008 +0200
+++ b/MoinMoin/auth/http.py	Wed Jun 18 16:00:34 2008 +0200
@@ -35,14 +35,13 @@
         # for standalone, request authorization and verify it,
         # deny access if it isn't verified
         if isinstance(request, request_standalone.Request):
-            request.setHttpHeader('WWW-Authenticate: Basic realm="MoinMoin"')
-            auth = request.headers.get('Authorization')
+            request.response.www_authenticate.set_basic(realm="MoinMoin")
+            
+            auth = request.authorization
             if auth:
-                auth = auth.split()[-1]
-                info = decodestring(auth).split(':', 1)
-                if len(info) == 2:
-                    u = user.User(request, auth_username=info[0], password=info[1],
-                                  auth_method=self.name, auth_attribs=[])
+                u = user.User(request, auth_username=auth.username,
+                              password=auth.password,
+                              auth_method=self.name, auth_attribs=[])
             if not u:
                 request.makeForbidden(401, _('You need to log in.'))
         # for Twisted, just check
--- a/MoinMoin/session.py	Wed Jun 18 00:28:07 2008 +0200
+++ b/MoinMoin/session.py	Wed Jun 18 16:00:34 2008 +0200
@@ -325,10 +325,12 @@
     def _set_cookie(self, request, cookie_string, expires):
         """ Set cookie, raw helper. """
         lifetime = expires - time.time()
-        cookie = self._make_cookie(request, self.cookie_name, cookie_string,
-                                   lifetime, expires)
+        domain = request.cfg.cookie_domain or None
+        path = request.cfg.cookie_path or None
         # Set cookie
-        request.setHttpHeader(cookie)
+        request.response.set_cookie(self.cookie_name, cookie_string,
+                                    max_age=lifetime, expires=expires,
+                                    path=path, domain=domain)
         # IMPORTANT: Prevent caching of current page and cookie
         request.disableHttpCaching()