A HTTP file server in 60 lines of code
15 (!) years ago I wrote a post on writing a web server serving files from a directory in a
small amount of code in .NET. Revisiting the premise with the current capabilities naturally yields
to a smaller footprint, in relying on the very compact form of starting a minimal API server.
Another nice reduction of lines of code is the boring mime-type mapping that a class in .NET can now do for us,
the FileExtensionContentTypeProvider
in the Microsoft.AspNetCore.StaticFiles
.
Also, I saved myself the url escaping (eg space becoming %20) - the browser these days seems to handle such intricacies just fine.
And here we go:
Gist not showing up? Most likely you're using Chrome. Reload the page to see the gist.
Comments
With an account on the Fediverse or Mastodon, you can respond to this post. Since the Fediverse is decentralized, you can use your existing account hosted by another Mastodon server or compatible platform if you don't have an account on this one. Known non-private replies are displayed below.
Reply to this blog post via mastodon