bottle.request.headers - python examples

Here are the examples of the python api bottle.request.headers taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

5 Examples 7

3 View Complete Implementation : decorators.py
Copyright GNU General Public License v3.0
Author : ValyrianTech
def authentication_required(f):
    """
    Decorator to check authentication before allowing access to certain functions

    :param f: The function that requires authentication
    :return: The result of the function OR a json dict containing the reason of the authentication failure
    """

    def decorated_function(*args, **kwargs):
        authentication_status = check_authentication(request.headers, request.json)
        if authentication_status == AuthenticationStatus.OK:
            return f(*args, **kwargs)
        else:
            return {'error': authentication_status}
    return decorated_function

0 View Complete Implementation : trigger.py
Copyright MIT License
Author : InfraBox
@post('/github/hook')
def trigger_build(conn):
    headers = dict(request.headers)

    if 'X-Github-Event' not in headers:
        return res(400, "X-Github-Event not set")

    if 'X-Hub-Signature' not in headers:
        return res(400, "X-Hub-Signature not set")

    event = headers['X-Github-Event']
    sig = headers['X-Hub-Signature']
    #pylint: disable=no-member
    body = request.body.read()
    secret = get_env('INFRABOX_GITHUB_WEBHOOK_SECRET')
    signed = sign_blob(secret, body)

    if signed != sig:
        return res(400, "X-Hub-Signature does not match blob signature")

    trigger = Trigger(conn)
    if event == 'push':
        return trigger.handle_push(request.json)
    elif event == 'pull_request':
        return trigger.handle_pull_request(request.json)

    return res(200, "OK")

0 View Complete Implementation : tests.py
Copyright GNU Lesser General Public License v2.1
Author : keredson
  def testHeaders(self):
    with boddle(headers={'x_header':'value'}):
      self.astertEqual(bottle.request.headers['X_HEADER'], 'value')

0 View Complete Implementation : tests.py
Copyright GNU Lesser General Public License v2.1
Author : keredson
  def testHyphenatedHeaders(self):
    with boddle(headers={'x-header':'value'}):
      self.astertEqual(bottle.request.headers['X-HEADER'], 'value')

0 View Complete Implementation : proxy.py
Copyright GNU General Public License v3.0
Author : krateng
def instructions(keys):
	authenticated = False
	if "Cookie" in request.headers:
		cookies = request.headers["Cookie"].split(";")
		for c in cookies:
			if c.strip().startswith("apikey="):
				authenticated = checkAPIkey(c.strip()[7:])

	if "token" in keys and authenticated:
		token = keys.get("token")
		parameters = {
			"method":"auth.getSession",
			"token":token,
			"api_key":get_settings("LASTFM_API_KEY")
		}
		response = urllib.request.urlopen("http://ws.audioscrobbler.com/2.0/?" + lfmbuild(parameters))
		xml = response.read()
		data = ET.fromstring(xml)
		if data.attrib.get("status") == "ok":
			username = data.find("session").find("name").text
			sessionkey = data.find("session").find("key").text

			update_settings("settings/settings.ini",{"LASTFM_API_SK":sessionkey,"LASTFM_USERNAME":username},create_new=True)

		return "/proxy"

	else:
		key,secret,sessionkey,name = get_settings("LASTFM_API_KEY","LASTFM_API_SECRET","LASTFM_API_SK","LASTFM_USERNAME")

		if key is None:
			lastfm = "<td>No Last.fm key provided</td>"
		elif secret is None:
			lastfm = "<td>No Last.fm secret provided</td>"
		elif sessionkey is None and authenticated:
			url = "http://www.last.fm/api/auth/?api_key=" + key + "&cb="
			lastfm = "<td clast='button'><a id='lastfmlink' href='" + url + "'><div>Connect</div></a></td>"
		elif sessionkey is None:
			lastfm = "<td>Not active</td>"
		else:

			lastfm = "<td>Account: " + name + "</td>"



	return {"KEY_STATUS_LASTFM":lastfm},[]