Skip to content

Commit 141b41a

Browse files
committed
#1625 fix some bugs with http request action
1 parent 19e1b0c commit 141b41a

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,15 @@
7777
<application
7878
android:name="io.github.sds100.keymapper.KeyMapperApp"
7979
android:allowBackup="true"
80+
android:directBootAware="true"
8081
android:icon="@mipmap/ic_launcher"
8182
android:label="@string/app_name"
82-
android:directBootAware="true"
8383
android:roundIcon="@mipmap/ic_launcher_round"
8484
android:supportsRtl="true"
8585
android:theme="@style/AppTheme.NoActionBar"
86+
android:usesCleartextTraffic="true"
8687
tools:ignore="GoogleAppIndexingWarning">
88+
<!-- Allow clear text traffic due to the HTTP Request Action. -->
8789

8890
<activity
8991
android:name=".MainActivity"

app/src/main/java/io/github/sds100/keymapper/actions/ActionData.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,5 +839,10 @@ sealed class ActionData : Comparable<ActionData> {
839839
val authorizationHeader: String,
840840
) : ActionData() {
841841
override val id: ActionId = ActionId.HTTP_REQUEST
842+
843+
override fun toString(): String {
844+
// Do not leak sensitive request info to logs.
845+
return "HttpRequest(description=$description)"
846+
}
842847
}
843848
}

app/src/main/java/io/github/sds100/keymapper/actions/HttpRequestBottomSheet.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ fun HttpRequestBottomSheet(delegate: CreateActionDelegate) {
7373
delegate.httpRequestBottomSheetState =
7474
delegate.httpRequestBottomSheetState?.copy(body = it)
7575
},
76+
onAuthorizationChanged = {
77+
delegate.httpRequestBottomSheetState =
78+
delegate.httpRequestBottomSheetState?.copy(authorizationHeader = it)
79+
},
7680
onDoneClick = {
7781
val result = delegate.httpRequestBottomSheetState ?: return@HttpRequestBottomSheet
7882
delegate.httpRequestBottomSheetState = null
@@ -92,6 +96,7 @@ private fun HttpRequestBottomSheet(
9296
onDescriptionChanged: (String) -> Unit = {},
9397
onUrlChanged: (String) -> Unit = {},
9498
onBodyChanged: (String) -> Unit = {},
99+
onAuthorizationChanged: (String) -> Unit = {},
95100
onDoneClick: () -> Unit = {},
96101
) {
97102
val scrollState = rememberScrollState()
@@ -221,11 +226,16 @@ private fun HttpRequestBottomSheet(
221226
value = state.authorizationHeader,
222227
label = { Text(stringResource(R.string.action_http_request_authorization_label)) },
223228
onValueChange = {
224-
onBodyChanged(it)
229+
onAuthorizationChanged(it)
225230
},
226231
supportingText = {
227232
Text(stringResource(R.string.action_http_request_authorization_supporting_text))
228233
},
234+
keyboardOptions = KeyboardOptions(
235+
capitalization = KeyboardCapitalization.None,
236+
autoCorrectEnabled = false,
237+
keyboardType = KeyboardType.Text,
238+
),
229239
)
230240

231241
Spacer(modifier = Modifier.height(16.dp))

app/src/main/java/io/github/sds100/keymapper/system/network/AndroidNetworkAdapter.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,23 @@ class AndroidNetworkAdapter(
152152
}
153153

154154
val request = requestBody
155-
.url("https://posttestserver.dev/p/kmr33yjcz5h38hkq/post")
155+
.url(url)
156156
.headers(headers.build())
157157
.build()
158158

159159
withContext(Dispatchers.IO) { httpClient.newCall(request).execute() }
160160
.use { response ->
161-
Timber.e(response.toString())
161+
// Keep this in. It is useful for debugging.
162+
Timber.d(response.toString())
163+
162164
if (!response.isSuccessful) {
163165
return Error.UnknownIOError
164166
}
165167

166168
return Success(Unit)
167169
}
168170
} catch (e: IOException) {
171+
Timber.e(e)
169172
return Error.UnknownIOError
170173
}
171174
}

0 commit comments

Comments
 (0)