-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(Feature)|Surface request metrics to response middleware #150
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool, URLSessionTaskMetrics
FTW! Nice work
let responseMiddleware = TransformingResponseMiddleware { taskResponse in | ||
var taskResponse = taskResponse | ||
XCTAssertGreaterThanOrEqual(taskResponse.metrics?.taskInterval.duration ?? 0, 2) | ||
expectation.fulfill() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Just one comment regarding accessibility modifiers.
R~
var data: Data? | ||
var response: HTTPURLResponse? | ||
var expectedContentLength: Int64? | ||
var error: Error? | ||
@available(iOS 10, *) | ||
lazy var metrics: URLSessionTaskMetrics? = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be public
, minus the expectedContentLength
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good catch! Saved me from doing a patch release :)
This pull request includes (pick all that apply):
Summary
In order to track request duration and other metrics, we want to expose this information via response middleware.
Requests metrics are provided by
URLSessionDataTask
viaURLSessionDataDelegate
(see changes inURLSessionClient.swift
, line 319):In the delegate method above, we store the collected metrics inside the task response structure. This structure is then passed to all response middleware in
synchronouslyProcessResponseMiddleware()
.Breaking changes
ResponsePipelineMiddleware
will have to be updated.Implementation
SessionDelegate
has been updated to capture request metrics inTaskResponse
.URLSessionClient
has been updated to passTaskResponse
to any response middleware.ResponsePipelineMiddleware
has been refactored to pass aTaskResponse
structure, which contains response data, HTTP response, error, and metrics, where available.URL
extension has been moved to test targets.@testable
imports have been removed where possible.Test Plan