Skip to content

Commit

Permalink
feat: Return headers on successful response (#265)
Browse files Browse the repository at this point in the history
* parsing headers into map writeabl map to be able to return it on succesful responses along with params value

* updated documentation

Co-authored-by: admin <[email protected]>
  • Loading branch information
JF-23 and admin committed Jul 17, 2021
1 parent e5f35df commit cbc3951
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ Event Data
|`id`|string|Required|The ID of the upload.|
|`responseCode`|string|Required|HTTP status code received|
|`responseBody`|string|Required|HTTP response body|
|`responseHeaders`|string|Required|HTTP response headers (Android)|

### cancelled

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class GlobalRequestObserverDelegate(reactContext: ReactApplicationContext) : Req
}

override fun onError(context: Context, uploadInfo: UploadInfo, exception: Throwable) {

val params = Arguments.createMap()
params.putString("id", uploadInfo.uploadId)

Expand All @@ -45,10 +44,15 @@ class GlobalRequestObserverDelegate(reactContext: ReactApplicationContext) : Req
}

override fun onSuccess(context: Context, uploadInfo: UploadInfo, serverResponse: ServerResponse) {
val headers = Arguments.createMap()
for ((key, value) in serverResponse.headers) {
headers.putString(key, value)
}
val params = Arguments.createMap()
params.putString("id", uploadInfo.uploadId)
params.putInt("responseCode", serverResponse.code)
params.putString("responseBody", serverResponse.bodyString)
params.putMap("responseHeaders", headers)
sendEvent("completed", params, context)
}

Expand Down

0 comments on commit cbc3951

Please sign in to comment.