I don't think this is the right fix.
This allows that a file without extension gets sent as entirely something 
else (meaning, I may have a file named "jpg" holding text data and it gets 
sent as appliaction/png).

BTW, can you pack an app that reproduces the issue ?

On Tuesday, August 20, 2013 1:36:50 PM UTC+2, Miguel Cabo wrote:
>
> I had a problem with Restful requests. The content-type response header 
> was text/plain when I sent a http://xxx.json request. Is it ok? I need 
> content-type response header as application/json. To do that I have 
> modified the glucon/contenttype.py with the following code:
>
> *Original contenttype.py*
> *
> *
> def contenttype(filename, default='text/plain'):
>
>     """
>     Returns the Content-Type string matching extension of the given 
> filename.
>     """
>     i = filename.rfind('.')
>
>     if i >= 0:
>         default = CONTENT_TYPE.get(filename[i:].lower(), default)
>         j = filename.rfind('.', 0, i)
>         if j >= 0:
>             default = CONTENT_TYPE.get(filename[j:].lower(), default)
>
>     if default.startswith('text/'):
>
>         default += '; charset=utf-8'
>
>     return default
>
>
> *Modified contenttype.py*
> *
> *
> def contenttype(filename, default='text/plain'):
>
>     """
>     Returns the Content-Type string matching extension of the given 
> filename.
>     """
>     i = filename.rfind('.')
>
>     if i >= 0:
>         default = CONTENT_TYPE.get(filename[i:].lower(), default)
>         j = filename.rfind('.', 0, i)
>         if j >= 0:
>             default = CONTENT_TYPE.get(filename[j:].lower(), default)
>     else:
>         default = CONTENT_TYPE.get('.' + filename.lower(), default)
>
>     if default.startswith('text/'):
>         default += '; charset=utf-8'
>
>     return default
>
>
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to