{"id":14989944,"url":"https://github.com/mrmike/ok2curl","last_synced_at":"2025-04-04T14:07:52.846Z","repository":{"id":1775947,"uuid":"43089983","full_name":"mrmike/Ok2Curl","owner":"mrmike","description":"Convert OkHttp requests into curl logs.","archived":false,"fork":false,"pushed_at":"2023-06-06T00:16:07.000Z","size":473,"stargazers_count":444,"open_issues_count":4,"forks_count":31,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-04T14:07:48.444Z","etag":null,"topics":["android","android-library","curl","curl-logs","interceptor","java","network-interceptors","okhttp"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrmike.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}},"created_at":"2015-09-24T19:59:28.000Z","updated_at":"2025-03-27T02:53:04.000Z","dependencies_parsed_at":"2022-08-08T13:00:16.047Z","dependency_job_id":"f7e3e8dd-1635-4c5c-aa10-053af75c58e5","html_url":"https://github.com/mrmike/Ok2Curl","commit_stats":{"total_commits":156,"total_committers":7,"mean_commits":"22.285714285714285","dds":"0.13461538461538458","last_synced_commit":"26e2718b899322b5f75fce7f4166c4913b4eedc8"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrmike%2FOk2Curl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrmike%2FOk2Curl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrmike%2FOk2Curl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrmike%2FOk2Curl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrmike","download_url":"https://codeload.github.com/mrmike/Ok2Curl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190250,"owners_count":20898702,"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":["android","android-library","curl","curl-logs","interceptor","java","network-interceptors","okhttp"],"created_at":"2024-09-24T14:19:12.348Z","updated_at":"2025-04-04T14:07:52.828Z","avatar_url":"https://github.com/mrmike.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ok2Curl [![Commit check](https://github.com/mrmike/Ok2Curl/actions/workflows/push.yml/badge.svg)](https://github.com/mrmike/Ok2Curl/actions/workflows/push.yml) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Ok2Curl-green.svg?style=flat)](https://android-arsenal.com/details/1/2653) [![Release](https://jitpack.io/v/mrmike/Ok2Curl.svg)](https://jitpack.io/#mrmike/Ok2Curl)\n\nSimply way to transform OkHttp requests into curl logs.\n\n## Supported OkHttp versions\nCurrently Ok2Curl requires OkHttp in version 4.x.\n\n## Usage\nAdd library to project dependencies. Library is hosted on Maven Central.\n```groovy\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    implementation 'com.github.mrmike:ok2curl:0.8.0'\n}\n```\n\nTo start logging requests with Ok2Curl add interceptor to OkHttp client.\n```kotlin\nval client = OkHttpClient.Builder()\n    .addInterceptor(CurlInterceptor(object : Logger {\n        override fun log(message: String) {\n            Log.v(\"Ok2Curl\", message)\n        }\n    }))\n    .build()\n```\n\n## Result\nWith Ok2Curl set up correctly every executed request will be transformed into curl log e.g.\n```shell\nadb logcat -s \"Ok2Curl\"\ncurl -X GET -H \"Cache-Control:max-stale=2147483647, only-if-cached\" https://api.github.com/repos/vmg/redcarpet/issues?state=closed\n```\n\n## Network interceptors\nBy default Ok2Curl uses application interceptors from OkHttp which is adequate for most cases. But sometimes you may want to use network interceptor e.g. to log Cookies set via [CookieHandler](http://docs.oracle.com/javase/6/docs/api/java/net/CookieHandler.html). In such a case add interceptor the same way as below:  \n\n```kotlin\nval client = OkHttpClient.Builder()\n    .addNetworkInterceptor(CurlInterceptor(logger))\n    .build()\n```\n\nTo get know more about Interceptor in OkHttp take a look here: https://github.com/square/okhttp/wiki/Interceptors\n\n## Configuration\n\n`CurlInterceptor` accepts an optional configuration object. With `Configuration` you can specify various options like:\n* header modifiers - custom logic for modifying header values\n* components - list of required command components\n* flags - optional curl flags\n* limit - bytes limit for body\n* delimiter for command components\n\n```kotlin\nclass Configuration(\n    val headerModifiers: List\u003cHeaderModifier\u003e = emptyList(),\n    val components: List\u003cCommandComponent\u003e = CommandComponent.DEFAULT,\n    val flags: Flags = Flags.EMPTY,\n    val limit: Long = 1024L * 1024L,\n    val delimiter: String = \" \"\n)\n```\n\n## Header modifiers\nOk2Curl allows you to modify any header before creating curl command. All you have to do is create your own modifier that implements [HeaderModifier](https://github.com/mrmike/Ok2Curl/blob/master/ok2curl/src/main/java/com/moczul/ok2curl/modifier/HeaderModifier.kt)\nand add this modifier to CurlInterceptor. See [sample](https://github.com/mrmike/Ok2Curl/blob/master/sample/src/main/java/com/moczul/sample/RequestService.kt) for reference.\n```\nval modifier = BasicAuthorizationHeaderModifier(Base64Decoder())\nval configuration = Configuration(headerModifiers = listOf(modifier))\nval curlInterceptor = CurlInterceptor(AndroidLogger(), configuration)\n```\n\n## Command Components\nWith Ok2Curl configuration you can specify a list of components for curl command. For instance,\nyou can skip header, body, and flag components.\n```kotlin\nval components = listOf(Curl, Method, Url)\nval configuration = Configuration(components = components)\nval curlInterceptor = CurlInterceptor(AndroidLogger(), configuration)\n```\n\nAs a result, CurlInterceptor will receive given simplified command\n```shell\n// Headers, body and flags are skipped\ncurl -X GET https://api.github.com/repos/vmg/redcarpet/issues?state=closed\n```\n\n## Flags\nOk2Curl supports basic Curl options. To use options use the following code:\n```kotlin\nval flags = Flags.builder()\n            .insecure()\n            .connectTimeout(seconds = 120)\n            .retry(5)\n            .build()\nval configuration = Configuration(flags = flags)\nval curlInterceptor = CurlInterceptor(AndroidLogger(), configuration)\n```\nSince now every Curl command will start with `curl --insecure --connect-timeout 120 --retry 5...`\n\n### Supported options\n* --insecure\n* --max-time seconds\n* --connect-timeout seconds\n* --retry num\n* --compressed\n* --location\n\nIf would like to support any new options please feel free to open PR. A full list of curl options is\navailable [here](https://curl.haxx.se/docs/manpage.html).\n\n\n## License\n\n    Copyright 2018 Michał Moczulski\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrmike%2Fok2curl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrmike%2Fok2curl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrmike%2Fok2curl/lists"}