5 # This software may be used and distributed according to the terms of the |
5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. |
6 # GNU General Public License version 2 or any later version. |
7 |
7 |
8 import os, mimetypes, re, cgi, copy |
8 import os, mimetypes, re, cgi, copy |
9 import webutil |
9 import webutil |
10 from mercurial import error, archival, templater, templatefilters |
10 from mercurial import error, encoding, archival, templater, templatefilters |
11 from mercurial.node import short, hex |
11 from mercurial.node import short, hex |
12 from mercurial.util import binary |
12 from mercurial.util import binary |
13 from common import paritygen, staticfile, get_contact, ErrorResponse |
13 from common import paritygen, staticfile, get_contact, ErrorResponse |
14 from common import HTTP_OK, HTTP_FORBIDDEN, HTTP_NOT_FOUND |
14 from common import HTTP_OK, HTTP_FORBIDDEN, HTTP_NOT_FOUND |
15 from mercurial import graphmod |
15 from mercurial import graphmod |
49 path = fctx.path() |
49 path = fctx.path() |
50 text = fctx.data() |
50 text = fctx.data() |
51 mt = mimetypes.guess_type(path)[0] |
51 mt = mimetypes.guess_type(path)[0] |
52 if mt is None: |
52 if mt is None: |
53 mt = binary(text) and 'application/octet-stream' or 'text/plain' |
53 mt = binary(text) and 'application/octet-stream' or 'text/plain' |
|
54 if mt.startswith('text/'): |
|
55 mt += '; charset="%s"' % encoding.encoding |
54 |
56 |
55 req.respond(HTTP_OK, mt, path, len(text)) |
57 req.respond(HTTP_OK, mt, path, len(text)) |
56 return [text] |
58 return [text] |
57 |
59 |
58 def _filerevision(web, tmpl, fctx): |
60 def _filerevision(web, tmpl, fctx): |