Skip to content
/ listen Public

A tiny HTTP server with support for SSL and POST requests only

Notifications You must be signed in to change notification settings

ArfNtz/listen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Listener

A tiny HTTP server with support for SSL and POST requests only

Language Swift 5 macOS Linux License: MIT

Motivation

  • easy code integration into other projects
  • less dependency when nginx/apache is not needed

Features

  • non blocking multithread I/O
  • linux and macOS compatible
  • open source development environment and dependencies
  • library and command line executable
  • kiss (keep it stupid simple) : minimal code

Dependencies

  • Foundation, SwiftNIO, SwiftNIOSSL

Development tools

  • VSCode
  • LLDB
  • Sourcekit-LSP

Testing platforms

  • macOS 10.15
  • Linux Ubuntu 18.04.

Build

$ swift build -c release

Use

Launch the server :

$ ./.build/release/listener
Use : $ listener <host> <port> <certFile> <keyFile> <numberOfThreads> <maxBodySize>
Example : $ listener localhost 8888 cert.pem key.pem 4 4096
host: localhost, port: 8888, cert: cert.pem, key: key.pem, nbThread: 4, maxBodySize: 65535
Server started and listening on [IPv6]::1/::1:8888 with 4 threads and maxBodySize 65535

Test (post some data to the https server launched ) using curl :

$ echo "content to be sent" > myTextFile.txt
$ curl -k --data-binary "@myTextFile.txt" --output - https://localhost:8888
content to be sent

In a swift program :

try HTTPServer().serve(host:host, port:port, cert:cert, key:key, nbThread:nbThread, maxBodySize:maxBodySize, action: Echo())

Code

VSCode files are located in the .vscode directory. They provide launch and task configurations for debug and test. These configurations can be used with "Native Debug" or "CodeLLDB" extensions.

Test

$ swift test
[8/8] Linking listenPackageTests.xctest
Test Suite 'All tests' started at 2020-02-11 11:57:46.592
Test Suite 'debug.xctest' started at 2020-02-11 11:57:46.596
Test Suite 'listenTests' started at 2020-02-11 11:57:46.596
Test Case 'listenTests.testExample' started at 2020-02-11 11:57:46.596
host: localhost, port: 8888, cert: cert.pem, key: key.pem, nbThread: 4, maxBodySize: 65535
Server started and listening on [IPv4]127.0.0.1/127.0.0.1:8888 with 4 threads and maxBodySize 65535

About

A tiny HTTP server with support for SSL and POST requests only

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages