Merge "Adjust change headings on status page"
diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py
index 7cfea1c..4ef1790 100755
--- a/tests/test_scheduler.py
+++ b/tests/test_scheduler.py
@@ -17,6 +17,7 @@
 import ConfigParser
 from cStringIO import StringIO
 import gc
+import gzip
 import hashlib
 import json
 import logging
@@ -842,9 +843,12 @@
         self.swift = zuul.lib.swift.Swift(self.config)
 
         def URLOpenerFactory(*args, **kw):
+            if isinstance(args[0], urllib2.Request):
+                return old_urlopen(*args, **kw)
             args = [self.fake_gerrit] + list(args)
             return FakeURLOpener(self.upstream_root, *args, **kw)
 
+        old_urlopen = urllib2.urlopen
         urllib2.urlopen = URLOpenerFactory
 
         self.launcher = zuul.launcher.gearman.Gearman(self.config, self.sched,
@@ -2989,7 +2993,7 @@
         self.assertEqual(self.history[4].pipeline, 'check')
         self.assertEqual(self.history[5].pipeline, 'check')
 
-    def test_json_status(self):
+    def test_json_status(self, compressed=False):
         "Test that we can retrieve JSON status info"
         self.worker.hold_jobs_in_build = True
         A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
@@ -2999,8 +3003,14 @@
 
         port = self.webapp.server.socket.getsockname()[1]
 
-        f = urllib.urlopen("http://localhost:%s/status.json" % port)
+        req = urllib2.Request("http://localhost:%s/status.json" % port)
+        if compressed:
+            req.add_header("accept-encoding", "gzip")
+        f = urllib2.urlopen(req)
         data = f.read()
+        if compressed:
+            gz = gzip.GzipFile(fileobj=StringIO(data))
+            data = gz.read()
 
         self.worker.hold_jobs_in_build = False
         self.worker.release()
@@ -3024,6 +3034,9 @@
         self.assertIn('project-test1', status_jobs)
         self.assertIn('project-test2', status_jobs)
 
+    def test_json_status_gzip(self):
+        self.test_json_status(True)
+
     def test_merging_queues(self):
         "Test that transitively-connected change queues are merged"
         self.config.set('zuul', 'layout_config',
diff --git a/zuul/webapp.py b/zuul/webapp.py
index 6b04384..cd02d20 100644
--- a/zuul/webapp.py
+++ b/zuul/webapp.py
@@ -16,7 +16,8 @@
 import logging
 import threading
 from paste import httpserver
-from webob import Request
+import webob
+from webob import dec
 
 
 class WebApp(threading.Thread):
@@ -27,7 +28,7 @@
         self.scheduler = scheduler
         self.port = port
         self.daemon = True
-        self.server = httpserver.serve(self.app, host='0.0.0.0',
+        self.server = httpserver.serve(dec.wsgify(self.app), host='0.0.0.0',
                                        port=self.port, start_loop=False)
 
     def run(self):
@@ -36,17 +37,17 @@
     def stop(self):
         self.server.server_close()
 
-    def app(self, environ, start_response):
-        request = Request(environ)
-        if request.path == '/status.json':
-            try:
-                ret = self.scheduler.formatStatusJSON()
-            except:
-                self.log.exception("Exception formatting status:")
-                raise
-            start_response('200 OK', [('content-type', 'application/json'),
-                                      ('Access-Control-Allow-Origin', '*')])
-            return [ret]
-        else:
-            start_response('404 Not Found', [('content-type', 'text/plain')])
-            return ['Not found.']
+    def app(self, request):
+        if request.path != '/status.json':
+            raise webob.exc.HTTPNotFound()
+        try:
+            ret = self.scheduler.formatStatusJSON()
+        except:
+            self.log.exception("Exception formatting status:")
+            raise
+        response = webob.Response(body=ret, content_type='application/json')
+        response.headers['Access-Control-Allow-Origin'] = '*'
+        response.headers['Vary'] = 'Accept-Encoding'
+        if 'gzip' in request.headers.get('accept-encoding', ()):
+            response.encode_content('gzip')
+        return response