A small, lightweight, embeddable HTTP server for Mac OS X or iOS applications

Overview

CocoaHTTPServer

Build Status Version Platform License

CocoaHTTPServer is a small, lightweight, embeddable HTTP server for Mac OS X or iOS applications.

Sometimes developers need an embedded HTTP server in their app. Perhaps it's a server application with remote monitoring. Or perhaps it's a desktop application using HTTP for the communication backend. Or perhaps it's an iOS app providing over-the-air access to documents. Whatever your reason, CocoaHTTPServer can get the job done. It provides:

  • Built in support for bonjour broadcasting
  • IPv4 and IPv6 support
  • Asynchronous networking using GCD and standard sockets
  • Password protection support
  • SSL/TLS encryption support
  • Extremely FAST and memory efficient
  • Extremely scalable (built entirely upon GCD)
  • Heavily commented code
  • Very easily extensible
  • WebDAV is supported too!

Can't find the answer to your question in any of the [wiki](https://github.com/robbiehanson/CocoaHTTPServer/wiki) articles? Try the **[mailing list](http://groups.google.com/group/cocoahttpserver)**.

Love the project? Wanna buy me a coffee? (or a beer :D) [![donation](http://www.paypal.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BHF2DJRETGV5S)
Comments
  • iOS server socket dies on screen lock

    iOS server socket dies on screen lock

    It seems the server socket is dying when a device with iOS 5+ goes to sleep. This is easily reproducible with the iPhoneHTTPServer project. Just run it with the default configuration (connected to a WiFi network to verify that the server is reachable), then lock the device (the app can be in the foreground or in the background, doesn't matter) and unlock it again. Try to connect to the web server and the connection will be refused.

    opened by oscahie 18
  • iPhoneHTTPServer Sample working on simulator but not on device.

    iPhoneHTTPServer Sample working on simulator but not on device.

    Greetings I have implemented this in an iPhone App but neither my App nor the Sample iPhoneHTTPServer work for the device, they do work in the simulator though.

    When I use the wifiIP:port on my Mac(using any browser) which is on the same network of the iPhone it simply won't open the Page, but it doesn t give a 404 error either. Its like the page is there but it can't connect.

    "Unable to connect" "Firefox can't establish a connection to the server at 192.168.0.102:52395." "The site could be temporarily unavailable or too busy. Try again in a few moments. If you are unable to load any pages, check your computer's network connection. If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web."

    Any idea what might be causing this? I know I have to disable my Mac OS X firewall when I want to share a website on the local network is there something similar for the iPhone App?

    thanks

    opened by igorcarrasco 10
  • Bonjour announcing not working iOS8

    Bonjour announcing not working iOS8

    I looks like the Bonjour announcing does not work on iOS8 anymore. The service can be discovered but when trying to resolve the service:

    [serverService setDelegate:self]; [serverService resolveWithTimeout:30.0];

    I get a net service error:

    • (void)netService:(NSNetService *)sender didNotResolve:(NSDictionary *)errorDict

      NSNetServicesErrorCode = "-72007"; NSNetServicesErrorDomain = 10;

    It works perfectly using iOS7. Using Bonjour Browser on the Mac I get the same result. The service is found but cannot be resolved.

    I just tried the Apple WiTap sample and the result is the same. So this seems to be an core os issue rather than an issue with CocoaHTTPServer.

    opened by spameater 7
  • Permission denied when starting server on port 80

    Permission denied when starting server on port 80

    Great job with CocoaHTTPServer - it's very useful and easy to setup. When I try to start a site on port 80, however, I get the following error (port 12345 works fine). I'm using the same code as in the SimpleHTTPServer AppDelegate, with the setPort line uncommented. I see that this is a permissions error, so if applicable, sandboxing is disabled. Thanks for your help.

    2013-01-07 23:15:29:762 SimpleHTTPServer[14086:303] HTTPServer: Failed to start HTTP Server: Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied" UserInfo=0x10280c4d0 {NSLocalizedDescription=Permission denied, NSLocalizedFailureReason=Error in bind() function}

    2013-01-07 23:15:29:762 SimpleHTTPServer[14086:303] Error starting HTTP Server: Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied" UserInfo=0x10280c4d0 {NSLocalizedDescription=Permission denied, NSLocalizedFailureReason=Error in bind() function}

    opened by jackhumphries 5
  • Remove ARC

    Remove ARC

    It's a bit of an odd move to move to an ARC only solution for a library like this one. Sadly this will mean all projects have to have a minimum requirement of 64bit intel processors because ARC doesn't work on 32bit processors.

    Please move back to old fashioned memory management or even better: like other libraries do: hybrid.

    opened by GerTeunis 5
  • dispatch_get_current_queue usage at risk

    dispatch_get_current_queue usage at risk

    There appear to be 89 uses of dispatch_get_current_queue in the CocoaHTTPServer source. The headers for that API say "Recommended for debugging and logging purposes only" and Apple has gone out of its way lately to state that the API is unreliable, especially under ARC. If one were to look at certain SDKs that may or may not yet be public they might find even more stern wording.

    A lot of this usage seems benign and easily removable — it either synchronously or asynchronously invokes the block based on whether or not the desired queue is already in use — but other areas seem fundamentally built around the concept.

    It seems like storing context data on queue creation with dispatch_queue_set_specific, then reading it out with dispatch_get_specific, is the way to go moving forward for the kind of checks this project is currently using dispatch_get_current_queue to perform.

    Started 
    opened by drance 5
  • Core/Categories/DDData.m - The left operand of '&' is a garbage value

    Core/Categories/DDData.m - The left operand of '&' is a garbage value

    outbuf [0] = ( inbuf[0] << 2 ) | ( ( inbuf[1] & 0x30) >> 4 ); outbuf [1] = ( ( inbuf[1] & 0x0F ) << 4 ) | ( ( inbuf[2] & 0x3C ) >> 2 ); outbuf [2] = ( ( inbuf[2] & 0x03 ) << 6 ) | ( inbuf[3] & 0x3F );

    Theres some analyzer warnings on these lines in DDData.m

    opened by JulesMoorhouse 5
  • Videos won't load when Wifi and Data are off

    Videos won't load when Wifi and Data are off

    For some reason we no longer get responses for locally stored video requests when all data is turned off. This just started with a recent upgrade to iOS7. We were trying to troubleshoot but got a tad lost. We are using the HTTPFileResponse to open the files.

    When logging out file reads while the device was offline, I saw that it would request 2 bytes and then never request anymore. A successful video load would request 2 bytes and then start grabbing chunks.

    Our Setup

    We have the CocoaHTTPServer serving files for the UIWebView inorder to serve HTML content.

    To reproduce

    Turn wifi and data off on an iOS7 device and try to play a local video through HTML in the UIWebview

    Results

    With data off the device acts as if it cannot load the video file while loading html, pdf and jpg files before and after. The HTML5 video container gives a networkState of 3 which is NETWORK_NO_SOURCE.

    Expected Results

    The local video would load the same whether online or offline.

    I can provide logs or do additional troubleshooting if someone could help point me in the right direction.

    opened by ktilcu 4
  • CocoaLumberjack Subproject

    CocoaLumberjack Subproject

    I removed all CocoaLumberjack files directly included in repo in Vendor/CocoaLumberjack and added them as subrepository CocoaLumberjack to the same directory.

    It now contains the latest changes including dispach_get_current_queue deprecation warning fix.

    opened by Tricertops 4
  • Function definition won't do anything

    Function definition won't do anything

    HTTPConnection.m, line 2496.

    The following function won't do anything:

    • (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err; { ... }

    I think the semi-colon at the end of the function parameter list shouldn't be there.

    opened by dd105 4
  • Deployment Target 10.6: Is Snow Leopard compatibility still possible?

    Deployment Target 10.6: Is Snow Leopard compatibility still possible?

    I try to run the "SimpleFileUploadServer" sample under 10.6 Snow Leopard with no success because the app crashes. I use Mac OS X 10.8.2 and XCode 4.6 for development. With Montain Lion everthing runs smooth. Do I miss something here?

    opened by juergenkoller 3
  • CocoaHTTPServer 2.3.0 installed via cocoapods compile error

    CocoaHTTPServer 2.3.0 installed via cocoapods compile error

    Repro:

    1. Create a new mac application TestProject in objective c
    2. Add a Podfile with the following, then run pod install:
    def macos_version; '10.14' end
    platform :osx, macos_version
    use_frameworks!
    inhibit_all_warnings!
    
    workspace 'TestProject.xcworkspace'
    
    target 'TestProject' do
      project 'TestProject.xcodeproj'
      pod 'CocoaHTTPServer', '2.3.0'
    end
    
    1. Open the generated TestProject.xcworkspace
    2. Add #import <CocoaHTTPServer/HTTPServer.h> to any objc file, such as AppDelegate.m
    3. Observe it fails to build because of import order or something similar in the generated CocoaHTTPServer-umbrella.h

    CocoaHTTPServer 2.2.1 works just fine though.

    opened by Oleksiy-Yakovenko 0
  • I found a problem on product evn, here is error log , anyone can help?

    I found a problem on product evn, here is error log , anyone can help?

    I found a problem on product evn, here is error log , anyone can help?

    code = -1004 desc = Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={NSErrorFailingURLKey=http://localhost:49786/index.html?...., _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <A2E88C08-0CF7-462D-8EB9-D6F960983E65>.<16>, _kCFStreamErrorCodeKey=61, NSLocalizedDescription=Could not connect to the server., _WKRecoveryAttempterErrorKey=<WKReloadFrameErrorRecoveryAttempter: 0x2822d7560>, networkTaskDescription=LocalDataTask <A2E88C08-0CF7-462D-8EB9-D6F960983E65>.<16>, _kCFStreamErrorDomainKey=1, NSErrorFailingURLStringKey=http://localhost:49786/index.html?...., NSUnderlyingError=0x282c26010 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}}

    Originally posted by @free1990 in https://github.com/robbiehanson/CocoaHTTPServer/issues/204

    Originally posted by @Tonyvalony in https://github.com/Tonyvalony/Jorge-Torres-Torres-Torres-torres/issues/3

    opened by Tonyvalony 0
  • code = -1004  desc = Error Domain=NSURLErrorDomain Code=-1004

    code = -1004 desc = Error Domain=NSURLErrorDomain Code=-1004

    I found a problem on product evn, here is error log , anyone can help?

    code = -1004 desc = Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={NSErrorFailingURLKey=http://localhost:49786/index.html?...., _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <A2E88C08-0CF7-462D-8EB9-D6F960983E65>.<16>, _kCFStreamErrorCodeKey=61, NSLocalizedDescription=Could not connect to the server., _WKRecoveryAttempterErrorKey=<WKReloadFrameErrorRecoveryAttempter: 0x2822d7560>, networkTaskDescription=LocalDataTask <A2E88C08-0CF7-462D-8EB9-D6F960983E65>.<16>, _kCFStreamErrorDomainKey=1, NSErrorFailingURLStringKey=http://localhost:49786/index.html?...., NSUnderlyingError=0x282c26010 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}}

    opened by free1990 5
Owner
Robbie Hanson
Robbie Hanson
Super lightweight async HTTP server library in pure Swift runs in iOS / MacOS / Linux

Embassy Super lightweight async HTTP server in pure Swift. Please read: Embedded web server for iOS UI testing. See also: Our lightweight web framewor

Envoy 540 Dec 15, 2022
Lightweight library for web server applications in Swift on macOS and Linux powered by coroutines.

Why Zewo? • Support • Community • Contributing Zewo Zewo is a lightweight library for web applications in Swift. What sets Zewo apart? Zewo is not a w

Zewo 1.9k Dec 22, 2022
Tiny http server engine written in Swift programming language.

What is Swifter? Tiny http server engine written in Swift programming language. Branches * stable - lands on CocoaPods and others. Supports the latest

null 3.6k Dec 31, 2022
Swift HTTP server using the pre-fork worker model

Curassow Curassow is a Swift Nest HTTP Server. It uses the pre-fork worker model and it's similar to Python's Gunicorn and Ruby's Unicorn. It exposes

Kyle Fuller Archive 397 Oct 30, 2022
💧 A server-side Swift HTTP web framework.

Vapor is an HTTP web framework for Swift. It provides a beautifully expressive and easy-to-use foundation for your next website, API, or cloud project

Vapor 22.4k Jan 3, 2023
libuv base Swift web HTTP server framework

Notice Trevi now open a Trevi Community. Yoseob/Trevi project split up into respective Trevi, lime, middlewares and sys packages at our community. If

leeyoseob 46 Jan 29, 2022
A Swift web framework and HTTP server.

A Swift Web Framework and HTTP Server Summary Kitura is a web framework and web server that is created for web services written in Swift. For more inf

Kitura 7.6k Dec 27, 2022
Tiny http server engine written in Swift programming language.

What is Swifter? Tiny http server engine written in Swift programming language. Branches * stable - lands on CocoaPods and others. Supports the latest

null 3.6k Jan 5, 2023
HTTP Implementation for Swift on Linux and Mac OS X

Swift HTTP Server Simple HTTP implementation for Swift using POSIX socket API. Running on Mac OS X and Linux. For Mac users: You can install new Swift

Huy 451 Jul 28, 2022
A lightweight library for writing HTTP web servers with Swift

Taylor Disclaimer: Not actively working on it anymore. You can check out some alternatives Swift 2.0 required. Working with Xcode 7.1. Disclaimer: It

Jorge Izquierdo 925 Nov 17, 2022
PillowTalk - An iOS & SwiftUI server monitor tool for linux based machines using remote proc file system with script execution.

An iOS & SwiftUI server monitor tool for linux based machines using remote proc file system with script execution.

Lakr Aream 416 Dec 16, 2022
iOS Tweak to redirect Discord API calls to a Fosscord server.

FosscordTweak iOS Tweak to redirect Discord API calls to a Fosscord server. Installation Manual Download .deb file from release and install on jailbro

null 8 May 16, 2022
Frank is a DSL for quickly writing web applications in Swift

Frank Frank is a DSL for quickly writing web applications in Swift with type-safe path routing. Sources/main.swift import Frank // Handle GET request

Kyle Fuller Archive 376 Jan 3, 2023
Simple server APIs in Swift

Simple server APIs in Swift

null 4 Apr 25, 2022
Server-side Swift. The Perfect core toolset and framework for Swift Developers. (For mobile back-end development, website and API development, and more…)

Perfect: Server-Side Swift 简体中文 Perfect: Server-Side Swift Perfect is a complete and powerful toolbox, framework, and application server for Linux, iO

PerfectlySoft Inc. 13.9k Dec 29, 2022
Swift Express is a simple, yet unopinionated web application server written in Swift

Documentation <h5 align="right"><a href="http://demo.swiftexpress.io/">Live ?? server running Demo <img src="https://cdn0.iconfinder.com/data/icons/

Crossroad Labs 850 Dec 2, 2022
High Performance (nearly)100% Swift Web server supporting dynamic content.

Dynamo - Dynamic Swift Web Server Starting this project the intention was to code the simplest possible Web Server entirely in Swift. Unfortunately I

John Holdsworth 68 Jul 25, 2022
Swift backend / server framework (Pure Swift, Supports Linux)

NetworkObjects NetworkObjects is a #PureSwift backend. This framework compiles for OS X, iOS and Linux and serves as the foundation for building power

Alsey Coleman Miller 258 Oct 6, 2022
Reliable Server Side Swift ✭ Make Apache great again!

mod_swift mod_swift is a technology demo which shows how to write native modules for the Apache Web Server in the Swift 3 programming language. The de

The ApacheExpress Alliance 174 Oct 22, 2022