In everyone's memory , Create a HTTP The server , It may be very complicated , It takes months of work , This is for large websites, maybe it's like this . however , If you just want to test in your own testing field , Or auxiliary servers , It can be very simple . Or a little website in an embedded device like raspberry pie , You can use a simple server . Create a simple server , There must be very few connections , The performance requirements are not high , And there's no fault tolerance mechanism , Nothing DNS, There's no dynamic balance, etc .
stay Python The standard library has some built-in test HTTP The server , These are in http.server Module , Generally used to test , Or simple server use .HTTPServer Class derived from TCPServer class , When calling its constructor, you need to provide a RequestHandlerClass Parameters . stay http.server A basic... Has been defined in the module BaseHTTPRequestHandler class , We just have to inherit it , Define some methods you need to deal with , You can use it . from BaseHTTPRequestHandler After inheritance , Generally, there is no need to rewrite handle Method , It's about adding custom processing methods , Method has no parameters , The format is ：
do_< The requested method name >
Comparison processing GET The request is named do_GET, Pay attention to capital letters here , You can't use lowercase or lowercase , because python It's different case names .
Processing HTTP When asked , The methods available are ：