Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion - self.file alongside self.template that serves a single static file to a given URL. #144

Open
drforr opened this issue Jun 12, 2017 · 5 comments

Comments

@drforr
Copy link

drforr commented Jun 12, 2017

It's really a synonym for self.template, it just explicitly doesn't do any preprocessing to the text. No real speed improvements, just clarity, being able to say that route X is completely static, no preprocessing.

--- cut here ---
submethod BUILD(|) {
my $rootdir = $?FILE.IO.parent.parent;
self.get: '/' => sub {
self.file: 'index.html'; # <--- There.
};
}
--- cut here ---

@szabgab
Copy link
Member

szabgab commented Jun 25, 2017

IMHO this should automatically set the content-type as well.
Question: should this be restricted to the directory of the application to avoid accidentally service other files? If so, should there be an override for that safety?

@drforr
Copy link
Author

drforr commented Jun 25, 2017

I'd suggest adding an optional MIME-type variable on the call. Testing a file's magic can be unreliable and slow. Think for example of a 1MB UTF-8 with the only non-ASCII character being a copyright symbol at the end. This way the user can either override bad magic detection or set it for performance purposes.

@szabgab
Copy link
Member

szabgab commented Jun 25, 2017

I'd say by default it should use the same algorithm as the static file serving, (is that based on extension?) but the user can override it with an optional parameter as @drforr suggests.

@ufobat
Copy link
Member

ufobat commented Jun 25, 2017

This makes sense :)

@drforr
Copy link
Author

drforr commented Jun 25, 2017

Right. I wasn't suggesting avoiding the MIME-type check altogether, I was just suggesting a way to override the behavior. Usually checking magic is fast so it's not a problem, but I've worked with documents where it's unreliable, or sometimes you simply want to, say, upgrade text/ASCII to text/UTF-8 because it's the right thing to do.

bin-doph pushed a commit to bin-doph/Bailador that referenced this issue Aug 15, 2017
This adds the routine and method 'file', which serves the purpose of simply
serving a file as-is. The content-type can optionally be specified, but
is not checked, defaults to text/plain;utf8
bin-doph pushed a commit to bin-doph/Bailador that referenced this issue Aug 15, 2017
bin-doph pushed a commit to bin-doph/Bailador that referenced this issue Aug 15, 2017
This adds the routine and method 'file', which serves the purpose of simply
serving a file as-is. The content-type can optionally be specified, but
is not checked, defaults to text/plain;utf8
bin-doph pushed a commit to bin-doph/Bailador that referenced this issue Aug 15, 2017
This adds the routine and method 'file', which serves the purpose of simply
serving a file as-is. The content-type can optionally be specified, but
is not checked, defaults to text/plain;utf8
bin-doph pushed a commit to bin-doph/Bailador that referenced this issue Aug 15, 2017
This adds the routine and method 'render-file', which serves the purpose of simply
serving a file. The content-type can optionally be specified, otherwise render()
will set it.
bin-doph pushed a commit to bin-doph/Bailador that referenced this issue Aug 15, 2017
This adds the routine and method 'render-file', which serves the purpose of simply
serving a file. The content-type can optionally be specified, otherwise render()
will set it.
bin-doph pushed a commit to bin-doph/Bailador that referenced this issue Aug 15, 2017
This adds the routine and method 'render-file', which serves the purpose of simply
serving a file. The content-type can optionally be specified, otherwise render()
will set it.
bin-doph added a commit to bin-doph/Bailador that referenced this issue Aug 15, 2017
This adds the routine and method 'render-file', which serves the purpose of simply
serving a file. The content-type can optionally be specified, otherwise render()
will set it.
ufobat pushed a commit that referenced this issue Sep 25, 2017
This adds the routine and method 'render-file', which serves the purpose of simply
serving a file. The content-type can optionally be specified, otherwise render()
will set it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants