IcedHTTP is a small embedded HTTP server for MacOS and iOS apps
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
Classes
IcedHTTP.xcodeproj
IcedHTTP
.gitignore
Makefile
README.md

README.md

IcedHTTP

A very small HTTP Server framework suitable for embedding into iOS or Mac OS Apps,
maybe even tvOS or watchOS, haven't tried.

IcedHTTP has no dependencies, only four classes and ships with handler objects for serving
up files and executing a block of code when a request is received for a dynamic response.

Primary design goals are: small size, simple integration and scaleable to light workloads.

Based on TextTransfer Example App by Matt Gallagher

Usage

#import <Foundation/Foundation.h>
#import <IcedHTTP/IcedHttp.h>

int main(int argc, char** argv)
{
    @autoreleasepool {
        IHTTPServer* server = [IHTTPServer sharedIHTTPServer]; // TODO default to 8080 or use -p argument to set the port
        [server registerPrototype:[IHTTPHandler handlerWithResponseBlock: ^(IHTTPRequest* request, IHTTPResponse* response) {
            [response sendStatus:200];
            [response sendBody:[@"Hello Client" dataUsingEncoding:NSUTF8StringEncoding]]; // TODO one for each -s argument
            [response completeResponse];
            return (NSUInteger)200;
        }]];
        
        [server startServer];
        
        NSLog(@"server running http://localhost:8080"); // TODO server.URL
        
        [[NSRunLoop currentRunLoop] run]; // TODO runUntilDate checking on the server.status?
        
        [server stopServer];
    }
    return 0;
}

Building

A simple Makefile is provided to build the framework and documentation:

make build
make headerdoc
make clean

Theory of Operation

The IcedHTTP Server is intended for simple embedded applications which wish to share
a small set of files or some dynamic content while running in the foreground or, for a short time,
while the application is in the background, before it is terminated.

Full API Documnetation is avaliable after running make headerdoc.

Handler Prototypes

The IHTTPServer class uses handler prototypes to respond to multiple incoming requests
concurrently with low memory overhead:

  • After creating the IHTTPServer, register IHTTPHandler objects with registerPrototype
  • IHTTPRequsts are created when connections are made to the server, which calls canHandleRequest: on each prototype
  • The first handler which responds YES is cloned via handlerForRequest:
  • handleRequest:response: is called on the cloned handler

Changelog

1.0 : IcedHTTP.framework Initial Release

  • Create IcedHTTP.xcodeproject with IcedHTTP.framework targets for MacOS and iOS
  • Add this README.md and Makefile for automated builds
  • Rename classes with IHTTP prefix across the board
  • Convert to Modern Objective-C and ARC
  • Refactor request and response code into IHTTPRequest and IHTTPResponse
  • Add IHTTPHandler to allow for apps to easily add dynamic responses

1.1 : Improved Logging

Copyright & Licenses

The MIT License (MIT)

Copyright (c) 2015-2017 Alf Watt

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

TextTransfer Example App by Matt Gallagher

Created by Matt Gallagher on 2009/07/13.
Copyright 2009 Matt Gallagher. All rights reserved.

Permission is given to use this source code file, free of charge, in any
project, commercial or otherwise, entirely at your risk, with the condition
that any redistribution (in part or whole) of source code must retain
this copyright and permission notice. Attribution in compiled projects is
appreciated but not required.
<style type="text/css" style="visiblity: hidden !important;"> body { font-family: helvetica, helvetica-neue, san-serif; padding: 2em; } pre { border: 1px solid lightgray; padding: 1em; } code { border-bottom: 1px dashed lightgray; padding: .1em; line-height: 1.75em; } a { color: #111; } </style>