File tree Expand file tree Collapse file tree 1 file changed +35
-1
lines changed
packages/react-native-fast-io/android/src/main/java/com/margelo/nitro/fastio Expand file tree Collapse file tree 1 file changed +35
-1
lines changed Original file line number Diff line number Diff line change 11package com.margelo.nitro.fastio
22
3+ import android.util.Log
34import com.margelo.nitro.core.Promise
5+ import java.net.HttpURLConnection
6+ import java.net.URL
47
58class HybridNetwork : HybridNetworkSpec () {
69 override fun request (opts : RequestOptions ): Promise <Unit > {
7- throw NotImplementedError (" HybridNetwork.request() not implemented" )
10+ return Promise .async {
11+ val connection = URL (opts.url).openConnection() as HttpURLConnection
12+
13+ connection.apply {
14+ requestMethod = opts.method.name.uppercase()
15+ doInput = true
16+
17+ opts.body?.let { hybridStream ->
18+ (hybridStream as HybridInputStream ).stream.use { input ->
19+ outputStream.use { output ->
20+ val buffer = ByteArray (HybridStreamFactory .BUFFER_SIZE )
21+ var bytesRead: Int
22+
23+ while (input.read(buffer).also { bytesRead = it } != - 1 ) {
24+ output.write(buffer, 0 , bytesRead)
25+ output.flush() // Important: flush each chunk
26+ }
27+ }
28+ }
29+ }
30+
31+ connect()
32+
33+ if (responseCode in 200 .. 299 ) {
34+ // tbd
35+ } else {
36+ throw Error (" HTTP Error: $responseCode " )
37+ }
38+ }
39+
40+ connection.disconnect()
41+ }
842 }
943
1044 override val memorySize: Long
You can’t perform that action at this time.
0 commit comments