1a107601fa490ca69215facceebe3d0dc5e7f1f8 | 6bcef0037bdb2d139a15065c3f31e872bae79df3 | ||
---|---|---|---|
173 | def __call__(self, environ, start_response): | 173 | def __call__(self, environ, start_response): |
174 | # get base domain as defined in INI file | 174 | # get base domain as defined in INI file |
175 | base_domain = config['global_conf']['domain'] | 175 | base_domain = config['global_conf']['domain'] |
176 | 176 | try: | |
177 | sub_domains = environ['HTTP_HOST'] | 177 | sub_domains, request_port = environ['HTTP_HOST'].split(':') |
178 | if not sub_domains.endswith(base_domain): | 178 | environ['request_port'] = int(request_port) |
179 | #if the domain doesn't end with base_domain, don't do anything | 179 | except ValueError: |
180 | return self.app(environ, start_response) | 180 | sub_domains = environ['HTTP_HOST'].split(':')[0] |
181 | | ||
182 | #If the domain doesn't end with base_domain, assume | ||
183 | #this is a cname, and redirect to the frame controller. | ||
184 | #Ignore localhost so paster shell still works. | ||
185 | #If this is an error, don't redirect | ||
186 | if (not sub_domains.endswith(base_domain) | ||
187 | and (not sub_domains == 'localhost')): | ||
188 | environ['sub_domain'] = sub_domains | ||
189 | if (not environ.get('extension') | ||
190 | and (not environ['PATH_INFO'].startswith('/error'))): | ||
191 | environ['original_path'] = environ['PATH_INFO'] | ||
192 | environ['PATH_INFO'] = '/frame' | ||
193 | return self.app(environ, start_response) | ||
181 | 194 | ||
182 | sub_domains = sub_domains[:-len(base_domain)].strip('.') | 195 | sub_domains = sub_domains[:-len(base_domain)].strip('.') |
183 | sub_domains = sub_domains.split('.') | 196 | sub_domains = sub_domains.split('.') |
... | ... | ||
294 | pass | 307 | pass |
295 | return r | 308 | return r |
296 | 309 | ||
310 | class LimitUploadSize(object): | ||
311 | def __init__(self, app, max_size=1024*500): | ||
312 | self.app = app | ||
313 | self.max_size = max_size | ||
314 | |||
315 | def __call__(self, environ, start_response): | ||
316 | cl_key = 'CONTENT_LENGTH' | ||
317 | if environ['REQUEST_METHOD'] == 'POST': | ||
318 | if ((cl_key not in environ) | ||
319 | or int(environ[cl_key]) > self.max_size): | ||
320 | r = Response() | ||
321 | r.status_code = 500 | ||
322 | r.content = 'request too big' | ||
323 | return r(environ, start_response) | ||
324 | |||
325 | return self.app(environ, start_response) | ||
297 | 326 | ||
298 | #god this shit is disorganized and confusing | 327 | #god this shit is disorganized and confusing |
299 | class RedditApp(PylonsBaseWSGIApp): | 328 | class RedditApp(PylonsBaseWSGIApp): |
... | ... | ||
335 | 364 | ||
336 | # CUSTOM MIDDLEWARE HERE (filtered by the error handling middlewares) | 365 | # CUSTOM MIDDLEWARE HERE (filtered by the error handling middlewares) |
337 | 366 | ||
367 | app = LimitUploadSize(app) | ||
338 | app = ProfilingMiddleware(app) | 368 | app = ProfilingMiddleware(app) |
339 | app = SourceViewMiddleware(app) | 369 | app = SourceViewMiddleware(app) |
340 | 370 | ||
341 | app = DomainMiddleware(app) | ||
342 | app = SubredditMiddleware(app) | 371 | app = SubredditMiddleware(app) |
372 | app = DomainMiddleware(app) | ||
343 | app = ExtensionMiddleware(app) | 373 | app = ExtensionMiddleware(app) |
344 | 374 | ||
375 | |||
345 | log_path = global_conf.get('log_path') | 376 | log_path = global_conf.get('log_path') |
346 | if log_path: | 377 | if log_path: |
347 | process_iden = global_conf.get('scgi_port', 'default') | 378 | process_iden = global_conf.get('scgi_port', 'default') |