FIRHTTPMetric.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import <Foundation/Foundation.h>
  15. #import "FIRPerformanceAttributable.h"
  16. // clang-format off
  17. // clang-format12 does a weird cascading indent of this enum.
  18. /* Different HTTP methods. */
  19. typedef NS_ENUM(NSInteger, FIRHTTPMethod) {
  20. /** HTTP Method GET */
  21. FIRHTTPMethodGET NS_SWIFT_NAME(get),
  22. /** HTTP Method PUT */
  23. FIRHTTPMethodPUT NS_SWIFT_NAME(put),
  24. /** HTTP Method POST */
  25. FIRHTTPMethodPOST NS_SWIFT_NAME(post),
  26. /** HTTP Method DELETE */
  27. FIRHTTPMethodDELETE NS_SWIFT_NAME(delete),
  28. /** HTTP Method HEAD */
  29. FIRHTTPMethodHEAD NS_SWIFT_NAME(head),
  30. /** HTTP Method PATCH */
  31. FIRHTTPMethodPATCH NS_SWIFT_NAME(patch),
  32. /** HTTP Method OPTIONS */
  33. FIRHTTPMethodOPTIONS NS_SWIFT_NAME(options),
  34. /** HTTP Method TRACE */
  35. FIRHTTPMethodTRACE NS_SWIFT_NAME(trace),
  36. /** HTTP Method CONNECT */
  37. FIRHTTPMethodCONNECT NS_SWIFT_NAME(connect)
  38. } NS_SWIFT_NAME(HTTPMethod);
  39. // clang-format on
  40. /**
  41. * FIRHTTPMetric object can be used to make the SDK record information about a HTTP network request.
  42. */
  43. NS_SWIFT_NAME(HTTPMetric)
  44. @interface FIRHTTPMetric : NSObject <FIRPerformanceAttributable>
  45. /**
  46. * Creates HTTPMetric object for a network request.
  47. * @param URL The URL for which the metrics are recorded.
  48. * @param httpMethod HTTP method used by the request.
  49. */
  50. - (nullable instancetype)initWithURL:(nonnull NSURL *)URL
  51. HTTPMethod:(FIRHTTPMethod)httpMethod
  52. NS_SWIFT_NAME(init(url:httpMethod:));
  53. /**
  54. * Use `initWithURL:HTTPMethod:` for Objective-C and `init(url:httpMethod:)` for Swift.
  55. */
  56. - (nonnull instancetype)init NS_UNAVAILABLE;
  57. /**
  58. * @brief HTTP Response code. Values are greater than 0.
  59. */
  60. @property(nonatomic, assign) NSInteger responseCode;
  61. /**
  62. * @brief Size of the request payload.
  63. */
  64. @property(nonatomic, assign) long requestPayloadSize;
  65. /**
  66. * @brief Size of the response payload.
  67. */
  68. @property(nonatomic, assign) long responsePayloadSize;
  69. /**
  70. * @brief HTTP Response content type.
  71. */
  72. @property(nonatomic, nullable, copy) NSString *responseContentType;
  73. /**
  74. * Marks the start time of the request.
  75. */
  76. - (void)start;
  77. /**
  78. * Marks the end time of the response and queues the network request metric on the device for
  79. * transmission. Check the logs if the metric is valid.
  80. */
  81. - (void)stop;
  82. @end