zotero / safari-app-extension

29 stars 5 forks source link

HTTP proxy function #1

Closed dstillman closed 5 years ago

dstillman commented 5 years ago

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, and body. The response can just be text.

michalrentka commented 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:

When the request responds I send back a message httpResponse with data included in a dictionary:

If 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: ""}.

adomasven commented 5 years ago

@michalrentka Thanks for the intial impulse, this is now well in use.