Fix HTTP Body Generation for JSON Requests #16
Closed
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.
I ran into a tricky issue which I believe is a bug in PMHTTP, though I'm not entirely I'm using the API correctly.
When generating and performing a network request as following, the provided JSON is not transmitted as part of the HTTP body, instead the HTTP body is empty:
This can be fixed by extending the code that generates the upload body in
HTTPManager
to also check for a.json
body type.This code also seems to exist in the
preparedURLRequest
property (PMHTTP/Sources/HTTPManagerRequest.swift
Lines 483 to 503 in 19e9c57
I would assume a long term fix would be to incorporate this code into the actual HTTP body generation.
The test suite itself did not expose this bug, since it was calling
preparedURLRequest
, which had the side effect of generating the HTTP body correctly. As soon as that line was removed from the tests, they failed expectedly.This change is