Sameera Kumarasingha
Sameera Kumarasingha

Reputation: 2988

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()

Upvotes: 0

Views: 2609

Answers (1)

szatkus
szatkus

Reputation: 1395

According to the module's source code this should work:

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

Upvotes: 4

Related Questions