RoutingHTTPServer.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #import <Foundation/Foundation.h>
  2. //! Project version number for Peertalk.
  3. FOUNDATION_EXPORT double RoutingHTTPServerVersionNumber;
  4. //! Project version string for Peertalk.
  5. FOUNDATION_EXPORT const unsigned char RoutingHTTPServerVersionString[];
  6. #import "HTTPServer.h"
  7. #import "HTTPConnection.h"
  8. #import "HTTPResponse.h"
  9. #import "RouteResponse.h"
  10. #import "RouteRequest.h"
  11. #import "RoutingConnection.h"
  12. #import "GCDAsyncSocket.h"
  13. typedef void (^RequestHandler)(RouteRequest *request, RouteResponse *response);
  14. @interface RoutingHTTPServer : HTTPServer
  15. @property (nonatomic, readonly) NSDictionary *defaultHeaders;
  16. // Specifies headers that will be set on every response.
  17. // These headers can be overridden by RouteResponses.
  18. - (void)setDefaultHeaders:(NSDictionary *)headers;
  19. - (void)setDefaultHeader:(NSString *)field value:(NSString *)value;
  20. // Returns the dispatch queue on which routes are processed.
  21. // By default this is NULL and routes are processed on CocoaHTTPServer's
  22. // connection queue. You can specify a queue to process routes on, such as
  23. // dispatch_get_main_queue() to process all routes on the main thread.
  24. - (dispatch_queue_t)routeQueue;
  25. - (void)setRouteQueue:(dispatch_queue_t)queue;
  26. - (NSDictionary *)mimeTypes;
  27. - (void)setMIMETypes:(NSDictionary *)types;
  28. - (void)setMIMEType:(NSString *)type forExtension:(NSString *)ext;
  29. - (NSString *)mimeTypeForPath:(NSString *)path;
  30. // Convenience methods. Yes I know, this is Cocoa and we don't use convenience
  31. // methods because typing lengthy primitives over and over and over again is
  32. // elegant with the beauty and the poetry. These are just, you know, here.
  33. - (void)get:(NSString *)path withBlock:(RequestHandler)block;
  34. - (void)post:(NSString *)path withBlock:(RequestHandler)block;
  35. - (void)put:(NSString *)path withBlock:(RequestHandler)block;
  36. - (void)delete:(NSString *)path withBlock:(RequestHandler)block;
  37. - (void)handleMethod:(NSString *)method withPath:(NSString *)path block:(RequestHandler)block;
  38. - (void)handleMethod:(NSString *)method withPath:(NSString *)path target:(id)target selector:(SEL)selector;
  39. - (BOOL)supportsMethod:(NSString *)method;
  40. - (RouteResponse *)routeMethod:(NSString *)method withPath:(NSString *)path parameters:(NSDictionary *)params request:(HTTPMessage *)request connection:(HTTPConnection *)connection;
  41. @end