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

Maybe fix curlString #664

Merged
merged 3 commits into from
Aug 3, 2019
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
7 changes: 7 additions & 0 deletions fuel/src/main/kotlin/com/github/kittinunf/fuel/core/Body.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.kittinunf.fuel.core

import com.github.kittinunf.fuel.core.requests.RepeatableBody
import java.io.InputStream
import java.io.OutputStream

Expand Down Expand Up @@ -58,6 +59,12 @@ interface Body {
*/
val length: Long?

/**
* Makes the body repeatable by e.g. loading its contents into memory
* @return [RepeatableBody] the body to be repeated
*/
fun asRepeatable(): RepeatableBody = RepeatableBody(this)

/**
* Represents this body as a string
* @param contentType [String] the type of the content in the body, or null if a guess is necessary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fun Request.httpString(): String = buildString {
headers.transformIterate(appendHeaderWithValue)

// body
body(body.asRepeatable())
appendln()
appendln(String(body.toByteArray()))
}
Expand All @@ -43,6 +44,7 @@ fun Request.cUrlString(): String = buildString {
}

// body
body(body.asRepeatable())
val escapedBody = String(body.toByteArray()).replace("\"", "\\\"")
if (escapedBody.isNotEmpty()) {
append(" -d \"$escapedBody\"")
Expand All @@ -54,4 +56,4 @@ fun Request.cUrlString(): String = buildString {

// url
append(" $url")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,6 @@ data class DefaultBody(
}
}

/**
* Makes the body repeatable by e.g. loading its contents into memory
* @return [RepeatableBody] the body to be repeated
*/
fun asRepeatable(): RepeatableBody = RepeatableBody(this)

companion object {
private val EMPTY_STREAM = {
ByteArrayInputStream(ByteArray(0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,10 @@ data class RepeatableBody(
* @return [Long?] the length in bytes, null if it is unknown
*/
override val length = body.length

/**
* Makes the body repeatable by e.g. loading its contents into memory
* @return [RepeatableBody] the body to be repeated
*/
override fun asRepeatable(): RepeatableBody = this
}