简体   繁体   中英

Python SimpleHttpServer, how to return files without extensions with plain/text mime type?

I coded following simple http server in python, I have some files without an extension and want to serve them with "text/plain" mime type. How can I achieve it?

import SimpleHTTPServer
import SocketServer

PORT = 80

class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    pass

Handler.extensions_map['.shtml'] = 'text/html'

httpd = SocketServer.TCPServer(("", PORT), Handler)

print "serving at port", PORT
httpd.serve_forever()

根据模块的源代码,这应该可以工作:

Handler.extensions_map[''] = 'text/plain'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM