Make URLSession client honor the HTTP status code#241
Merged
Conversation
`APNSURLSessionClient.send` decided success vs. failure purely by whether the response body decoded as an `APNSErrorResponse`, ignoring the HTTP status code, and threw `urlResponseNotFound` whenever the `apns-id` header was absent. As a result a non-2xx response with an empty/non-JSON body was reported as success, and an error response without `apns-id` surfaced as `urlResponseNotFound` instead of a typed `APNSError`. - Treat `statusCode == 200` as success (per Apple's APNs spec); decode the error body on any other status, falling back to the status code alone when absent. - Look up response headers via the case-insensitive `value(forHTTPHeaderField:)` and tolerate a missing `apns-id`. - Add the `APNSURLSession` target to the test target (both manifests) and an `APNSURLSessionClientTests` suite covering success, header propagation, and the bad-device-token / missing-topic error paths against `APNSTestServer`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
APNSURLSessionClient.senddetermined success/failure purely by whether the response body decoded as anAPNSErrorResponse, ignoring the HTTP status code, and threwurlResponseNotFoundwhenever theapns-idheader was missing. Consequences:APNSResponse.apns-idheader surfaced asurlResponseNotFoundrather than a typedAPNSError.The NIO
APNSClientalready keys offresponse.status == .ok; this brings the URLSession client in line.Changes
statusCode == 200as success; on any other status, decode the error body when present and otherwise surface the status code alone.value(forHTTPHeaderField:)and tolerate a missingapns-id.APNSURLSessiontarget to the test target in bothPackage.swiftandPackage@swift-5.10.swift.APNSURLSessionClientTests(previously the entire target had zero tests) covering success, header propagation, bad-device-token, and missing-topic, exercised againstAPNSTestServer.Testing
swift test— 76 tests pass (up from 72).