Closed
Bug 626871
Opened 14 years ago
Closed 14 years ago
[amo] Write a trafficscript for mobile
Categories
(mozilla.org Graveyard :: Server Operations, task)
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: jbalogh, Assigned: oremj)
References
Details
We want to do mobile detection in zeus for performance.
Zeus should set and vary on an X-Mobile header.
Python will send a Vary: X-Mobile header to Zeus.
Zeus should send a Vary: User-Agent header to the client.
Client => Zeus(request.X-MOBILE) => Python
Python(Vary:X-Mobile) => Zeus(Vary:User-Agent) => Client
Here's the Python code:
class DetectMobileMiddleware(object):
# Mobile user agents.
UA = re.compile('android|fennec|iemobile|iphone|opera (?:mini|mobi)')
# We set a cookie if you explicitly select mobile/no mobile.
MC = 'mamo'
def process_request(self, request):
ua = request.META.get('HTTP_USER_AGENT', '').lower()
mc = request.COOKIES.get(self.MC)
if (self.UA.search(ua) and mc != 'off') or mc == 'on':
request.META['HTTP_X_MOBILE'] = '1'
Assignee | ||
Updated•14 years ago
|
Assignee: server-ops → jeremy.orem+bugs
Assignee | ||
Comment 1•14 years ago
|
||
Added this to preview:
$UA = "(android|fennec|iemobile|iphone|opera (mini|mobi))";
$MC = "mamo";
$ua = string.lowercase(http.getHeader( "User-Agent" ));
$mc = http.getCookie($MC);
if(($mc != "off" && string.regexmatch($ua, $UA)) || $mc == "on") {
http.addHeader("X-Mobile", 1);
http.addResponseHeader("Vary", "User-Agent");
http.cache.setkey("mobile");
}
Since I have http.cache.setkey("mobile") I don't think you will need to send Vary: from python.
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Reporter | ||
Comment 2•14 years ago
|
||
This doesn't work for me with the user agent or the cookie. I removed zamboni's middleware so we're relying on zeus now.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Assignee | ||
Comment 3•14 years ago
|
||
Zeus is dumb and has case insensitive variables.
Seems like this is working:
$ua_f = "(android|fennec|iemobile|iphone|opera (mini|mobi))";
$mc_f = "mamo";
$ua = string.lowercase(http.getHeader( "User-Agent" ));
$mc = http.getCookie($mc_f);
if(($mc != "off" && string.regexmatch($ua, $ua_f)) || $mc == "on") {
http.addHeader("X-Mobile", 1);
http.addResponseHeader("Vary", "User-Agent");
http.cache.setkey("mobile");
}
Status: REOPENED → RESOLVED
Closed: 14 years ago → 14 years ago
Resolution: --- → FIXED
Updated•10 years ago
|
Product: mozilla.org → mozilla.org Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•