2

I want to setup a local HTTP Server running in my Mac OSX machine which should be able to handle requests that are coming from web browser. But I am not sure whether we can setup HTTPS server using swift. In this https://swift.org/server-apis/ there is only info about HTTP but not HTTPS. Any help is very much appreciated

  • Does it have to be written in Swift? Are you developing or writing the code yourselves? – Graham Miln Aug 2 '18 at 9:43
  • Yes it has to be written in swift. I want to write it myself – Lalitha Syamaleswari ch Aug 2 '18 at 10:43
  • 1
    Please be aware that code level questions are off-topic here and should be asked on StackOverflow. – nohillside Aug 2 '18 at 11:10
5

Yes, Apple's Swift language can be used to create a web server that accepts HTTPS connections. See Going Server-side with Swift Open Source for Apple's introduction to developing servers.

Using Swift, you have access to a range of included and third party SSL/TLS libraries. The language used to write the library is not important, so long as the library offers a C API.

Network.framework and AFNetworking

If you are a developer, consider using Apple's Network framework. The framework claims to provide easier support for secure connections.

Alternatively, look at using the open source project AFNetworking.

Apple's Frameworks

Given you want to focus on Apple's security offerings, you can pick from:

  • Apple's Network.framework (in beta at the time of answering)
  • Apple's NSURL* family of classes
  • Apple's CFNetwork
  • Apple's Secure Transport API

Be aware that most of these are ultimately built upon the low level Common Crypto code base.

Transparent Proxy

Consider using an existing web server, such as Nginx, httpd, or Caddy, to act as a transparent proxy in-front of your own service. The existing web server can handle the SSL/TLS security and pass back HTTP requests to your locally running service.

This is a fairly common configuration because it simplifies your service and puts the security burden on a well tested existing front-end server.

Not a developer?

If you are not a developer, consider using a pre-built web server with support for Lets Encrypt (free) TLS certificates. One such server is Caddy:

Caddy is the HTTP/2 web server with automatic HTTPS.

  • I don't want to relay on third party libraries that were mentioned in (Going Server-side with Swift Open Source). I want to setup it using native swift code. I will try using AFNetworking. Thank you – Lalitha Syamaleswari ch Aug 2 '18 at 10:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .