HTTP server written in x86_64 assembly language(GNU assembler) for Linux.
- Config file implementation
- Command line arguments
- Error reporting(including complaints about unknown args or words in config)
- Multi-threaded connection servicing
- Decoding characters in hexadecimal encoding in requests
- Buffered IO
- Checking http method and protocol version in requests
- Proper partial content request serving
- Directory listing
- Mime-types
- Root jail
- Logging
$ git clone https://github.com/M0x1m/http-server-assembly.git
binutils
package is required for building the server.
Building the server:
$ cd http-server-assembly
$ bash build.sh
$ ./server [{-d|--daemonize}, {-h|--help},
{--port=(binding port)}, {--root=(directory)},
{--host_addr=(ipv4 interface addr)},
{--config=(path to the server config)}]
The server without arguments will start according to the parameters of the
configuration file.
If configuration file cannot be found, the server's parameters will set to
built-in parameters:
Binding address: 0.0.0.0(All interfaces)
Binding port: 80
The server root directory: .
Default directory file: index.html
Enable default directory files: yes
Enable directory list: yes
Timeout: 90 000ms
Minimal permission: 4
Show hidden files(i.e. files whose names start with '.') in directory listing: yes
MIME-types file name: mime.types
Dirlist sorting: yes
Dirlist caching: yes
Cache directory: cache
Log file: server.log
Enable log to file: yes
Enable silent log: no
Table view dirlisting: yes
The server config parameters list:
server-port=<port>
server-binding-device-address=<ip>
server-root=<dir>
default-directory-file-name=<file>
enable-default-directory-files=<true|false>
enable-dirlisting=<true|false>
enable-custom-403-page=<true|false>
enable-custom-404-page=<true|false>
403-page-file-path=<path>
404-page-file-path=<path>
minimal-openning-permission=<num>
client-request-timeout=<num>
enable-hidden-files-in-dirlisting=<true|false>
mimetypes-file-path=<path>
enable-dirlists-sorting=<true|false>
enable-dirlists-caching=<true|false>
caches-directory-name=<dir>
log-file-path=<file>
enable-logging-to-file=<true|false>
enable-silent-logging=<true|false>
table-view-dirlisting=<true|false>
This parameter defines the server binding port.
This parameter defines the server binding address.
This parameter is used to bind the server to the specified network interface.
This parameter defines the server's root directory.
The client won't have access to files and directories below the server root.
This parameter the defines default file name of file that will be opened in requested directory when client requests a directory.
This parameter toggles opening files in requested directories by default file name when client requests a directory.
This parameter toggles sending HTML page of the directory content what client
had requested.
HTML page will be make and send if default directory file cannot be found or
default files are disabled.
This parameter defines path to 404 http error page.
Same as 404
This parameter toggles using of page described by 404-page-file-path option
Same as enable-custom-404-page
This parameter defines minimal permission for file or directory openning or
listing. If the permission less than this option the server sends 403 error
response.
The permission that the server checks have defined in others
permission
group of file or directory.
The permission parameter can be from 0(---) to 7(xwr). If the permission is
0
the server will try to open any files.
This parameter sets timeout in milliseconds for client request. If client timed out the server sends 408 error response.
enable-hidden-files-in-dirlisting
Files whose names start with .
are considered hidden. Thus this parameter
determines showing the files in directory listing whose name start with .
.
This parameter defines the path to MIME-types file instead of the built-in
path: mime.types
Mime types file syntax:
# <- Commentary
# Tabs and spaces allowed
# Types divided by newlines
# Type ------- Extensions
text/x-c c cc cxx cpp h hh hpp
text/html html htm
This parameter toggles sorting by name in directory listing.
WARNING: Sorting can doing long on directories with a lot of entries. For example directory with 14638 entries is sorted in 16.6 seconds(CPU: Athlon 64 X2 4200+ 2200MHz).
This parameter toggles caching a pages of directory listing.
This parameter determines a location of a cache files. Cache directory should not have any extrinsic files or directories.
This parameter determines a file name of a server log file. Server will write all logs with date and time to specified file.
This parameter toggles server logs writes to the log-file-path
This parameter toggles server logs writes to stdout. If specified true, the server will do not attempts to write to stdout, otherwise, if specified false, the server will writes logs only with time in stdout
This parameter toggles using of HTML table tags for dirlistings instead of simple list of links. If specified true, the server in dirlisting also writes modification time and size in row for each file in requested directory.
A comment in the config file defines by #
.
root=/home/user # This option specifies the server root directory.
List of arguments:
-d | --daemonize
--config=<file>
--port=<port>
--host_addr=<ip>
--root=<dir>
-h | --help
Daemonize the server(i.e. run the server in background).
This parameter specifies path to the server's configuration file.
Same as server-port config option
Same as server-binding-device-address config option
Same as server-root-directory config option
Prints usage message and list of the arguments.
x86_64 Linux syscall table:
https://chromium.googlesource.com/chromiumos/docs/+/master/constants/syscalls.md
Linux man pages:
https://man7.org/linux/man-pages/index.html
HTTP reference documentation:
https://developer.mozilla.org/en-US/docs/Web/HTTP#reference