A HTTP file server by ChatGPT
After yesterday’s update of some long standing code on this website, considering that writing this kind of code is a pretty routine work, I tasked ChatGPT to write me the same that I did. Here is my specification:
I would like you to build the following with modern dotnet / csharp:
- A web server which serves files an directories in a console app.
- when started, an argument is provided that constitutes the root path of the server
- when started, the contents are shown as list in html (no css required, just markup)
- A directory, when clicked will show its contents in the same way as before
- A file, when clicked, will be downloaded
Check out the results of the interaction after a couple of iterations (the interaction has been stolen straight from Anthropic’s Claude :):
Gist not showing up? Most likely you're using Chrome. Reload the page to see the gist.
The iterations are documented in this chat. In general, especially at the start the code was written in a strange way.
While the system would use minimal APIs, it would read and write into the HttpContext. After telling it so, it switched
to using the query parameter and the Results
helper to produce results.
When pasted into my project I can see that many namespaces are imported that are not in use. Also, the context is still passed in as argument to the route handler, even though it is not used anymore. But in theory, combining this with a code inspection tool like Resharper could yield nice results. All in all, the program did what it was requested to do.
More concerning was what was made up about the double asterisk (**) used in the route pattern. The reason to put 2 there is wrong and even non-sensical, the irony being that I asked the system yesterday about how to match route parts that contain slashes, and it yielded the correct answer of prefixing the route with a single asterisk.
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