Django删除响应头的Server
windows
进入源码文件lib/wsgiref/handlers.py,或者导入包from wsgiref import handlers。修改如下代码
def send_preamble(self):
"""Transmit version/status/date/server, via self._write()"""
if self.origin_server:
if self.client_is_modern():
self._write(('HTTP/%s %s\r\n' % (self.http_version,self.status)).encode('iso-8859-1'))
if 'Date' not in self.headers:
self._write(
('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
)
if self.server_software and 'Server' not in self.headers:
pass # 添加pass
# self._write(('Server: %s\r\n' % self.server_software).encode('iso-8859-1')) # 将这句注释
else:
self._write(('Status: %s\r\n' % self.status).encode('iso-8859-1'))
Linux
直接编辑/usr/local/lib/python3.7/wsgiref/handlers.py文件
如果python路径不一样,则可以在Linux中进入python,导入from wsgiref import handlers,然后输入handlers回车,会显示该文件存放的路径,进入进行编辑
进入heandlers.py文件的命令模式,输入/Server查找到如下代码进行修改
def send_preamble(self):
"""Transmit version/status/date/server, via self._write()"""
if self.origin_server:
if self.client_is_modern():
self._write(('HTTP/%s %s\r\n' % (self.http_version,self.status)).encode('iso-8859-1'))
if 'Date' not in self.headers:
self._write(
('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
)
if self.server_software and 'Server' not in self.headers:
pass # 添加pass
# self._write(('Server: %s\r\n' % self.server_software).encode('iso-8859-1')) # 将这句注释
else:
self._write(('Status: %s\r\n' % self.status).encode('iso-8859-1'))