Skip to content

Commit

Permalink
fix(android): support for content-length in fetch request (#105)
Browse files Browse the repository at this point in the history
Co-authored-by: Joseph Pender <[email protected]>
  • Loading branch information
PratikBodawala and theproducer authored Sep 6, 2024
1 parent e9dad48 commit 7adb608
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 32 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-worms-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@capacitor/background-runner": minor
---

(Android) Adding support for Content-Length in fetch requests
16 changes: 8 additions & 8 deletions .github/workflows/reusable_build-packages.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
name: "Build Packages"

on:
on:
workflow_call:
secrets:
CAP_GH_RELEASE_TOKEN:
required: true

jobs:
build:
runs-on: 'ubuntu-22.04'
runs-on: "ubuntu-22.04"
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.CAP_GH_RELEASE_TOKEN }}
token: ${{ secrets.CAP_GH_RELEASE_TOKEN || github.token }}

- name: 'Setup Tools'
- name: "Setup Tools"
uses: ./.github/actions/setup-tools

- uses: nrwl/nx-set-shas@v3
with:
main-branch-name: 'main'
main-branch-name: "main"

- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
distribution: "temurin"
java-version: "17"

- name: 'Build Packages'
- name: "Build Packages"
shell: bash
run: |
pnpm nx affected --target=build
12 changes: 6 additions & 6 deletions .github/workflows/reusable_lint-packages.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
name: "Lint Packages"

on:
on:
workflow_call:
secrets:
CAP_GH_RELEASE_TOKEN:
required: true

jobs:
lint:
runs-on: 'macos-12'
runs-on: "macos-12"
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.CAP_GH_RELEASE_TOKEN }}
token: ${{ secrets.CAP_GH_RELEASE_TOKEN || github.token }}

- name: 'Setup Tools'
- name: "Setup Tools"
uses: ./.github/actions/setup-tools

- uses: nrwl/nx-set-shas@v3
with:
main-branch-name: 'main'
main-branch-name: "main"

- name: 'Lint Packages'
- name: "Lint Packages"
shell: bash
run: |
pnpm nx affected --target=lint
14 changes: 7 additions & 7 deletions .github/workflows/reusable_setup.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "Setup"

on:
on:
workflow_call:
secrets:
CAP_GH_RELEASE_TOKEN:
Expand All @@ -10,21 +10,21 @@ jobs:
setup:
strategy:
matrix:
os: ['ubuntu-22.04', 'macos-12']
os: ["ubuntu-22.04", "macos-12"]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.CAP_GH_RELEASE_TOKEN }}
token: ${{ secrets.CAP_GH_RELEASE_TOKEN || github.token }}

- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
distribution: "temurin"
java-version: "17"

- name: 'Setup Tools'
- name: "Setup Tools"
uses: ./.github/actions/setup-tools
with:
skip-install-on-cache-hit: 'true'
skip-install-on-cache-hit: "true"
14 changes: 6 additions & 8 deletions .github/workflows/reusable_unit-tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "Unit Tests"

on:
on:
workflow_call:
secrets:
CAP_GH_RELEASE_TOKEN:
Expand All @@ -14,29 +14,27 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.CAP_GH_RELEASE_TOKEN }}
token: ${{ secrets.CAP_GH_RELEASE_TOKEN || github.token }}
- name: List available Xcode versions
run: ls /Applications | grep Xcode
- name: Select Xcode
run: sudo xcode-select -switch /Applications/Xcode_14.3.1.app && /usr/bin/xcodebuild -version
- name: Run ios-engine unit tests
run: cd ./packages/ios-engine && swift package clean && swift test

unit-test-android:
runs-on: macos-13
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.CAP_GH_RELEASE_TOKEN }}
- name: 'Running Android Unit Tests'
uses: reactivecircus/android-emulator-runner@v2
token: ${{ secrets.CAP_GH_RELEASE_TOKEN || github.token }}
- name: "Running Android Unit Tests"
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
working-directory: ./packages/android-js-engine
emulator-options: -no-window -no-audio -no-boot-anim -accel on -no-snapshot-save
profile: pixel_6
script: ./gradlew connectedCheck


Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,18 @@ class NativeWebAPI {
connection.setRequestProperty(it.key, it.value)
}

if (options.body != null) {
val requestBody = options.body
if (requestBody != null) {
connection.doOutput = true
connection.setChunkedStreamingMode(0)
val contentEncoding = options.headers["Transfer-Encoding"]
if (contentEncoding == "chunked") {
connection.setChunkedStreamingMode(0)
} else {
connection.setFixedLengthStreamingMode(requestBody.size)
}

val output = BufferedOutputStream(connection.outputStream)
output.write(options.body)
output.write(requestBody)
output.flush()
}
}
Expand Down

0 comments on commit 7adb608

Please sign in to comment.