Exemple #1
0
	def get(self):
		url = self.request.get("url")
		jsonp = self.request.get("jsonp")

		try:
			if not url:
				# Show the home page
				self.print_home()
				return

			url = url.replace(" ", "%20")
			data = mirror.get(url)
			response = {'data': base64.b64encode(data)}
		  
		except Exception, e:
			response = {"error" : repr(e)}
Exemple #2
0
    def get(self):
        url = self.request.get("url")
        jsonp = self.request.get("jsonp")

        try:
            if not url:
                # Show the home page
                self.print_home()
                return

            url = url.replace(" ", "%20")
            data = mirror.get(url)
            response = {'data': base64.b64encode(data)}

        except Exception, e:
            response = {"error": repr(e)}
Exemple #3
0
    def get(self):
        # Parameters
        url = self.request.get('url').replace(' ', '%20')
        callback = self.request.get('callback')
        encode = self.request.get('encode')
        ifnonematch = self.request.headers.get('If-None-Match') or ''

        if not url:
            # Show the home page
            self.redirect('/')
            return

        # Set headers for allowing cross domain XHR and content type
        self.response.headers['Access-Control-Allow-Origin'] = '*'
        self.response.headers[
            'Content-Type'] = 'text/plain; charset=ISO-8859-1'

        # Check for a cached hash
        hash = memcache.get(url + '_hash')
        if hash == ifnonematch:
            self.response.set_status(304)
            self.response.headers['ETag'] = hash
            return

        # Get this URL
        data = mirror.get(url)

        # Generate the hash if needed
        if not hash:
            hash = '"' + hashlib.md5(data).hexdigest() + '"'
            if not memcache.add(url + '_hash', hash, 86400):
                logging.error('Memcache set failed for hash of url ' + url)

        # Base64 encode the data if required
        if encode == 'base64':
            data = base64.b64encode(data)

        # Handle a callback function
        if callback:
            # Warning, data must be escaped too
            data = callback + '("' + data + '")'

        # Sent the data
        self.response.headers['ETag'] = hash
        self.response.out.write(data)
Exemple #4
0
	def get(self):
		# Parameters
		url = self.request.get('url').replace(' ', '%20')
		callback = self.request.get('callback')
		encode = self.request.get('encode')
		ifnonematch = self.request.headers.get('If-None-Match') or ''
		
		if not url:
			# Show the home page
			self.redirect('/')
			return
		
		# Set headers for allowing cross domain XHR and content type
		self.response.headers['Access-Control-Allow-Origin'] = '*'
		self.response.headers['Content-Type'] = 'text/plain; charset=ISO-8859-1'
		
		# Check for a cached hash
		hash = memcache.get(url + '_hash')
		if hash == ifnonematch:
			self.response.set_status(304)
			self.response.headers['ETag'] = hash
			return
		
		# Get this URL
		data = mirror.get(url)
		
		# Generate the hash if needed
		if not hash:
			hash = '"' + hashlib.md5(data).hexdigest() + '"'
			if not memcache.add(url + '_hash', hash, 86400):
				logging.error('Memcache set failed for hash of url ' + url)
		
		# Base64 encode the data if required
		if encode == 'base64':
			data = base64.b64encode(data)
		
		# Handle a callback function
		if callback:
			# Warning, data must be escaped too
			data = callback + '("' + data + '")'
		
		# Sent the data
		self.response.headers['ETag'] = hash
		self.response.out.write(data)