FIRHTTPMetric.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. /* Different HTTP methods. */
  17. typedef NS_ENUM(NSInteger, FIRHTTPMethod) {
  18. /** HTTP Method GET */
  19. FIRHTTPMethodGET NS_SWIFT_NAME(get),
  20. /** HTTP Method PUT */
  21. FIRHTTPMethodPUT NS_SWIFT_NAME(put),
  22. /** HTTP Method POST */
  23. FIRHTTPMethodPOST NS_SWIFT_NAME(post),
  24. /** HTTP Method DELETE */
  25. FIRHTTPMethodDELETE NS_SWIFT_NAME(delete),
  26. /** HTTP Method HEAD */
  27. FIRHTTPMethodHEAD NS_SWIFT_NAME(head),
  28. /** HTTP Method PATCH */
  29. FIRHTTPMethodPATCH NS_SWIFT_NAME(patch),
  30. /** HTTP Method OPTIONS */
  31. FIRHTTPMethodOPTIONS NS_SWIFT_NAME(options),
  32. /** HTTP Method TRACE */
  33. FIRHTTPMethodTRACE NS_SWIFT_NAME(trace),
  34. /** HTTP Method CONNECT */
  35. FIRHTTPMethodCONNECT NS_SWIFT_NAME(connect)
  36. } NS_SWIFT_NAME(HTTPMethod);
  37. /**
  38. * FIRHTTPMetric object can be used to make the SDK record information about a HTTP network request.
  39. */
  40. NS_SWIFT_NAME(HTTPMetric)
  41. @interface FIRHTTPMetric : NSObject <FIRPerformanceAttributable>
  42. /**
  43. * Creates HTTPMetric object for a network request.
  44. * @param URL The URL for which the metrics are recorded.
  45. * @param httpMethod HTTP method used by the request.
  46. */
  47. - (nullable instancetype)initWithURL:(nonnull NSURL *)URL
  48. HTTPMethod:(FIRHTTPMethod)httpMethod NS_SWIFT_NAME(init(url:httpMethod:));
  49. /**
  50. * Use `initWithURL:HTTPMethod:` for Objective-C and `init(url:httpMethod:)` for Swift.
  51. */
  52. - (nonnull instancetype)init NS_UNAVAILABLE;
  53. /**
  54. * @brief HTTP Response code. Values are greater than 0.
  55. */
  56. @property(nonatomic, assign) NSInteger responseCode;
  57. /**
  58. * @brief Size of the request payload.
  59. */
  60. @property(nonatomic, assign) long requestPayloadSize;
  61. /**
  62. * @brief Size of the response payload.
  63. */
  64. @property(nonatomic, assign) long responsePayloadSize;
  65. /**
  66. * @brief HTTP Response content type.
  67. */
  68. @property(nonatomic, nullable, copy) NSString *responseContentType;
  69. /**
  70. * Marks the start time of the request.
  71. */
  72. - (void)start;
  73. /**
  74. * Marks the end time of the response and queues the network request metric on the device for
  75. * transmission. Check the logs if the metric is valid.
  76. */
  77. - (void)stop;
  78. @end