Skip to content

dzove855/Bash-web-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bash-web-server

A purely bash web server, no socat, netcat, etc...

Requirement

How to

The port can be set by the env var: HTTP_PORT

The path to accept (Directory) can be set by using: BASH_LOADABLES_PATH (see man bash)

Server Methods:

  • serveHtml (needs DOCUMENT_ROOT envvars) - This will serve the static files
  • script file - The script need a file as first argument which will be source. The file will need a function named runner, which will be run on each request

Basic authentication can be enabled by env var: BASIC_AUTH, accounts and passwords are stored in the file specified in $BASIC_AUTH_FILE

Usage

Simple explication of various functions that could be used.

Session Handling

Variables:

    SESSION_COOKIE
        The name of the cookie : default BASHSESSID

Functions:

    sessionStart
        Start a session or reuse an existing session

    sessionSet $1 $2
        Set a session variable

    sessionGet $1 
        Get the value of the given variable

Cookie Handling

Functions:

    cookieSet $1 
        Send the cookie
        Example: cookieSet "BASHSESSID=12345; max-age=5000" 

HTTP Handling

Functions:

    httpSendStatus $1 
        Send the provided http status
        Example: httpSendStatus 200

    To set Headers, you should add an entry inside the assoc var HTTP_RESPONSE_HEADERS
        HTTP_RESPONSE_HEADERS["ExampleHeader"]="The value of the Header"

Websocket

!!!NOTE: This is still expiremental and only works for sendin data, not receiving!

Functions:

    websocketStart FUNCTION
        Start the websocket server

    websocketStop
        Stop the websocket server inside the function

About

A purely bash web server, no socat, netcat, etc...

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages