OwlCyberSecurity - MANAGER
Edit File: common.cpython-39.pyc
a kH�f� � @ s� d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl m Z d dlmZ d dl mZ d d lmZ G d d� de�ZG dd � d e�ZdS )� N)�urlparse)�settings)�PermissionDenied)� mail_managers)�HttpResponsePermanentRedirect)� is_valid_path)�MiddlewareMixin)�escape_leading_slashesc @ s4 e Zd ZdZeZdd� Zdd� Zdd� Zdd � Z d S )�CommonMiddlewarea "Common" middleware for taking care of some basic operations: - Forbid access to User-Agents in settings.DISALLOWED_USER_AGENTS - URL rewriting: Based on the APPEND_SLASH and PREPEND_WWW settings, append missing slashes and/or prepends missing "www."s. - If APPEND_SLASH is set and the initial URL doesn't end with a slash, and it is not found in urlpatterns, form a new URL by appending a slash at the end. If this new URL is found in urlpatterns, return an HTTP redirect to this new URL; otherwise process the initial URL as usual. This behavior can be customized by subclassing CommonMiddleware and overriding the response_redirect_class attribute. c C s� |j �d�}|dur2tjD ]}|�|�rtd��q|�� }tjr�|r�|�d�s�| � |�rd| � |�}n|�� }| �|j � d|� |� ��S dS )z� Check for denied User-Agents and rewrite the URL based on settings.APPEND_SLASH and settings.PREPEND_WWW �HTTP_USER_AGENTNzForbidden user agentzwww.z://www.)�META�getr ZDISALLOWED_USER_AGENTS�searchr �get_hostZPREPEND_WWW� startswith�should_redirect_with_slash�get_full_path_with_slash� get_full_path�response_redirect_class�scheme)�self�request� user_agentZuser_agent_regex�host�path� r �Z/home/gouroczh/virtualenv/test/3.9/lib/python3.9/site-packages/django/middleware/common.py�process_request"