Django刪除響應(yīng)頭的Server
windows
進入源碼文件lib/wsgiref/handlers.py批糟,或者導(dǎo)入包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埠啃,導(dǎo)入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'))