GCDWebServer.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /*
  2. Copyright (c) 2012-2015, Pierre-Olivier Latour
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * The name of Pierre-Olivier Latour may not be used to endorse
  12. or promote products derived from this software without specific
  13. prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY
  18. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #import <TargetConditionals.h>
  26. #import "GCDWebServerRequest.h"
  27. #import "GCDWebServerResponse.h"
  28. /**
  29. * The GCDWebServerMatchBlock is called for every handler added to the
  30. * GCDWebServer whenever a new HTTP request has started (i.e. HTTP headers have
  31. * been received). The block is passed the basic info for the request (HTTP method,
  32. * URL, headers...) and must decide if it wants to handle it or not.
  33. *
  34. * If the handler can handle the request, the block must return a new
  35. * GCDWebServerRequest instance created with the same basic info.
  36. * Otherwise, it simply returns nil.
  37. */
  38. typedef GCDWebServerRequest* (^GCDWebServerMatchBlock)(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery);
  39. /**
  40. * The GCDWebServerProcessBlock is called after the HTTP request has been fully
  41. * received (i.e. the entire HTTP body has been read). The block is passed the
  42. * GCDWebServerRequest created at the previous step by the GCDWebServerMatchBlock.
  43. *
  44. * The block must return a GCDWebServerResponse or nil on error, which will
  45. * result in a 500 HTTP status code returned to the client. It's however
  46. * recommended to return a GCDWebServerErrorResponse on error so more useful
  47. * information can be returned to the client.
  48. */
  49. typedef GCDWebServerResponse* (^GCDWebServerProcessBlock)(GCDWebServerRequest* request);
  50. /**
  51. * The GCDWebServerAsynchronousProcessBlock works like the GCDWebServerProcessBlock
  52. * except the GCDWebServerResponse can be returned to the server at a later time
  53. * allowing for asynchronous generation of the response.
  54. *
  55. * The block must eventually call "completionBlock" passing a GCDWebServerResponse
  56. * or nil on error, which will result in a 500 HTTP status code returned to the client.
  57. * It's however recommended to return a GCDWebServerErrorResponse on error so more
  58. * useful information can be returned to the client.
  59. */
  60. typedef void (^GCDWebServerCompletionBlock)(GCDWebServerResponse* response);
  61. typedef void (^GCDWebServerAsyncProcessBlock)(GCDWebServerRequest* request, GCDWebServerCompletionBlock completionBlock);
  62. /**
  63. * The port used by the GCDWebServer (NSNumber / NSUInteger).
  64. *
  65. * The default value is 0 i.e. let the OS pick a random port.
  66. */
  67. extern NSString* const GCDWebServerOption_Port;
  68. /**
  69. * The Bonjour name used by the GCDWebServer (NSString). If set to an empty string,
  70. * the name will automatically take the value of the GCDWebServerOption_ServerName
  71. * option. If this option is set to nil, Bonjour will be disabled.
  72. *
  73. * The default value is nil.
  74. */
  75. extern NSString* const GCDWebServerOption_BonjourName;
  76. /**
  77. * The Bonjour service type used by the GCDWebServer (NSString).
  78. *
  79. * The default value is "_http._tcp", the service type for HTTP web servers.
  80. */
  81. extern NSString* const GCDWebServerOption_BonjourType;
  82. /**
  83. * Request a port mapping in the NAT gateway (NSNumber / BOOL).
  84. *
  85. * This uses the DNSService API under the hood which supports IPv4 mappings only.
  86. *
  87. * The default value is NO.
  88. *
  89. * @warning The external port set up by the NAT gateway may be different than
  90. * the one used by the GCDWebServer.
  91. */
  92. extern NSString* const GCDWebServerOption_RequestNATPortMapping;
  93. /**
  94. * Only accept HTTP requests coming from localhost i.e. not from the outside
  95. * network (NSNumber / BOOL).
  96. *
  97. * The default value is NO.
  98. *
  99. * @warning Bonjour and NAT port mapping should be disabled if using this option
  100. * since the server will not be reachable from the outside network anyway.
  101. */
  102. extern NSString* const GCDWebServerOption_BindToLocalhost;
  103. /**
  104. * The maximum number of incoming HTTP requests that can be queued waiting to
  105. * be handled before new ones are dropped (NSNumber / NSUInteger).
  106. *
  107. * The default value is 16.
  108. */
  109. extern NSString* const GCDWebServerOption_MaxPendingConnections;
  110. /**
  111. * The value for "Server" HTTP header used by the GCDWebServer (NSString).
  112. *
  113. * The default value is the GCDWebServer class name.
  114. */
  115. extern NSString* const GCDWebServerOption_ServerName;
  116. /**
  117. * The authentication method used by the GCDWebServer
  118. * (one of "GCDWebServerAuthenticationMethod_...").
  119. *
  120. * The default value is nil i.e. authentication is disabled.
  121. */
  122. extern NSString* const GCDWebServerOption_AuthenticationMethod;
  123. /**
  124. * The authentication realm used by the GCDWebServer (NSString).
  125. *
  126. * The default value is the same as the GCDWebServerOption_ServerName option.
  127. */
  128. extern NSString* const GCDWebServerOption_AuthenticationRealm;
  129. /**
  130. * The authentication accounts used by the GCDWebServer
  131. * (NSDictionary of username / password pairs).
  132. *
  133. * The default value is nil i.e. no accounts.
  134. */
  135. extern NSString* const GCDWebServerOption_AuthenticationAccounts;
  136. /**
  137. * The class used by the GCDWebServer when instantiating GCDWebServerConnection
  138. * (subclass of GCDWebServerConnection).
  139. *
  140. * The default value is the GCDWebServerConnection class.
  141. */
  142. extern NSString* const GCDWebServerOption_ConnectionClass;
  143. /**
  144. * Allow the GCDWebServer to pretend "HEAD" requests are actually "GET" ones
  145. * and automatically discard the HTTP body of the response (NSNumber / BOOL).
  146. *
  147. * The default value is YES.
  148. */
  149. extern NSString* const GCDWebServerOption_AutomaticallyMapHEADToGET;
  150. /**
  151. * The interval expressed in seconds used by the GCDWebServer to decide how to
  152. * coalesce calls to -webServerDidConnect: and -webServerDidDisconnect:
  153. * (NSNumber / double). Coalescing will be disabled if the interval is <= 0.0.
  154. *
  155. * The default value is 1.0 second.
  156. */
  157. extern NSString* const GCDWebServerOption_ConnectedStateCoalescingInterval;
  158. #if TARGET_OS_IPHONE
  159. /**
  160. * Enables the GCDWebServer to automatically suspend itself (as if -stop was
  161. * called) when the iOS app goes into the background and the last
  162. * GCDWebServerConnection is closed, then resume itself (as if -start was called)
  163. * when the iOS app comes back to the foreground (NSNumber / BOOL).
  164. *
  165. * See the README.md file for more information about this option.
  166. *
  167. * The default value is YES.
  168. *
  169. * @warning The running property will be NO while the GCDWebServer is suspended.
  170. */
  171. extern NSString* const GCDWebServerOption_AutomaticallySuspendInBackground;
  172. #endif
  173. /**
  174. * HTTP Basic Authentication scheme (see https://tools.ietf.org/html/rfc2617).
  175. *
  176. * @warning Use of this authentication scheme is not recommended as the
  177. * passwords are sent in clear.
  178. */
  179. extern NSString* const GCDWebServerAuthenticationMethod_Basic;
  180. /**
  181. * HTTP Digest Access Authentication scheme (see https://tools.ietf.org/html/rfc2617).
  182. */
  183. extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
  184. @class GCDWebServer;
  185. /**
  186. * Delegate methods for GCDWebServer.
  187. *
  188. * @warning These methods are always called on the main thread in a serialized way.
  189. */
  190. @protocol GCDWebServerDelegate <NSObject>
  191. @optional
  192. /**
  193. * This method is called after the server has successfully started.
  194. */
  195. - (void)webServerDidStart:(GCDWebServer*)server;
  196. /**
  197. * This method is called after the Bonjour registration for the server has
  198. * successfully completed.
  199. *
  200. * Use the "bonjourServerURL" property to retrieve the Bonjour address of the
  201. * server.
  202. */
  203. - (void)webServerDidCompleteBonjourRegistration:(GCDWebServer*)server;
  204. /**
  205. * This method is called after the NAT port mapping for the server has been
  206. * updated.
  207. *
  208. * Use the "publicServerURL" property to retrieve the public address of the
  209. * server.
  210. */
  211. - (void)webServerDidUpdateNATPortMapping:(GCDWebServer*)server;
  212. /**
  213. * This method is called when the first GCDWebServerConnection is opened by the
  214. * server to serve a series of HTTP requests.
  215. *
  216. * A series of HTTP requests is considered ongoing as long as new HTTP requests
  217. * keep coming (and new GCDWebServerConnection instances keep being opened),
  218. * until before the last HTTP request has been responded to (and the
  219. * corresponding last GCDWebServerConnection closed).
  220. */
  221. - (void)webServerDidConnect:(GCDWebServer*)server;
  222. /**
  223. * This method is called when the last GCDWebServerConnection is closed after
  224. * the server has served a series of HTTP requests.
  225. *
  226. * The GCDWebServerOption_ConnectedStateCoalescingInterval option can be used
  227. * to have the server wait some extra delay before considering that the series
  228. * of HTTP requests has ended (in case there some latency between consecutive
  229. * requests). This effectively coalesces the calls to -webServerDidConnect:
  230. * and -webServerDidDisconnect:.
  231. */
  232. - (void)webServerDidDisconnect:(GCDWebServer*)server;
  233. /**
  234. * This method is called after the server has stopped.
  235. */
  236. - (void)webServerDidStop:(GCDWebServer*)server;
  237. @end
  238. /**
  239. * The GCDWebServer class listens for incoming HTTP requests on a given port,
  240. * then passes each one to a "handler" capable of generating an HTTP response
  241. * for it, which is then sent back to the client.
  242. *
  243. * GCDWebServer instances can be created and used from any thread but it's
  244. * recommended to have the main thread's runloop be running so internal callbacks
  245. * can be handled e.g. for Bonjour registration.
  246. *
  247. * See the README.md file for more information about the architecture of GCDWebServer.
  248. */
  249. @interface GCDWebServer : NSObject
  250. /**
  251. * Sets the delegate for the server.
  252. */
  253. @property(nonatomic, assign) id<GCDWebServerDelegate> delegate;
  254. /**
  255. * Returns YES if the server is currently running.
  256. */
  257. @property(nonatomic, readonly, getter=isRunning) BOOL running;
  258. /**
  259. * Returns the port used by the server.
  260. *
  261. * @warning This property is only valid if the server is running.
  262. */
  263. @property(nonatomic, readonly) NSUInteger port;
  264. /**
  265. * Returns the Bonjour name used by the server.
  266. *
  267. * @warning This property is only valid if the server is running and Bonjour
  268. * registration has successfully completed, which can take up to a few seconds.
  269. */
  270. @property(nonatomic, readonly) NSString* bonjourName;
  271. /**
  272. * Returns the Bonjour service type used by the server.
  273. *
  274. * @warning This property is only valid if the server is running and Bonjour
  275. * registration has successfully completed, which can take up to a few seconds.
  276. */
  277. @property(nonatomic, readonly) NSString* bonjourType;
  278. /**
  279. * This method is the designated initializer for the class.
  280. */
  281. - (instancetype)init;
  282. /**
  283. * Adds to the server a handler that generates responses synchronously when handling incoming HTTP requests.
  284. *
  285. * Handlers are called in a LIFO queue, so if multiple handlers can potentially
  286. * respond to a given request, the latest added one wins.
  287. *
  288. * @warning Addling handlers while the server is running is not allowed.
  289. */
  290. - (void)addHandlerWithMatchBlock:(GCDWebServerMatchBlock)matchBlock processBlock:(GCDWebServerProcessBlock)processBlock;
  291. /**
  292. * Adds to the server a handler that generates responses asynchronously when handling incoming HTTP requests.
  293. *
  294. * Handlers are called in a LIFO queue, so if multiple handlers can potentially
  295. * respond to a given request, the latest added one wins.
  296. *
  297. * @warning Addling handlers while the server is running is not allowed.
  298. */
  299. - (void)addHandlerWithMatchBlock:(GCDWebServerMatchBlock)matchBlock asyncProcessBlock:(GCDWebServerAsyncProcessBlock)processBlock;
  300. /**
  301. * Removes all handlers previously added to the server.
  302. *
  303. * @warning Removing handlers while the server is running is not allowed.
  304. */
  305. - (void)removeAllHandlers;
  306. /**
  307. * Starts the server with explicit options. This method is the designated way
  308. * to start the server.
  309. *
  310. * Returns NO if the server failed to start and sets "error" argument if not NULL.
  311. */
  312. - (BOOL)startWithOptions:(NSDictionary*)options error:(NSError**)error;
  313. /**
  314. * Stops the server and prevents it to accepts new HTTP requests.
  315. *
  316. * @warning Stopping the server does not abort GCDWebServerConnection instances
  317. * currently handling already received HTTP requests. These connections will
  318. * continue to execute normally until completion.
  319. */
  320. - (void)stop;
  321. @end
  322. @interface GCDWebServer (Extensions)
  323. /**
  324. * Returns the server's URL.
  325. *
  326. * @warning This property is only valid if the server is running.
  327. */
  328. @property(nonatomic, readonly) NSURL* serverURL;
  329. /**
  330. * Returns the server's Bonjour URL.
  331. *
  332. * @warning This property is only valid if the server is running and Bonjour
  333. * registration has successfully completed, which can take up to a few seconds.
  334. * Also be aware this property will not automatically update if the Bonjour hostname
  335. * has been dynamically changed after the server started running (this should be rare).
  336. */
  337. @property(nonatomic, readonly) NSURL* bonjourServerURL;
  338. /**
  339. * Returns the server's public URL.
  340. *
  341. * @warning This property is only valid if the server is running and NAT port
  342. * mapping is active.
  343. */
  344. @property(nonatomic, readonly) NSURL* publicServerURL;
  345. /**
  346. * Starts the server on port 8080 (OS X & iOS Simulator) or port 80 (iOS)
  347. * using the default Bonjour name.
  348. *
  349. * Returns NO if the server failed to start.
  350. */
  351. - (BOOL)start;
  352. /**
  353. * Starts the server on a given port and with a specific Bonjour name.
  354. * Pass a nil Bonjour name to disable Bonjour entirely or an empty string to
  355. * use the default name.
  356. *
  357. * Returns NO if the server failed to start.
  358. */
  359. - (BOOL)startWithPort:(NSUInteger)port bonjourName:(NSString*)name;
  360. #if !TARGET_OS_IPHONE
  361. /**
  362. * Runs the server synchronously using -startWithPort:bonjourName: until a
  363. * SIGINT signal is received i.e. Ctrl-C. This method is intended to be used
  364. * by command line tools.
  365. *
  366. * Returns NO if the server failed to start.
  367. *
  368. * @warning This method must be used from the main thread only.
  369. */
  370. - (BOOL)runWithPort:(NSUInteger)port bonjourName:(NSString*)name;
  371. /**
  372. * Runs the server synchronously using -startWithOptions: until a SIGTERM or
  373. * SIGINT signal is received i.e. Ctrl-C in Terminal. This method is intended to
  374. * be used by command line tools.
  375. *
  376. * Returns NO if the server failed to start and sets "error" argument if not NULL.
  377. *
  378. * @warning This method must be used from the main thread only.
  379. */
  380. - (BOOL)runWithOptions:(NSDictionary*)options error:(NSError**)error;
  381. #endif
  382. @end
  383. @interface GCDWebServer (Handlers)
  384. /**
  385. * Adds a default handler to the server to handle all incoming HTTP requests
  386. * with a given HTTP method and generate responses synchronously.
  387. */
  388. - (void)addDefaultHandlerForMethod:(NSString*)method requestClass:(Class)aClass processBlock:(GCDWebServerProcessBlock)block;
  389. /**
  390. * Adds a default handler to the server to handle all incoming HTTP requests
  391. * with a given HTTP method and generate responses asynchronously.
  392. */
  393. - (void)addDefaultHandlerForMethod:(NSString*)method requestClass:(Class)aClass asyncProcessBlock:(GCDWebServerAsyncProcessBlock)block;
  394. /**
  395. * Adds a handler to the server to handle incoming HTTP requests with a given
  396. * HTTP method and a specific case-insensitive path and generate responses
  397. * synchronously.
  398. */
  399. - (void)addHandlerForMethod:(NSString*)method path:(NSString*)path requestClass:(Class)aClass processBlock:(GCDWebServerProcessBlock)block;
  400. /**
  401. * Adds a handler to the server to handle incoming HTTP requests with a given
  402. * HTTP method and a specific case-insensitive path and generate responses
  403. * asynchronously.
  404. */
  405. - (void)addHandlerForMethod:(NSString*)method path:(NSString*)path requestClass:(Class)aClass asyncProcessBlock:(GCDWebServerAsyncProcessBlock)block;
  406. /**
  407. * Adds a handler to the server to handle incoming HTTP requests with a given
  408. * HTTP method and a path matching a case-insensitive regular expression and
  409. * generate responses synchronously.
  410. */
  411. - (void)addHandlerForMethod:(NSString*)method pathRegex:(NSString*)regex requestClass:(Class)aClass processBlock:(GCDWebServerProcessBlock)block;
  412. /**
  413. * Adds a handler to the server to handle incoming HTTP requests with a given
  414. * HTTP method and a path matching a case-insensitive regular expression and
  415. * generate responses asynchronously.
  416. */
  417. - (void)addHandlerForMethod:(NSString*)method pathRegex:(NSString*)regex requestClass:(Class)aClass asyncProcessBlock:(GCDWebServerAsyncProcessBlock)block;
  418. @end
  419. @interface GCDWebServer (GETHandlers)
  420. /**
  421. * Adds a handler to the server to respond to incoming "GET" HTTP requests
  422. * with a specific case-insensitive path with in-memory data.
  423. */
  424. - (void)addGETHandlerForPath:(NSString*)path staticData:(NSData*)staticData contentType:(NSString*)contentType cacheAge:(NSUInteger)cacheAge;
  425. /**
  426. * Adds a handler to the server to respond to incoming "GET" HTTP requests
  427. * with a specific case-insensitive path with a file.
  428. */
  429. - (void)addGETHandlerForPath:(NSString*)path filePath:(NSString*)filePath isAttachment:(BOOL)isAttachment cacheAge:(NSUInteger)cacheAge allowRangeRequests:(BOOL)allowRangeRequests;
  430. /**
  431. * Adds a handler to the server to respond to incoming "GET" HTTP requests
  432. * with a case-insensitive path inside a base path with the corresponding file
  433. * inside a local directory. If no local file matches the request path, a 401
  434. * HTTP status code is returned to the client.
  435. *
  436. * The "indexFilename" argument allows to specify an "index" file name to use
  437. * when the request path corresponds to a directory.
  438. */
  439. - (void)addGETHandlerForBasePath:(NSString*)basePath directoryPath:(NSString*)directoryPath indexFilename:(NSString*)indexFilename cacheAge:(NSUInteger)cacheAge allowRangeRequests:(BOOL)allowRangeRequests;
  440. @end
  441. /**
  442. * GCDWebServer provides its own built-in logging facility which is used by
  443. * default. It simply sends log messages to stderr assuming it is connected
  444. * to a terminal type device.
  445. *
  446. * GCDWebServer is also compatible with a limited set of third-party logging
  447. * facilities. If one of them is available at compile time, GCDWebServer will
  448. * automatically use it in place of the built-in one.
  449. *
  450. * Currently supported third-party logging facilities are:
  451. * - XLFacility (by the same author as GCDWebServer): https://github.com/swisspol/XLFacility
  452. * - CocoaLumberjack: https://github.com/CocoaLumberjack/CocoaLumberjack
  453. *
  454. * For both the built-in logging facility and CocoaLumberjack, the default
  455. * logging level is INFO (or DEBUG if the preprocessor constant "DEBUG"
  456. * evaluates to non-zero at compile time).
  457. *
  458. * It's possible to have GCDWebServer use a custom logging facility by defining
  459. * the "__GCDWEBSERVER_LOGGING_HEADER__" preprocessor constant in Xcode build
  460. * settings to the name of a custom header file (escaped like \"MyLogging.h\").
  461. * This header file must define the following set of macros:
  462. *
  463. * GWS_LOG_DEBUG(...)
  464. * GWS_LOG_VERBOSE(...)
  465. * GWS_LOG_INFO(...)
  466. * GWS_LOG_WARNING(...)
  467. * GWS_LOG_ERROR(...)
  468. * GWS_LOG_EXCEPTION(__EXCEPTION__)
  469. *
  470. * IMPORTANT: Except for GWS_LOG_EXCEPTION() which gets passed an NSException,
  471. * these macros must behave like NSLog(). Furthermore the GWS_LOG_DEBUG() macro
  472. * should not do anything unless the preprocessor constant "DEBUG" evaluates to
  473. * non-zero.
  474. *
  475. * The logging methods below send log messages to the same logging facility
  476. * used by GCDWebServer. They can be used for consistency wherever you interact
  477. * with GCDWebServer in your code (e.g. in the implementation of handlers).
  478. */
  479. @interface GCDWebServer (Logging)
  480. /**
  481. * Sets the log level of the logging facility below which log messages are discarded.
  482. *
  483. * @warning The interpretation of the "level" argument depends on the logging
  484. * facility used at compile time.
  485. *
  486. * If using the built-in logging facility, the log levels are as follow:
  487. * DEBUG = 0
  488. * VERBOSE = 1
  489. * INFO = 2
  490. * WARNING = 3
  491. * ERROR = 4
  492. * EXCEPTION = 5
  493. */
  494. + (void)setLogLevel:(int)level;
  495. /**
  496. * Logs a message to the logging facility at the VERBOSE level.
  497. */
  498. - (void)logVerbose:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
  499. /**
  500. * Logs a message to the logging facility at the INFO level.
  501. */
  502. - (void)logInfo:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
  503. /**
  504. * Logs a message to the logging facility at the WARNING level.
  505. */
  506. - (void)logWarning:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
  507. /**
  508. * Logs a message to the logging facility at the ERROR level.
  509. */
  510. - (void)logError:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
  511. /**
  512. * Logs an exception to the logging facility at the EXCEPTION level.
  513. */
  514. - (void)logException:(NSException*)exception;
  515. @end
  516. #ifdef __GCDWEBSERVER_ENABLE_TESTING__
  517. @interface GCDWebServer (Testing)
  518. /**
  519. * Activates recording of HTTP requests and responses which create files in the
  520. * current directory containing the raw data for all requests and responses.
  521. *
  522. * @warning The current directory must not contain any prior recording files.
  523. */
  524. @property(nonatomic, getter=isRecordingEnabled) BOOL recordingEnabled;
  525. /**
  526. * Runs tests by playing back pre-recorded HTTP requests in the given directory
  527. * and comparing the generated responses with the pre-recorded ones.
  528. *
  529. * Returns the number of failed tests or -1 if server failed to start.
  530. */
  531. - (NSInteger)runTestsWithOptions:(NSDictionary*)options inDirectory:(NSString*)path;
  532. @end
  533. #endif