{"id":16894144,"url":"https://github.com/limuyang2/okcronet","last_synced_at":"2025-04-07T15:08:05.326Z","repository":{"id":229952877,"uuid":"778077984","full_name":"limuyang2/okcronet","owner":"limuyang2","description":"🚀 A network request library similar to OKHTTP, implemented using Cronet(Http3/QUIC)","archived":false,"fork":false,"pushed_at":"2025-03-14T08:25:04.000Z","size":302,"stargazers_count":87,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T12:09:37.403Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/limuyang2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-27T03:05:57.000Z","updated_at":"2025-03-28T12:51:17.000Z","dependencies_parsed_at":"2025-01-21T10:26:53.074Z","dependency_job_id":"7edfcd08-7e41-4523-bb57-d7bb9ec633ef","html_url":"https://github.com/limuyang2/okcronet","commit_stats":null,"previous_names":["limuyang2/okcronet"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limuyang2%2Fokcronet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limuyang2%2Fokcronet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limuyang2%2Fokcronet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/limuyang2%2Fokcronet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/limuyang2","download_url":"https://codeload.github.com/limuyang2/okcronet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247675597,"owners_count":20977376,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T17:17:46.594Z","updated_at":"2025-04-07T15:08:05.297Z","avatar_url":"https://github.com/limuyang2.png","language":"Kotlin","funding_links":[],"categories":["Kotlin","网络编程"],"sub_categories":["Spring Cloud框架"],"readme":"# okcronet\nA network request library similar to OKHTTP, implemented using Cronet\n\n[中文](https://github.com/limuyang2/okcronet/blob/main/README_CN.md)\n\n# Why\nGoogle provides a bridge implementation from `okhttp` to `Cronet` [cronet-transport-for-okhttp](https://github.com/google/cronet-transport-for-okhttp/), but as in `README` As described in the `Incompatibilities` content, you cannot use the source code to improve its functionality.\n\nTherefore, the goal of the okcronet project is to solve the problems of HTTP3/QUIC support provided by interceptors implemented by `Cronet`.\n\nFor answers about `okhttp`'s support for HTTP3/QUIC, you can view this [issues](https://github.com/square/okhttp/issues/907).\n\n# Advantages of okcronet\n* Easy to use, consistent with OkHttp usage\n* Supports HTTP3/QUIC, which can provide better network performance\n* Supports all features of Cronet, such as caching, thread pools, proxies, etc.\n\n# Import\nYou need to reference both the OkCronet library and the Cronet library.\n## okcronet Library:\n```\nimplementation(\"io.github.limuyang2:okcronet:1.0.5\")\n```\n\n## Cronet Library:\n### Google Official Cronet:\n#### Way 1\n[Google Latest Version](https://maven.google.com/web/index.html?#org.chromium.net)\n```\nimplementation(\"org.chromium.net:cronet-api:119.6045.31\")\nimplementation(\"org.chromium.net:cronet-common:119.6045.31\")\nimplementation(\"org.chromium.net:cronet-embedded:119.6045.31\")\n```\n#### Way 2\nThe packages officially provided by Google are not the latest. If you want to use the latest version synchronized with `chromium`, you can visit the official storage bucket to obtain it.[google cloud](https://console.cloud.google.com/storage/browser/chromium-cronet/android;tab=objects?inv=1\u0026invt=Abmz0w\u0026prefix=\u0026forceOnObjectsSortingFiltering=true)\n\n\n### Google Play Cronet:\nReference link - [android develop](https://developer.android.com/develop/connectivity/cronet/start#kts)\n```\nimplementation(\"com.google.android.gms:play-services-cronet:18.1.0\")\n```\n\n# Using\nThe usage is consistent with the usage of okhttp. There is just one more `CronetEngine` creation work.\n## Build a globally unique CronetEngine\n```kotlin\n    // cronetEngine needs to maintain global uniqueness and cannot be created repeatedly\n    private val cronetEngine: CronetEngine by lazy(LazyThreadSafetyMode.NONE) {\n        val httpCacheDir =\n            File(\n                this.applicationContext.externalCacheDir ?: this.applicationContext.cacheDir,\n                \"http\"\n            )\n\n        if (!httpCacheDir.exists()) {\n            httpCacheDir.mkdir()\n        }\n\n        CronetEngine.Builder(\n            NativeCronetEngineBuilderImpl(this.applicationContext)\n        )\n            .setStoragePath(httpCacheDir.absolutePath)\n            .enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 1048576)\n            .enableHttp2(true)\n            .enableQuic(true)\n            .setThreadPriority(-1)\n            .enableBrotli(true)\n            .build()\n    }\n```\n\n## GET\n```kotlin\n    // Create CronetClient\n    val cronetClient = CronetClient.Builder(cronetEngine).build()\n\n    // Build Request\n    val request = Request.Builder()\n        .url(\"https://www.fastly.com/quic-http-3\")\n        .get()\n        .build()\n\n    // Initiate network requests synchronously\n    cronetClient.newCall(request).execute()\n\n```\n\n## POST\n```kotlin\n    // Create CronetClient\n    val cronetClient = CronetClient.Builder(cronetEngine).build()\n\n    // Build RequestBody\n    val body: RequestBody = \"jsonString\".toRequestBody()\n\n    // Build Request\n    val request = Request.Builder()\n        .url(\"https://www.fastly.com/quic-http-3\")\n        .post(body)\n        .build()\n\n    // Initiate network requests synchronously\n    cronetClient.newCall(request).execute()\n```\n\n# Proguard\nYou need to add obfuscation rules for `cronet`. If you are using the version officially provided by Google, it will be included automatically.\n\n\n# Thanks\n[okhttp](https://github.com/square/okhttp)\n\n[cronet-transport-for-okhttp](https://github.com/google/cronet-transport-for-okhttp)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flimuyang2%2Fokcronet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flimuyang2%2Fokcronet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flimuyang2%2Fokcronet/lists"}