GCDWebServer.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  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. * Only accept HTTP requests coming from localhost i.e. not from the outside
  84. * network (NSNumber / BOOL).
  85. *
  86. * The default value is NO.
  87. *
  88. * @warning Bonjour should be disabled if using this option since the server
  89. * will not be reachable from the outside network anyway.
  90. */
  91. extern NSString* const GCDWebServerOption_BindToLocalhost;
  92. /**
  93. * The maximum number of incoming HTTP requests that can be queued waiting to
  94. * be handled before new ones are dropped (NSNumber / NSUInteger).
  95. *
  96. * The default value is 16.
  97. */
  98. extern NSString* const GCDWebServerOption_MaxPendingConnections;
  99. /**
  100. * The value for "Server" HTTP header used by the GCDWebServer (NSString).
  101. *
  102. * The default value is the GCDWebServer class name.
  103. */
  104. extern NSString* const GCDWebServerOption_ServerName;
  105. /**
  106. * The authentication method used by the GCDWebServer
  107. * (one of "GCDWebServerAuthenticationMethod_...").
  108. *
  109. * The default value is nil i.e. authentication is disabled.
  110. */
  111. extern NSString* const GCDWebServerOption_AuthenticationMethod;
  112. /**
  113. * The authentication realm used by the GCDWebServer (NSString).
  114. *
  115. * The default value is the same as the GCDWebServerOption_ServerName option.
  116. */
  117. extern NSString* const GCDWebServerOption_AuthenticationRealm;
  118. /**
  119. * The authentication accounts used by the GCDWebServer
  120. * (NSDictionary of username / password pairs).
  121. *
  122. * The default value is nil i.e. no accounts.
  123. */
  124. extern NSString* const GCDWebServerOption_AuthenticationAccounts;
  125. /**
  126. * The class used by the GCDWebServer when instantiating GCDWebServerConnection
  127. * (subclass of GCDWebServerConnection).
  128. *
  129. * The default value is the GCDWebServerConnection class.
  130. */
  131. extern NSString* const GCDWebServerOption_ConnectionClass;
  132. /**
  133. * Allow the GCDWebServer to pretend "HEAD" requests are actually "GET" ones
  134. * and automatically discard the HTTP body of the response (NSNumber / BOOL).
  135. *
  136. * The default value is YES.
  137. */
  138. extern NSString* const GCDWebServerOption_AutomaticallyMapHEADToGET;
  139. /**
  140. * The interval expressed in seconds used by the GCDWebServer to decide how to
  141. * coalesce calls to -webServerDidConnect: and -webServerDidDisconnect:
  142. * (NSNumber / double). Coalescing will be disabled if the interval is <= 0.0.
  143. *
  144. * The default value is 1.0 second.
  145. */
  146. extern NSString* const GCDWebServerOption_ConnectedStateCoalescingInterval;
  147. #if TARGET_OS_IPHONE
  148. /**
  149. * Enables the GCDWebServer to automatically suspend itself (as if -stop was
  150. * called) when the iOS app goes into the background and the last
  151. * GCDWebServerConnection is closed, then resume itself (as if -start was called)
  152. * when the iOS app comes back to the foreground (NSNumber / BOOL).
  153. *
  154. * See the README.md file for more information about this option.
  155. *
  156. * The default value is YES.
  157. *
  158. * @warning The running property will be NO while the GCDWebServer is suspended.
  159. */
  160. extern NSString* const GCDWebServerOption_AutomaticallySuspendInBackground;
  161. #endif
  162. /**
  163. * HTTP Basic Authentication scheme (see https://tools.ietf.org/html/rfc2617).
  164. *
  165. * @warning Use of this authentication scheme is not recommended as the
  166. * passwords are sent in clear.
  167. */
  168. extern NSString* const GCDWebServerAuthenticationMethod_Basic;
  169. /**
  170. * HTTP Digest Access Authentication scheme (see https://tools.ietf.org/html/rfc2617).
  171. */
  172. extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
  173. @class GCDWebServer;
  174. /**
  175. * Delegate methods for GCDWebServer.
  176. *
  177. * @warning These methods are always called on the main thread in a serialized way.
  178. */
  179. @protocol GCDWebServerDelegate <NSObject>
  180. @optional
  181. /**
  182. * This method is called after the server has successfully started.
  183. */
  184. - (void)webServerDidStart:(GCDWebServer*)server;
  185. /**
  186. * This method is called after the Bonjour registration for the server has
  187. * successfully completed.
  188. */
  189. - (void)webServerDidCompleteBonjourRegistration:(GCDWebServer*)server;
  190. /**
  191. * This method is called when the first GCDWebServerConnection is opened by the
  192. * server to serve a series of HTTP requests.
  193. *
  194. * A series of HTTP requests is considered ongoing as long as new HTTP requests
  195. * keep coming (and new GCDWebServerConnection instances keep being opened),
  196. * until before the last HTTP request has been responded to (and the
  197. * corresponding last GCDWebServerConnection closed).
  198. */
  199. - (void)webServerDidConnect:(GCDWebServer*)server;
  200. /**
  201. * This method is called when the last GCDWebServerConnection is closed after
  202. * the server has served a series of HTTP requests.
  203. *
  204. * The GCDWebServerOption_ConnectedStateCoalescingInterval option can be used
  205. * to have the server wait some extra delay before considering that the series
  206. * of HTTP requests has ended (in case there some latency between consecutive
  207. * requests). This effectively coalesces the calls to -webServerDidConnect:
  208. * and -webServerDidDisconnect:.
  209. */
  210. - (void)webServerDidDisconnect:(GCDWebServer*)server;
  211. /**
  212. * This method is called after the server has stopped.
  213. */
  214. - (void)webServerDidStop:(GCDWebServer*)server;
  215. @end
  216. /**
  217. * The GCDWebServer class listens for incoming HTTP requests on a given port,
  218. * then passes each one to a "handler" capable of generating an HTTP response
  219. * for it, which is then sent back to the client.
  220. *
  221. * GCDWebServer instances can be created and used from any thread but it's
  222. * recommended to have the main thread's runloop be running so internal callbacks
  223. * can be handled e.g. for Bonjour registration.
  224. *
  225. * See the README.md file for more information about the architecture of GCDWebServer.
  226. */
  227. @interface GCDWebServer : NSObject
  228. /**
  229. * Sets the delegate for the server.
  230. */
  231. @property(nonatomic, assign) id<GCDWebServerDelegate> delegate;
  232. /**
  233. * Returns YES if the server is currently running.
  234. */
  235. @property(nonatomic, readonly, getter=isRunning) BOOL running;
  236. /**
  237. * Returns the port used by the server.
  238. *
  239. * @warning This property is only valid if the server is running.
  240. */
  241. @property(nonatomic, readonly) NSUInteger port;
  242. /**
  243. * Returns the Bonjour name used by the server.
  244. *
  245. * @warning This property is only valid if the server is running and Bonjour
  246. * registration has successfully completed, which can take up to a few seconds.
  247. */
  248. @property(nonatomic, readonly) NSString* bonjourName;
  249. /**
  250. * Returns the Bonjour service type used by the server.
  251. *
  252. * @warning This property is only valid if the server is running and Bonjour
  253. * registration has successfully completed, which can take up to a few seconds.
  254. */
  255. @property(nonatomic, readonly) NSString* bonjourType;
  256. /**
  257. * This method is the designated initializer for the class.
  258. */
  259. - (instancetype)init;
  260. /**
  261. * Adds to the server a handler that generates responses synchronously when handling incoming HTTP requests.
  262. *
  263. * Handlers are called in a LIFO queue, so if multiple handlers can potentially
  264. * respond to a given request, the latest added one wins.
  265. *
  266. * @warning Addling handlers while the server is running is not allowed.
  267. */
  268. - (void)addHandlerWithMatchBlock:(GCDWebServerMatchBlock)matchBlock processBlock:(GCDWebServerProcessBlock)processBlock;
  269. /**
  270. * Adds to the server a handler that generates responses asynchronously when handling incoming HTTP requests.
  271. *
  272. * Handlers are called in a LIFO queue, so if multiple handlers can potentially
  273. * respond to a given request, the latest added one wins.
  274. *
  275. * @warning Addling handlers while the server is running is not allowed.
  276. */
  277. - (void)addHandlerWithMatchBlock:(GCDWebServerMatchBlock)matchBlock asyncProcessBlock:(GCDWebServerAsyncProcessBlock)processBlock;
  278. /**
  279. * Removes all handlers previously added to the server.
  280. *
  281. * @warning Removing handlers while the server is running is not allowed.
  282. */
  283. - (void)removeAllHandlers;
  284. /**
  285. * Starts the server with explicit options. This method is the designated way
  286. * to start the server.
  287. *
  288. * Returns NO if the server failed to start and sets "error" argument if not NULL.
  289. */
  290. - (BOOL)startWithOptions:(NSDictionary*)options error:(NSError**)error;
  291. /**
  292. * Stops the server and prevents it to accepts new HTTP requests.
  293. *
  294. * @warning Stopping the server does not abort GCDWebServerConnection instances
  295. * currently handling already received HTTP requests. These connections will
  296. * continue to execute normally until completion.
  297. */
  298. - (void)stop;
  299. @end
  300. @interface GCDWebServer (Extensions)
  301. /**
  302. * Returns the server's URL.
  303. *
  304. * @warning This property is only valid if the server is running.
  305. */
  306. @property(nonatomic, readonly) NSURL* serverURL;
  307. /**
  308. * Returns the server's Bonjour URL.
  309. *
  310. * @warning This property is only valid if the server is running and Bonjour
  311. * registration has successfully completed, which can take up to a few seconds.
  312. * Also be aware this property will not automatically update if the Bonjour hostname
  313. * has been dynamically changed after the server started running (this should be rare).
  314. */
  315. @property(nonatomic, readonly) NSURL* bonjourServerURL;
  316. /**
  317. * Starts the server on port 8080 (OS X & iOS Simulator) or port 80 (iOS)
  318. * using the default Bonjour name.
  319. *
  320. * Returns NO if the server failed to start.
  321. */
  322. - (BOOL)start;
  323. /**
  324. * Starts the server on a given port and with a specific Bonjour name.
  325. * Pass a nil Bonjour name to disable Bonjour entirely or an empty string to
  326. * use the default name.
  327. *
  328. * Returns NO if the server failed to start.
  329. */
  330. - (BOOL)startWithPort:(NSUInteger)port bonjourName:(NSString*)name;
  331. #if !TARGET_OS_IPHONE
  332. /**
  333. * Runs the server synchronously using -startWithPort:bonjourName: until a
  334. * SIGINT signal is received i.e. Ctrl-C. This method is intended to be used
  335. * by command line tools.
  336. *
  337. * Returns NO if the server failed to start.
  338. *
  339. * @warning This method must be used from the main thread only.
  340. */
  341. - (BOOL)runWithPort:(NSUInteger)port bonjourName:(NSString*)name;
  342. /**
  343. * Runs the server synchronously using -startWithOptions: until a SIGTERM or
  344. * SIGINT signal is received i.e. Ctrl-C in Terminal. This method is intended to
  345. * be used by command line tools.
  346. *
  347. * Returns NO if the server failed to start and sets "error" argument if not NULL.
  348. *
  349. * @warning This method must be used from the main thread only.
  350. */
  351. - (BOOL)runWithOptions:(NSDictionary*)options error:(NSError**)error;
  352. #endif
  353. @end
  354. @interface GCDWebServer (Handlers)
  355. /**
  356. * Adds a default handler to the server to handle all incoming HTTP requests
  357. * with a given HTTP method and generate responses synchronously.
  358. */
  359. - (void)addDefaultHandlerForMethod:(NSString*)method requestClass:(Class)aClass processBlock:(GCDWebServerProcessBlock)block;
  360. /**
  361. * Adds a default handler to the server to handle all incoming HTTP requests
  362. * with a given HTTP method and generate responses asynchronously.
  363. */
  364. - (void)addDefaultHandlerForMethod:(NSString*)method requestClass:(Class)aClass asyncProcessBlock:(GCDWebServerAsyncProcessBlock)block;
  365. /**
  366. * Adds a handler to the server to handle incoming HTTP requests with a given
  367. * HTTP method and a specific case-insensitive path and generate responses
  368. * synchronously.
  369. */
  370. - (void)addHandlerForMethod:(NSString*)method path:(NSString*)path requestClass:(Class)aClass processBlock:(GCDWebServerProcessBlock)block;
  371. /**
  372. * Adds a handler to the server to handle incoming HTTP requests with a given
  373. * HTTP method and a specific case-insensitive path and generate responses
  374. * asynchronously.
  375. */
  376. - (void)addHandlerForMethod:(NSString*)method path:(NSString*)path requestClass:(Class)aClass asyncProcessBlock:(GCDWebServerAsyncProcessBlock)block;
  377. /**
  378. * Adds a handler to the server to handle incoming HTTP requests with a given
  379. * HTTP method and a path matching a case-insensitive regular expression and
  380. * generate responses synchronously.
  381. */
  382. - (void)addHandlerForMethod:(NSString*)method pathRegex:(NSString*)regex requestClass:(Class)aClass processBlock:(GCDWebServerProcessBlock)block;
  383. /**
  384. * Adds a handler to the server to handle incoming HTTP requests with a given
  385. * HTTP method and a path matching a case-insensitive regular expression and
  386. * generate responses asynchronously.
  387. */
  388. - (void)addHandlerForMethod:(NSString*)method pathRegex:(NSString*)regex requestClass:(Class)aClass asyncProcessBlock:(GCDWebServerAsyncProcessBlock)block;
  389. @end
  390. @interface GCDWebServer (GETHandlers)
  391. /**
  392. * Adds a handler to the server to respond to incoming "GET" HTTP requests
  393. * with a specific case-insensitive path with in-memory data.
  394. */
  395. - (void)addGETHandlerForPath:(NSString*)path staticData:(NSData*)staticData contentType:(NSString*)contentType cacheAge:(NSUInteger)cacheAge;
  396. /**
  397. * Adds a handler to the server to respond to incoming "GET" HTTP requests
  398. * with a specific case-insensitive path with a file.
  399. */
  400. - (void)addGETHandlerForPath:(NSString*)path filePath:(NSString*)filePath isAttachment:(BOOL)isAttachment cacheAge:(NSUInteger)cacheAge allowRangeRequests:(BOOL)allowRangeRequests;
  401. /**
  402. * Adds a handler to the server to respond to incoming "GET" HTTP requests
  403. * with a case-insensitive path inside a base path with the corresponding file
  404. * inside a local directory. If no local file matches the request path, a 401
  405. * HTTP status code is returned to the client.
  406. *
  407. * The "indexFilename" argument allows to specify an "index" file name to use
  408. * when the request path corresponds to a directory.
  409. */
  410. - (void)addGETHandlerForBasePath:(NSString*)basePath directoryPath:(NSString*)directoryPath indexFilename:(NSString*)indexFilename cacheAge:(NSUInteger)cacheAge allowRangeRequests:(BOOL)allowRangeRequests;
  411. @end
  412. /**
  413. * GCDWebServer provides its own built-in logging facility which is used by
  414. * default. It simply sends log messages to stderr assuming it is connected
  415. * to a terminal type device.
  416. *
  417. * GCDWebServer is also compatible with a limited set of third-party logging
  418. * facilities. If one of them is available at compile time, GCDWebServer will
  419. * automatically use it in place of the built-in one.
  420. *
  421. * Currently supported third-party logging facilities are:
  422. * - XLFacility (by the same author as GCDWebServer): https://github.com/swisspol/XLFacility
  423. * - CocoaLumberjack: https://github.com/CocoaLumberjack/CocoaLumberjack
  424. *
  425. * For both the built-in logging facility and CocoaLumberjack, the default
  426. * logging level is INFO (or DEBUG if the preprocessor constant "DEBUG"
  427. * evaluates to non-zero at compile time).
  428. *
  429. * It's possible to have GCDWebServer use a custom logging facility by defining
  430. * the "__GCDWEBSERVER_LOGGING_HEADER__" preprocessor constant in Xcode build
  431. * settings to the name of a custom header file (escaped like \"MyLogging.h\").
  432. * This header file must define the following set of macros:
  433. *
  434. * GWS_LOG_DEBUG(...)
  435. * GWS_LOG_VERBOSE(...)
  436. * GWS_LOG_INFO(...)
  437. * GWS_LOG_WARNING(...)
  438. * GWS_LOG_ERROR(...)
  439. * GWS_LOG_EXCEPTION(__EXCEPTION__)
  440. *
  441. * IMPORTANT: Except for GWS_LOG_EXCEPTION() which gets passed an NSException,
  442. * these macros must behave like NSLog(). Furthermore the GWS_LOG_DEBUG() macro
  443. * should not do anything unless the preprocessor constant "DEBUG" evaluates to
  444. * non-zero.
  445. *
  446. * The logging methods below send log messages to the same logging facility
  447. * used by GCDWebServer. They can be used for consistency wherever you interact
  448. * with GCDWebServer in your code (e.g. in the implementation of handlers).
  449. */
  450. @interface GCDWebServer (Logging)
  451. /**
  452. * Sets the log level of the logging facility below which log messages are discarded.
  453. *
  454. * @warning The interpretation of the "level" argument depends on the logging
  455. * facility used at compile time.
  456. *
  457. * If using the built-in logging facility, the log levels are as follow:
  458. * DEBUG = 0
  459. * VERBOSE = 1
  460. * INFO = 2
  461. * WARNING = 3
  462. * ERROR = 4
  463. * EXCEPTION = 5
  464. */
  465. + (void)setLogLevel:(int)level;
  466. /**
  467. * Logs a message to the logging facility at the VERBOSE level.
  468. */
  469. - (void)logVerbose:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
  470. /**
  471. * Logs a message to the logging facility at the INFO level.
  472. */
  473. - (void)logInfo:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
  474. /**
  475. * Logs a message to the logging facility at the WARNING level.
  476. */
  477. - (void)logWarning:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
  478. /**
  479. * Logs a message to the logging facility at the ERROR level.
  480. */
  481. - (void)logError:(NSString*)format, ... NS_FORMAT_FUNCTION(1,2);
  482. /**
  483. * Logs an exception to the logging facility at the EXCEPTION level.
  484. */
  485. - (void)logException:(NSException*)exception;
  486. @end
  487. #ifdef __GCDWEBSERVER_ENABLE_TESTING__
  488. @interface GCDWebServer (Testing)
  489. /**
  490. * Activates recording of HTTP requests and responses which create files in the
  491. * current directory containing the raw data for all requests and responses.
  492. *
  493. * @warning The current directory must not contain any prior recording files.
  494. */
  495. @property(nonatomic, getter=isRecordingEnabled) BOOL recordingEnabled;
  496. /**
  497. * Runs tests by playing back pre-recorded HTTP requests in the given directory
  498. * and comparing the generated responses with the pre-recorded ones.
  499. *
  500. * Returns the number of failed tests or -1 if server failed to start.
  501. */
  502. - (NSInteger)runTestsWithOptions:(NSDictionary*)options inDirectory:(NSString*)path;
  503. @end
  504. #endif