File manager - Edit - /usr/local/CyberPanel/lib/python3.10/site-packages/django/middleware/__pycache__/common.cpython-310.pyc
Back
o �h� � @ 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�}|durtjD ]}|�|�rtd��q |�� }tjrC|rE|�d�sG| � |�r2| � |�}n|�� }| �|j � d|� |� ��S dS dS 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 �DISALLOWED_USER_AGENTS�searchr �get_host�PREPEND_WWW� startswith�should_redirect_with_slash�get_full_path_with_slash� get_full_path�response_redirect_class�scheme)�self�request� user_agent�user_agent_regex�host�path� r �N/usr/local/CyberPanel/lib/python3.10/site-packages/django/middleware/common.py�process_request"