Fixes several issues with local HTTP requests #30
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.
From https://community.webcore.co/t/xml-response-handling-from-web-request/878/31
PR just for ease of seeing the changes; showing bits of code in Discourse was not working well for this one.
$httpContentType
is nullThe
wc_async_reply
event is expecting acontentType
parameter butlocalHttpRequestHandler
does not provide it. AddedcontentType: mediaType
to the event data.mediaType
can include charset and boundarymediaType
inlocalHttpRequestHandler
is just the Content-Type header; the charset needs to be removed (i.e. passingcontentType: mediaType
gives me a value ofapplication/json; charset=utf-8
.response.body
is not availableThe
localHttpRequestHandler
does not pass along the response body, only any json that is parsed from it. Instead, both the json and raw response body should be passed. Note that changes towc_async_reply
could also affectasyncHttpRequestHandler
but it didn't look like anything would break.Tweaked
localHttpRequestHandler
to passresponseData: data, jsonData: json
then updated the event handler.json response can't have leading or trailing whitespace
The
startsWith
andendsWith
calls should operate on a trimmed value:hubResponse.json
may be simpler option here, but maybe not. It caused problems when I tried to parse JSON data that is not an array or object (e.g."text"
or5
ornull
)Is
$response.data.*
a thing?I thought I remembered
$response.data.*
being used to access JSON values, like{"test": "test"}
accessed as$response.data.test
, but I think I was mistaken because I couldn't find any code that does it. If that does happen for normal requests this PR does not address it for locals, you would access the request with$response.test
(which I think is the correct way anyway, just making sure).