Skip to content

Conversation

ArnyminerZ
Copy link
Member

Purpose

Migrate the current okhttp implementation to ktor.

Short description

  • Added the ktor dependency.
  • Remove unused okhttp dependencies.
  • Migrated MockWebServer usages to Ktor's mock server, using a custom wrapper to simplify the structure.
  • Simplified URLs in tests with the utility functions provided by ktor.
  • The http engine for Ktor is injected using Hilt.

Checklist

  • The PR has a proper title, description and label.
  • I have self-reviewed the PR.
  • I have added documentation to complex functions and functions that can be used by other modules.
  • I have added reasonable tests or consciously decided to not add tests.

Signed-off-by: Arnau Mora <[email protected]>
Signed-off-by: Arnau Mora <[email protected]>
@ArnyminerZ ArnyminerZ linked an issue Jul 16, 2025 that may be closed by this pull request
@ArnyminerZ ArnyminerZ self-assigned this Jul 16, 2025
@ArnyminerZ ArnyminerZ added the refactoring Quality improvement of existing functions label Jul 16, 2025
@ArnyminerZ ArnyminerZ requested a review from Copilot July 16, 2025 06:50
Copilot

This comment was marked as outdated.

ArnyminerZ and others added 6 commits July 16, 2025 08:54
Signed-off-by: Arnau Mora <[email protected]>
Signed-off-by: Arnau Mora <[email protected]>
# Conflicts:
#	app/src/androidTest/java/at/bitfire/icsdroid/model/ValidationUseCaseTest.kt
#	app/src/main/java/at/bitfire/icsdroid/model/ValidationUseCase.kt
Signed-off-by: Arnau Mora <[email protected]>
@ArnyminerZ ArnyminerZ marked this pull request as ready for review August 6, 2025 08:27
@ArnyminerZ ArnyminerZ requested review from Copilot and sunkup August 6, 2025 08:27
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates the HTTP networking implementation from OkHttp to Ktor with OkHttp as the underlying engine. This migration maintains the same underlying networking behavior while adopting Ktor's more modern Kotlin-first API.

  • Replaces direct OkHttp client usage with Ktor HttpClient while keeping OkHttp as the engine
  • Migrates test infrastructure from MockWebServer to Ktor's MockEngine with a custom wrapper
  • Updates dependency injection to provide HttpClient through Hilt

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
gradle/libs.versions.toml Adds Ktor dependencies for core, mock, and OkHttp engine
app/build.gradle.kts Replaces OkHttp dependencies with Ktor equivalents
app/src/main/java/at/bitfire/icsdroid/HttpClient.kt Refactors singleton HttpClient to use Ktor with OkHttp engine and adds Hilt module
app/src/main/java/at/bitfire/icsdroid/CalendarFetcher.kt Updates HTTP calls to use Ktor API instead of OkHttp
app/src/main/java/at/bitfire/icsdroid/model/ValidationUseCase.kt Adds HttpClient dependency injection
app/src/main/java/at/bitfire/icsdroid/ProcessEventsTask.kt Updates to use injected HttpClient
app/src/androidTest/java/at/bitfire/icsdroid/MockEngineWrapper.kt New wrapper for Ktor MockEngine to simplify test setup
app/src/androidTest/java/at/bitfire/icsdroid/model/ValidationUseCaseTest.kt Migrates from MockWebServer to MockEngineWrapper
app/src/androidTest/java/at/bitfire/icsdroid/CalendarFetcherTest.kt Updates test infrastructure to use Ktor MockEngine
Comments suppressed due to low confidence (3)

gradle/libs.versions.toml:29

  • Ktor version 3.2.1 does not exist. The latest stable version of Ktor is 2.3.x series. Please use a valid Ktor version like "2.3.12" or check the official Ktor releases.
ktor = "3.2.1"

app/src/main/java/at/bitfire/icsdroid/HttpClient.kt:28

  • [nitpick] The alias 'AppHttpClient' is confusing since it's aliasing the same class being defined. Consider using a more descriptive name or removing the alias if not needed.
import at.bitfire.icsdroid.HttpClient as AppHttpClient

app/src/androidTest/java/at/bitfire/icsdroid/MockEngineWrapper.kt:28

  • [nitpick] The fallback response uses HttpStatusCode.NotImplemented which may not clearly indicate the actual issue (empty queue). Consider using a more descriptive status code or error message for debugging test failures.
            respond("No more responses", HttpStatusCode.NotImplemented)

Signed-off-by: Arnau Mora <[email protected]>
Copy link
Member

@sunkup sunkup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! A few minor style comments. Feel free to ask or discard if you don't agree.

@ArnyminerZ ArnyminerZ requested a review from sunkup August 11, 2025 17:55
Copy link
Member

@sunkup sunkup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK 👍

@sunkup sunkup merged commit 11ad0d0 into dev Aug 12, 2025
7 checks passed
@sunkup sunkup deleted the 616-replace-okhttp-with-ktor-okhttp-engine branch August 12, 2025 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Quality improvement of existing functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace okhttp with ktor (okhttp engine)
2 participants