Initial commit

This commit is contained in:
Jordan Goulder 2024-12-06 21:41:47 -05:00
commit 8eaa2c996a
3 changed files with 104 additions and 0 deletions

22
LICENSE.txt Normal file
View File

@ -0,0 +1,22 @@
MIT License
Copyright (c) 2024 Jordan Goulder
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

56
README.md Normal file
View File

@ -0,0 +1,56 @@
# netcat Web Server
Serve a web page and inspect HTTP requests using `netcat`.
## Usage
1. After cloning the repository, make sure that the `ncws.h` script is executable.
````sh
$ chmod +x ncws.h
````
3. Run the `ncws.h` script.
````sh
$ ./ncws.h
netcat web server
Listening on 0.0.0.0 8080
````
4. In another terminal, make a request to the server using `curl`.
````sh
$ curl http://127.0.0.1:8080
````
5. `netcat` will print the request and send a response.
````sh
...
Connection received on localhost 40790
GET / HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: curl/8.11.0
Accept: */*
````
6. `curl` should receive the response and print it.
````sh
$ curl http://127.0.0.1:8080
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello, World!</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
````
7. The script will then resume listening for more requests.
````sh
...
Listening on 0.0.0.0 8080
````
8. Press `CTRL-C` to terminate the script.

26
ncws.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/env bash
read -r -d '' HTML << EOM
HTTP/1.1 200 OK
Content-Type: text/html;
Server: netcat
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello, World!</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
EOM
echo "netcat web server"
while true; do
printf '%s' "$HTML" | netcat -v -N -l 8080;
done