Closed dstillman closed 5 years ago
I implemented a simple http request proxy function. Let me know if you want to rename or change something.
It can be called by sending a message performHttpRequest
with the userInfo
dictionary which can be passed by JS.
The dictionary should contain values based on the JS interface:
{String} url
{String} method
{Object} options
{Number} options.timeout
{Object} options.headers
{String} options.body
When the request responds I send back a message httpResponse
with data included in a dictionary:
{String} url
- url of http request{Number} statusCode
- status code of response{String} response
- optional string response, can be emptyIf the url is not specified or can't be parsed I send back the httpResponse
message with data {url: "missing/incorrect url", statusCode: -1, response: ""}
.
If the http method is not specified I send back the httpResponse
message with data {url: "url", statusCode: -2, response: ""}
.
@michalrentka Thanks for the intial impulse, this is now well in use.
We'll want a Swift function that makes arbitrary HTTP requests on behalf of the JS code and sends the response back to the injected script.
The JS interface is here:
https://github.com/zotero/zotero/blob/11990596125339875c46277deca8f10b1153378f/chrome/content/zotero/xpcom/http.js#L100-L130
Most of that can stay on the JS side, but we'll need at least
method
,url
,headers
, andbody
. The response can just be text.