Drop a few files into a desktop app, show someone a QR code, and let them download through their browser. That is the sending workflow in RoomDrop, a local-network file-sharing utility I’m building with Go, Wails, React, and TypeScript.
The recipient doesn’t need to install anything. The desktop app prepares the files and starts a small HTTP server on the selected network adapter. A link connects the browser to that session.
The interesting part is deciding when that session should end. A checkbox labeled One-time download raises several questions: does opening the page count? What happens if the connection breaks? Can two requests both get through? And what should Stop sharing do to a download already in progress?
Those decisions are the subject of this entry. RoomDrop also supports receiving files; the behavior below concerns its sending sessions.
Opening the page is separate from downloading
A sharing link needs a page where the recipient can inspect the filenames and choose Download. Visiting that page should leave the transfer available.
RoomDrop separates the page from the action:
| Request | Effect |
|---|---|
GET /s/<token> |
Show the sharing page. |
HEAD /s/<token> |
Return page headers without starting a transfer. |
POST /s/<token>/download |
Attempt the download. |
GET or HEAD on the download endpoint |
Reject the request without consuming the session. |
That separation also keeps ordinary link previews from spending a one-time
download. A preview fetching the page cannot accidentally trigger the download
action. The request routing lives in
session.go.
A failed attempt should leave room for a retry
Consuming the link as soon as the download starts would make a dropped connection expensive: the sender would need to create another session even though the file never finished transferring.
RoomDrop keeps the session in its sharing state while sending the payload.
For a one-time session, only one download can be active. A second request gets
an HTTP 409 Conflict response and can try again later. The state check and the
reservation of that active slot happen under the same mutex, so two requests
cannot both claim it.
The transfer counts as complete only when all of these conditions hold:
- The copy finishes without an error and sends the expected number of bytes.
- Flushing the HTTP response succeeds.
- The request context has not been canceled.
- The session is still sharing.
An interrupted transfer releases the active slot and leaves the link available
until it expires or the sender stops it. A completed one-time transfer changes
the session to downloaded, preventing another download.
The expected byte count matters even for local files. RoomDrop serves a single file directly from an open file handle. If that file is shortened during the session, reaching the new end of the file must not count as sending the original payload. The implementation checks for that short read; the source file should still be left unchanged while sharing.
Completion has a limit
The server can observe writes, errors, cancellation, and the number of bytes it sent. It cannot confirm that the recipient kept the file in their Downloads folder.
That is the boundary of one-time download here: one completed server-side transfer. The browser may receive the response and the user may still discard it. RoomDrop cannot turn an HTTP response into proof that someone saved a file.
This distinction affects shutdown too. After a successful one-time transfer,
the session stops accepting downloads and uses graceful server shutdown to let
the current response finish. Closing its socket immediately could cut off the
response that just consumed the link. The
download implementation
keeps that sequence explicit.
Stop sharing reaches the running transfer
An explicit stop has a different purpose. The sender is asking to revoke access now, including work already underway.
RoomDrop changes the session state, stops the expiry timer, cancels the shared server context, and closes the HTTP server’s active connections. The transfer then finishes as interrupted. Expiry follows the same stop path.
The distinction in Go is useful: Server.Shutdown gives active requests time to
finish, while RoomDrop uses Server.Close when the sender stops the session.
The successful one-time path needs time to finish its response; manual
revocation needs to interrupt it.
The desktop window follows that contract as well. Closing it stops the session
and hides the window, leaving the app available in the system tray. The tray’s
Stop session action and app shutdown reach the same session manager. Those
connections are visible in
main.go.
Preparation needs cancellation too
There is work to stop before a link even exists. Multiple files and folders become a temporary ZIP on disk, which takes time and requires enough free space. RoomDrop finishes preparing that payload before opening the sharing listener.
ZIP creation reads through a context-aware reader. Stop can cancel that work, and the manager checks cancellation again before publishing the prepared session. That second check closes a race: canceled preparation must not finish later and produce a live sharing link.
During a session, cleanup waits until no transfers are using the payload. It then closes the file and attempts to remove the temporary ZIP, once. Original files are kept. A crash or forced process termination can leave the temporary archive behind, so this cleanup applies to the normal lifecycle.
The preparation and file handling are in
payload.go.
The session manager owns when those resources can be released.
Test the promises behind the controls
The useful regression cases follow directly from what the interface says:
- Open and preview a one-time link, fail a download, then retry successfully.
- Hold one download open and check that a concurrent request is rejected.
- Start a real HTTP download, read part of it, and stop the session before the rest arrives.
- Cancel ZIP preparation and check that no sharing session is published.
These cases are covered in the repository’s
session_test.go.
They check the consequences of One-time download and Stop sharing, including
the points where requests and background work overlap.
What a temporary link provides
RoomDrop binds to the selected local IPv4 address and an OS-assigned port. Each session gets a cryptographically random 256-bit token. The token makes the URL hard to guess; anyone who obtains an unprotected link and can reach the server can use it while the session is active.
Transfers use local HTTP, so file contents and optional download passwords are unencrypted. Password protection gates the download, while filenames and sizes remain visible on the page. The intended setting is a trusted local network; the link and its expiry do not provide transport encryption. The network notes describe those boundaries.
For me, this is what makes a small utility interesting to build. A checkbox and a stop button require decisions about retries, concurrent requests, response completion, cancellation, and resource ownership. Defining those outcomes gives the interface promises that the backend can actually enforce.