def set_content_type(): e = request.environ c.render_style = e['render_style'] response.content_type = e['content_type'] if e.has_key('extension'): c.extension = ext = e['extension'] if ext in ('embed', 'wired', 'widget'): wrapper = request.params.get("callback", "document.write") wrapper = filters._force_utf8(wrapper) if not valid_jsonp_callback(wrapper): abort(BadRequestError(errors.BAD_JSONP_CALLBACK)) # force logged-out state since these can be accessed cross-domain c.user = UnloggedUser(get_browser_langs()) c.user_is_loggedin = False def to_js(content): return wrapper + "(" + utils.string2js(content) + ");" c.response_wrapper = to_js if ext in ("rss", "api", "json") and request.method.upper() == "GET": user = valid_feed(request.GET.get("user"), request.GET.get("feed"), request.path) if user and not g.read_only_mode: c.user = user c.user_is_loggedin = True if ext in ("mobile", "m") and not request.GET.get("keep_extension"): try: if request.cookies['reddit_mobility'] == "compact": c.extension = "compact" c.render_style = "compact" except (ValueError, KeyError): c.suggest_compact = True if ext in ("mobile", "m", "compact"): if request.GET.get("keep_extension"): c.cookies['reddit_mobility'] = Cookie(ext, expires=NEVER) # allow JSONP requests to generate callbacks, but do not allow # the user to be logged in for these callback = request.GET.get("jsonp") if is_api() and request.method.upper() == "GET" and callback: if not valid_jsonp_callback(callback): abort(BadRequestError(errors.BAD_JSONP_CALLBACK)) c.allowed_callback = callback c.user = UnloggedUser(get_browser_langs()) c.user_is_loggedin = False response.content_type = "application/javascript"
def POST_options(self, all_langs, **prefs): filter_prefs(prefs, c.user) if c.errors.errors: return abort(BadRequestError(errors.INVALID_PREF)) set_prefs(c.user, prefs) c.user._commit() u = UrlParser(c.site.path + "prefs") u.update_query(done='true') if c.cname: u.put_in_frame() return self.redirect(u.unparse())
def _abort_oauth_error(self, error): g.stats.simple_event('oauth2.errors.%s' % error) abort(BadRequestError(error))