Exemplo n.º 1
0
def _check_request_headers(docmeta: DocMetadata, response_data: Dict[str, Any],
                           headers: Dict[str, Any]) -> bool:
    """Check the request headers, update the response headers accordingly."""
    last_mod_dt: datetime = docmeta.modified

    # Latest trackback ping time depends on the database
    if 'trackback_ping_latest' in response_data \
       and isinstance(response_data['trackback_ping_latest'], datetime) \
       and response_data['trackback_ping_latest'] > last_mod_dt:
        # If there is a more recent trackback ping, use that datetime
        last_mod_dt = response_data['trackback_ping_latest']

    # Check for request headers If-Modified-Since and If-None-Match and compare
    # them to the last modified time to determine whether we will return a
    # "not modified" response
    mod_since_dt = _time_header_parse(headers, 'If-Modified-Since')
    none_match_dt = _time_header_parse(headers, 'If-None-Match')
    not_modified = _not_modified(last_mod_dt, mod_since_dt, none_match_dt)

    last_mod_mime = mime_header_date(last_mod_dt)
    headers['Last-Modified'] = last_mod_mime
    headers['ETag'] = last_mod_mime
    headers['Expires'] = abs_expires_header()[1]

    return not_modified
Exemplo n.º 2
0
def _check_request_headers(docmeta: DocMetadata, response_data: Dict[str, Any],
                           resp_headers: Dict[str, Any]) -> bool:
    """Check the request headers, update the response headers accordingly."""
    last_mod_dt: datetime = docmeta.modified

    # Latest trackback ping time depends on the database
    if 'trackback_ping_latest' in response_data \
       and isinstance(response_data['trackback_ping_latest'], datetime) \
       and response_data['trackback_ping_latest'] > last_mod_dt:
        # If there is a more recent trackback ping, use that datetime
        last_mod_dt = response_data['trackback_ping_latest']

    last_mod_mime = mime_header_date(last_mod_dt)
    etag = f'"{last_mod_mime}"'

    resp_headers['Last-Modified'] = last_mod_mime
    resp_headers['ETag'] = etag
    resp_headers['Expires'] = abs_expires_header()[1]

    not_modified = _not_modified(last_mod_dt,
                                 _time_header_parse('If-Modified-Since'),
                                 _get_req_header('if-none-match'), etag)

    return not_modified
Exemplo n.º 3
0
def _write_expires_header(response_headers: Dict[str, Any]) -> None:
    """Writes an expires header for the response."""
    response_headers["Expires"] = abs_expires_header()[1]