Python 3.9 is now generally available.

google.appengine.api.appinfo.HttpHeadersDict

A dict that limits keys and values to what http_headers allows.

Inherits From: ValidatedDict, ValidatedBase, expected_type

http_headers is an static handler key; it applies to handlers with static_dir or static_files keys. The following code is an example of how http_headers is used::

handlers:

- url: /static
  static_dir: static
  http_headers:
    X-Foo-Header: foo value
    X-Bar-Header: bar value

**kwds keyword arguments will be validated and put into the dict.

Child Classes

class KeyValidator

class ValueValidator

Methods

CheckInitialized

View source

Checks for missing or conflicting attributes.

Subclasses should override this function and raise an exception for any errors. Always run this method when all assignments are complete.

Raises
ValidationError When there are missing or conflicting attributes.

Get

View source

Gets a header value.

Args
header_name HTTP header name to look for.

Returns
A header value that corresponds to header_name. If more than one such value is in self, one of the values is selected arbitrarily and returned. The selection is not deterministic.

GetValidator

View source

Check the key for validity and return a corresponding value validator.

Args
key The key that will correspond to the validator we are returning.

GetWarnings

View source

Return all the warnings we've got, along with their associated fields.

Returns
A list of tuples of (dotted_field, warning), both strings.

KEY_VALIDATOR

Ensures that keys in HttpHeadersDict are valid.

HttpHeadersDict contains a list of headers. An instance is used as HttpHeadersDict's KEY_VALIDATOR.

Set

View source

Set a single value on Validated instance.

This method checks that a given key and value are valid and if so puts the item into this dictionary.

Args
key The name of the attributes.
value The value to set.

Raises
ValidationError When no validated attribute exists on class.

SetMultiple

View source

Set multiple values on Validated instance.

All attributes will be validated before being set.

Args
attributes A dict of attributes/items to set.

Raises
ValidationError When no validated attribute exists on class.

ToDict

View source

Convert ValidatedBase object to a dictionary.

Recursively traverses all of its elements and converts everything to simplified collections.

Subclasses should override this method.

Returns
A dictionary mapping all attributes to simple values or collections.

ToYAML

View source

Print validated object as simplified YAML.

Returns
Object as a simplified YAML string compatible with parsing using the SafeLoader.

VALUE_VALIDATOR

Ensures that values in HttpHeadersDict are valid.

An instance is used as HttpHeadersDict's VALUE_VALIDATOR.

clear

D.clear() -> None. Remove all items from D.

copy

D.copy() -> a shallow copy of D

fromkeys

Create a new dictionary with keys from iterable and values set to value.

get

Return the value for key if key is in the dictionary, else default.

items

D.items() -> a set-like object providing a view on D's items

keys

D.keys() -> a set-like object providing a view on D's keys

pop

D.pop(k[,d]) -> v, remove specified key and return the corresponding value.

If key is not found, default is returned if given, otherwise KeyError is raised

popitem

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault

View source

Trap setdefaultss to ensure all key/value pairs are valid.

See the documentation for setdefault on dict for usage details.

Raises
ValidationError if the specified key is illegal or the value invalid.

update

View source

Trap updates to ensure all key/value pairs are valid.

See the documentation for update on dict for usage details.

Raises
ValidationError if any of the specified keys are illegal or values invalid.

values

D.values() -> an object providing a view on D's values

__contains__

True if the dictionary has the specified key, else False.

__eq__

Return self==value.

__ge__

Return self>=value.

__getitem__

x.getitem(y) <==> x[y]

__gt__

Return self>value.

__iter__

Implement iter(self).

__le__

Return self<=value.

__len__

Return len(self).

__lt__

Return self<value.

__ne__

Return self!=value.

__or__

Return self|value.

__ror__

Return value|self.

DISALLOWED_HEADERS

{
 'content-encoding',
 'content-length',
 'date',
 'server'
}

MAX_HEADER_LENGTH 500
MAX_HEADER_VALUE_LENGTHS

{
 'content-security-policy': 10240,
 'content-security-policy-report-only': 10240,
 'location': 2047,
 'set-cookie': 4096,
 'set-cookie2': 4096,
 'x-content-security-policy': 10240,
 'x-webkit-csp': 10240
}

MAX_LEN 500