AlwaysLoveme / capacitor-plugin-filedownload

a file download plugin for Capacitor3.0+
MIT License
13 stars 7 forks source link

don't change Http method to POST just because I add headers #14

Open robwatt opened 1 year ago

robwatt commented 1 year ago

Your documentation states that if I add headers you will change the http method from PUT to POST.

In your Android source you don't do that, in your iOS source you do. I believe the Android source is correct, and iOS is a bug - and it should only switch if you add a BODY; although I would perhaps suggest that you also give the user an option to specify what HTTP method they would like to use instead.

Reason being: I need to do a GET for my file, but I also need to add some headers for authorization, and some others things (changing the method is not an option). By adding this you switch the method to a POST which will fail. Plus as I stated above your Android and iOS behaviours differ.

From your Java source - note only changed based on the fact there is a body.

JSObject requestBodyObject = call.getObject("body", null);
if (requestBodyObject != null) {
  // code removed for clarity
  requestBuilder.method("POST", requestBody);
}

From your swift source - note changed even if I add a header

let method = !headers.isEmpty || body != nil ? HTTPMethod.post : HTTPMethod.get