kernelsauce / turbo

Turbo is a framework built for LuaJIT 2 to simplify the task of building fast and scalable network applications. It uses a event-driven, non-blocking, no thread design to deliver excellent performance and minimal footprint to high-load applications while also providing excellent support for embedded uses.
http://turbo.readthedocs.io/
Apache License 2.0
528 stars 84 forks source link

turbo.web.StaticFileHandler always returns invalid mime type #283

Closed MageSlayer closed 8 years ago

MageSlayer commented 8 years ago

Hi

The issue is about wrong web._StaticWebCache:get_mime(path) bevahiour. It always returns nil as mime_type. It is caused by invalid filename split. Instead of splitting on dot, it splits on every character. That is dot is used as regexp in fact. Tested on latest revision (8e1a1addaf725ba15b4566b2d1988a310d77d168)

See attached trivial patch for fix. mime-patch.zip

nagadomi commented 8 years ago

Long time ago, I got the same problem. Maybe It's caused by overwriting string:split() by the other library.

this monkey patch is related: https://github.com/kernelsauce/turbo/blob/357cf6f41a033647fb86812cf9fe572611eed88b/turbo/util.lua#L40

As far as I know, Torch7/xlua defines string:split() (different behavior): https://github.com/torch/xlua/blob/41308fe696bf8b0892f4ad4f9857d12a87a3f75e/init.lua#L689

MageSlayer commented 8 years ago

Hm. That might be the case. Thanks for the hint. I'll check it tomorrow.

MageSlayer commented 8 years ago

Sorry for noise. That was monkey patching indeed. So it's not related to Turbo.

luastoned commented 8 years ago

Well, turbo should not assume that string.split does not exist, maybe make use of a local function?

kernelsauce commented 8 years ago

I agree. I will change it around to just do the splitting in this function without any function. Im not sure if its so smart to remove the string:split completely, as it may break peoples things if changed at this point...

MageSlayer commented 8 years ago

Well. Making it local will definitely help as string.split is too common to override. Thanks for pro-active attitude :)

luastoned commented 8 years ago

I'm pretty sure people can re-implement string:split if they need to. Turbo should not pollute the global namespace at all now that I think about it.

kernelsauce commented 8 years ago

Fixed.