RCTURLRequestHandler.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import <React/RCTBridgeModule.h>
  8. #import <React/RCTURLRequestDelegate.h>
  9. /**
  10. * Provides the interface needed to register a request handler. Request handlers
  11. * are also bridge modules, so should be registered using RCT_EXPORT_MODULE().
  12. */
  13. @protocol RCTURLRequestHandler <RCTBridgeModule>
  14. /**
  15. * Indicates whether this handler is capable of processing the specified
  16. * request. Typically the handler would examine the scheme/protocol of the
  17. * request URL (and possibly the HTTP method and/or headers) to determine this.
  18. */
  19. - (BOOL)canHandleRequest:(NSURLRequest *)request;
  20. /**
  21. * Send a network request and call the delegate with the response data. The
  22. * method should return a token, which can be anything, including the request
  23. * itself. This will be used later to refer to the request in callbacks. The
  24. * `sendRequest:withDelegate:` method *must* return before calling any of the
  25. * delegate methods, or the delegate won't recognize the token.
  26. * Following common Objective-C pattern, `delegate` will not be retained.
  27. */
  28. - (id)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequestDelegate>)delegate;
  29. @optional
  30. /**
  31. * Not all request types can be cancelled, but this method can be implemented
  32. * for ones that can. It should be used to free up any resources on ongoing
  33. * processes associated with the request.
  34. */
  35. - (void)cancelRequest:(id)requestToken;
  36. /**
  37. * If more than one RCTURLRequestHandler responds YES to `canHandleRequest:`
  38. * then `handlerPriority` is used to determine which one to use. The handler
  39. * with the highest priority will be selected. Default priority is zero. If
  40. * two or more valid handlers have the same priority, the selection order is
  41. * undefined.
  42. */
  43. - (float)handlerPriority;
  44. @end