2 Star 3 Fork 0

Asc0t6e / Medusa

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
HTTPServer.py 2.07 KB
一键复制 编辑 原始数据 按行查看 历史
Asc0t6e 提交于 2021-12-24 18:31 . v1.0.108:palm_tree:
# !/usr/bin/env python
# -*- coding: utf-8 -*-
from http.server import BaseHTTPRequestHandler, HTTPServer
from Web.DatabaseHub import DomainNameSystemLog
import base64
from ClassCongregation import ErrorLog
class Server(BaseHTTPRequestHandler):
def Response(self):
try:
self.response_headers=""
self.send_response(200)
self.send_header('Content-type', 'text/html')
for i in self._headers_buffer:
self.response_headers+=str(i.decode("utf-8"))
self.end_headers()
except Exception as e:
ErrorLog().Write("HTTPServer_Server(Class)_Response(def)", e)
def do_GET(self):
try:
Request=str(self.requestline)+"\n"+str(self.headers)
self.Response()
DomainNameSystemLog().Write(ip="", domain_name="", type="http", response=base64.b64encode(self.response_headers.encode('utf-8')), request=base64.b64encode(Request.encode('utf-8')))
#self.wfile.write("GET request for {}".format(self.path).encode('utf-8'))
except Exception as e:
ErrorLog().Write("HTTPServer_Server(Class)_GET(def)", e)
def do_POST(self):
try:
ContentLength = int(self.headers['Content-Length']) # <--- Gets the size of data
PostData = self.rfile.read(ContentLength) # <--- Gets the data itself
Request=str(self.requestline)+"\n"+str(self.headers)+"\n"+PostData.decode("utf-8")
self.Response()
DomainNameSystemLog().Write(ip="", domain_name="", type="http", response=base64.b64encode(self.response_headers.encode('utf-8')), request=base64.b64encode(Request.encode('utf-8')))
#self.wfile.write("POST request for {}".format(self.path).encode('utf-8'))
except Exception as e:
ErrorLog().Write("HTTPServer_Server(Class)_POST(def)", e)
if __name__ == '__main__':
try:
ServerAddress = ('0.0.0.0', 8888)
Httpd = HTTPServer(ServerAddress, Server)
Httpd.serve_forever()
except Exception as e:
ErrorLog().Write("HTTPServer_main(def)", e)
1
https://gitee.com/asc0t6e/Medusa.git
git@gitee.com:asc0t6e/Medusa.git
asc0t6e
Medusa
Medusa
master

搜索帮助