This project demonstrates password protecting a specific resource. More specifically, the project allows unrestricted access to the ~/Sites folder, but requires a password for anything in the ~/Sites/secret/ subfolder.
Create the following folder: ~/Sites/secret
And then add a file to it. For example: ~/Sites/secret/doc.txt
Open the Xcode project, and build and go.
On the Xcode console you'll see a message saying something like: "Started HTTP server on port 59123"
The actual port the server uses is not hard-coded. You can hard-code it if you want, but by default it will just allow the operating system to provide an available port.
Now open your browser and type the URL (replacing with the proper port):
Notice that it displays your file without password prompt:
Now type the URL (replacing with password prompt):
Notice that it prompts you for a username/password. The sample code accepts any username, and the password is "secret".
(Replace 59123 with whatever port the server is actually running on.)