'Test serving of static content'

def test_static(self):

    with self.create_server() as server:
        conn = server.connect()
        def missing(url, body=''):
            conn.request(u'GET', url)
            r = conn.getresponse()
            self.ae(r.status, httplib.NOT_FOUND)
            self.ae(r.read(), body)
        for prefix in (u'static', u'icon'):
            missing((u'/%s/missing.xxx' % prefix))
            missing((u'/%s/../out.html' % prefix), 'Naughty,    naughty!')
            missing((u'/%s/C:/out.html' % prefix), 'Naughty,    naughty!')
        def test_response(r):
            self.assertIn('max-age=', r.getheader(u'Cache-Control'))
            self.assertIn('public', r.getheader(u'Cache-Control'))
            self.assertIsNotNone(r.getheader(u'Expires'))
            self.assertIsNotNone(r.getheader(u'ETag'))
            self.assertIsNotNone(r.getheader(u'Content-Type'))
        def test(src, url, sz=None):
            raw = P(src, data=True)
            conn.request(u'GET', url)
            r = conn.getresponse()
            self.ae(r.status, httplib.OK)
            data = r.read()
            if (sz is None):
                self.ae(data, raw)
            else:
                self.ae(sz, identify(data)[1])
            test_response(r)
            conn.request(u'GET', url, headers={u'If-None-Match': r.getheader(u'ETag')})
            r = conn.getresponse()
            self.ae(r.status, httplib.NOT_MODIFIED)
            self.ae('', r.read())
        test(u'content-server/empty.html', u'/static/empty.html')
        test(u'images/lt.png', u'/favicon.png')
        test(u'images/lt.png', u'/icon/lt.png?sz=full')
        test(u'images/lt.png', u'/icon/lt.png', sz=48)
        test(u'images/lt.png', u'/icon/lt.png?sz=16', sz=16)
