Exemplo n.º 1
0
def proxy_head(rq, app):
	data = validate_request(rq, [
		{'name':'url', 'type':'url', 'required':True}
	])

	url   = urlparse.urlparse(data['values']['url'])
	query = ''

	if url.query:
		query = '?%s' % url.query

	path = '%s%s' % (url.path, query)
	conn = httplib.HTTPConnection(url.netloc)
	conn.request('HEAD', path)

	res = conn.getresponse()
	mime = res.getheader('content-type')
	size = res.getheader('content-length')

	info = {
		'host':url.netloc,
		'path':path,
	}

	if mime:
		info['type'] = mime

	if size:
		info['size'] = int(size)

	return respond(rq, info, res.status)
Exemplo n.º 2
0
def lucky_num():
    """POST route to process form data and send json response"""

    name = request.json["name"]
    email = request.json["email"]
    year = request.json["year"]
    color = request.json["color"]

    req = {
        "name": name,
        "email": email,
        "year": year,
        "color": color
    }

    try:
        validation = validate_request(req)

        num = random.randint(1,100)
        data = get_num_facts(num, year)
        return make_response(data, 200)
    except ValidationError as e:
        return make_response(e.errors, 422)
Exemplo n.º 3
0
	def parse_rq_base(self, rq):
		self.rq = rq
		return self.apply(validate_request(rq, self.get_rq_base_schema()))
Exemplo n.º 4
0
	def parse_object_data(self, strict=True):
		self.obj_data = validate_request(self.rq, self.get_model_schema(), strict)
		return self