bashttp/README.md

59 lines
1.6 KiB
Markdown
Raw Permalink Normal View History

2023-07-02 22:45:41 +00:00
# bashttp
A very goofy http server that runs scripts based of the given URI route
## Config
All routes and scripts must be layed out in a file called config, or you can specift the path by setting the `CONFIG_PATH` env variable.
2023-07-02 22:45:41 +00:00
An example config is shown below
```
GET / command.sh
POST /joe headers.sh
POST /echo body.sh
2023-07-02 22:45:41 +00:00
```
As shown above, each line is the method route given to run a given script.
2023-07-02 22:45:41 +00:00
2023-07-02 22:47:45 +00:00
## Scripts
Anything written to a scripts stdout will be treated as part of the HTTP Response.
2023-07-02 22:47:45 +00:00
Therefore the first things returned will be treated as headers. To stop reading headers, print a `\n` to stdout to
tell the HTTP Response that the headers have ended.
2023-07-03 03:44:48 +00:00
All content after the headers will be treated as the response body, and if the Status header is given, it will be treated as the http response code.
2023-07-03 03:44:48 +00:00
An example script that gives custom headers (with res code) is shown below:
```sh
#!/bin/bash
# print headers that will be returned
printf "Content-Type: text/plain\n"
printf "aaaaaaaa: AAAAAAAAAA\n"
2023-07-03 03:44:48 +00:00
printf "Status: 418\n" # return 418 im a teapot
printf "\n"
printf "joe\n"
```
2023-07-03 02:40:04 +00:00
Finally if you wish to read the request body given by the user, that is always stored in stdin. For example to create a echo endpoint:
```sh
#!/bin/bash
# even though we have no headers
# we still need to tell there will be no more headers
printf "\n"
2023-07-03 02:40:04 +00:00
# the body of any http request made will be stored in stdin
cat
```
2023-07-02 22:45:41 +00:00
## License
This project is licensed under the [WTFPL](https://www.wtfpl.net/)
## Warrenty
This project is probably not secure and if it beaks, uh... have fun
...wtfpl