Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): support for content-length in fetch request #105

Merged
merged 4 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading