You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
974 B
Objective-C
44 lines
974 B
Objective-C
#ifndef HTTP_H
|
|
#define HTTP_H
|
|
|
|
#import "socket.h"
|
|
#import "lambda.h"
|
|
|
|
static NSString *httpHeader = @"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
|
|
static NSString *httpMultipart = @"HTTP/1.1 200 OK\r\nContent-Type: multipart/form-data\r\n\r\n";
|
|
|
|
enum RequestType {
|
|
GET = 0,
|
|
POST = 1,
|
|
};
|
|
|
|
@interface HTTPRequest : NSObject {
|
|
NSString *type;
|
|
NSString *uri;
|
|
NSString *host;
|
|
}
|
|
@property (assign,nonatomic) NSString *type;
|
|
@property (assign,nonatomic) NSString *uri;
|
|
@property (assign,nonatomic) NSString *host;
|
|
+(id) parseRequest: (NSString *) req;
|
|
@end
|
|
|
|
@interface HTTPServer : NSObject {
|
|
NSSocket *sock;
|
|
NSMutableDictionary *handlers;
|
|
bool open;
|
|
}
|
|
|
|
+(id) httpServerWithPort: (int) port;
|
|
-(id) read;
|
|
-(BOOL) listen;
|
|
-(BOOL) write: (NSString *) data;
|
|
-(BOOL) writeData: (NSData *) data;
|
|
-(void) close;
|
|
-(void) assignHandler: (NSLambda *) handler to: (NSString *) url;
|
|
-(void) handleRequest: (HTTPRequest *) req;
|
|
-(void) handleURI: (NSString *) URI;
|
|
@end
|
|
|
|
#endif
|