def make_resource(self, ro, uri): log.debug("RovServerHomeView.make_resource: uri '%s'" % (uri)) if uri in HTTP_REDIRECTS: uri = HTTP_REDIRECTS[uri] log.debug("- updated uri '%s'" % (uri)) finaluri = uri is_rdf = False retry_count = 0 while retry_count < 5: retry_count += 1 try: httpsession = HTTP_Session(uri) (status, reason, headers, finaluri, body) = httpsession.doRequestFollowRedirect( uri, method="HEAD", exthost=True ) if status == 200: if str(finaluri) != uri: log.info("- <%s> redirected to <%s>" % (uri, finaluri)) HTTP_REDIRECTS[uri] = str(finaluri) is_rdf = headers["content-type"] in RDF_serialize_formats.iterkeys() else: log.warning("HTTP resppnse %03d %s accessing %s, attempt %d" % (status, reason, uri, retry_count)) httpsession.close() break except Exception, e: log.warning("HTTPSession exception (%s) accessing %s, attempt %d" % (e, uri, retry_count))
def test_MockHttpResources(self): testbaseuri = "http://testdomain.org/testdata/ro-test-1/" testbasepath = os.path.join(TestBaseDir, "ro-test-1/") with MockHttpFileResources(testbaseuri, testbasepath): hs = HTTP_Session(testbaseuri) (status, reason, headers, body) = hs.doRequest("README-ro-test-1.txt") self.assertEquals(status, 200) self.assertEquals(reason, "OK") self.assertEquals(headers["content-type"], "text/plain") self.assertRegexpMatches(body, "README-ro-test-1") (status, reason, headers, body) = hs.doRequest("README-ro-test-1.txt", method="HEAD") self.assertEquals(status, 200) self.assertEquals(reason, "OK") self.assertEquals(headers["content-type"], "text/plain") self.assertEquals(body, "") (status, reason, headers, body) = hs.doRequest("subdir1/subdir1-file.txt") self.assertEquals(status, 200) self.assertEquals(reason, "OK") self.assertEquals(headers["content-type"], "text/plain") (status, reason, headers, body) = hs.doRequest("minim.rdf", method="HEAD") self.assertEquals(status, 200) self.assertEquals(reason, "OK") self.assertEquals(headers["content-type"], "application/rdf+xml") (status, reason, headers, body) = hs.doRequest("filename%20with%20spaces.txt", method="HEAD") self.assertEquals(status, 200) self.assertEquals(reason, "OK") self.assertEquals(headers["content-type"], "text/plain") (status, reason, headers, body) = hs.doRequest("filename%23with%23hashes.txt", method="HEAD") self.assertEquals(status, 200) self.assertEquals(reason, "OK") self.assertEquals(headers["content-type"], "text/plain") return