55 self.config = config |
55 self.config = config |
56 # instantiate publisher here and not in init_publisher to get some |
56 # instantiate publisher here and not in init_publisher to get some |
57 # checks done before daemonization (eg versions consistency) |
57 # checks done before daemonization (eg versions consistency) |
58 self.appli = CubicWebPublisher(repo, config) |
58 self.appli = CubicWebPublisher(repo, config) |
59 self.base_url = config['base-url'] |
59 self.base_url = config['base-url'] |
60 self.https_url = config['https-url'] |
|
61 global MAX_POST_LENGTH |
60 global MAX_POST_LENGTH |
62 MAX_POST_LENGTH = config['max-post-length'] |
61 MAX_POST_LENGTH = config['max-post-length'] |
63 |
62 |
64 def init_publisher(self): |
63 def init_publisher(self): |
65 config = self.config |
64 config = self.config |
102 finish_deferred = request.notifyFinish() |
101 finish_deferred = request.notifyFinish() |
103 finish_deferred.addErrback(partial(self.on_request_finished_ko, request)) |
102 finish_deferred.addErrback(partial(self.on_request_finished_ko, request)) |
104 # reload modified files in debug mode |
103 # reload modified files in debug mode |
105 if self.config.debugmode: |
104 if self.config.debugmode: |
106 self.config.uiprops.reload_if_needed() |
105 self.config.uiprops.reload_if_needed() |
107 if self.https_url: |
|
108 self.config.https_uiprops.reload_if_needed() |
|
109 self.appli.vreg.reload_if_needed() |
106 self.appli.vreg.reload_if_needed() |
110 if self.config['profile']: # default profiler don't trace threads |
107 if self.config['profile']: # default profiler don't trace threads |
111 return self.render_request(request) |
108 return self.render_request(request) |
112 else: |
109 else: |
113 deferred = threads.deferToThread(self.render_request, request) |
110 deferred = threads.deferToThread(self.render_request, request) |
128 code=500, twisted_request=request) |
125 code=500, twisted_request=request) |
129 |
126 |
130 def _render_request(self, request): |
127 def _render_request(self, request): |
131 origpath = request.path |
128 origpath = request.path |
132 host = request.host |
129 host = request.host |
133 # dual http/https access handling: expect a rewrite rule to prepend |
|
134 # 'https' to the path to detect https access |
|
135 https = False |
|
136 if origpath.split('/', 2)[1] == 'https': |
|
137 origpath = origpath[6:] |
|
138 request.uri = request.uri[6:] |
|
139 https = True |
|
140 if self.url_rewriter is not None: |
130 if self.url_rewriter is not None: |
141 # XXX should occur before authentication? |
131 # XXX should occur before authentication? |
142 path = self.url_rewriter.rewrite(host, origpath, request) |
132 path = self.url_rewriter.rewrite(host, origpath, request) |
143 request.uri.replace(origpath, path, 1) |
133 request.uri.replace(origpath, path, 1) |
144 req = CubicWebTwistedRequestAdapter(request, self.appli.vreg, https) |
134 req = CubicWebTwistedRequestAdapter(request, self.appli.vreg) |
145 try: |
135 try: |
146 ### Try to generate the actual request content |
136 ### Try to generate the actual request content |
147 content = self.appli.handle_request(req) |
137 content = self.appli.handle_request(req) |
148 except DirectResponse as ex: |
138 except DirectResponse as ex: |
149 return ex.response |
139 return ex.response |