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

Feature/http timeout #152

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,18 @@ fun ParameterHolder.httpLoggingLevel() = option(

fun ParameterHolder.httpRequestTimeout() = option(
"--http-request-timeout",
help = "Http request timeout in milliseconds. Default "
).long()
help = "Http request timeout in milliseconds. Default 30 000 "
).long().default(30000)

fun ParameterHolder.httpSocketTimeout() = option(
"--http-socket-timeout",
help = "Http socket timeout in milliseconds. Default 30 000 "
).long().default(30000)

fun ParameterHolder.httpConnectTimeout() = option(
"--http-connect-timeout",
help = "Http connect timeout in milliseconds. Default 30 000 "
).long().default(30000)

internal interface WithConfluenceServerOptions {
val confluenceUrl: Url?
Expand All @@ -69,6 +79,8 @@ internal interface WithConfluenceServerOptions {
val skipSsl: Boolean?
val httpLogLevel: LogLevel
val httpRequestTimeout: Long?
val httpConnectTimeout: Long?
val httpSocketTimeout: Long?

val confluenceAuth: ConfluenceAuth
get() = when {
Expand All @@ -93,7 +105,9 @@ internal interface WithConfluenceServerOptions {
skipSsl = skipSsl ?: defaultSslSkip,
auth = confluenceAuth,
httpLogLevel = httpLogLevel,
requestTimeout = httpRequestTimeout
requestTimeout = httpRequestTimeout,
connectTimeout = httpConnectTimeout,
socketTimeout = httpSocketTimeout
)
fun askForSecret(prompt: String, requireConfirmation: Boolean = true): String?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class DumpToMarkdown : CliktCommand(name = "export-to-md", help = "Exports confl
override val skipSsl: Boolean? by skipSsl()
override val httpLogLevel: LogLevel by httpLoggingLevel()
override val httpRequestTimeout: Long? by httpRequestTimeout()
override val httpSocketTimeout: Long? by httpSocketTimeout()
override val httpConnectTimeout: Long? by httpConnectTimeout()

val space: String? by confluenceSpace()
private val pageId: String? by option("--page-id", help = "Id of page that you want to dump")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class Upload : CliktCommand(name = "upload", help = "Converts source files and u
override val skipSsl: Boolean? by skipSsl()
override val httpLogLevel: LogLevel by httpLoggingLevel()
override val httpRequestTimeout: Long? by httpRequestTimeout()
override val httpSocketTimeout: Long? by httpSocketTimeout()
override val httpConnectTimeout: Long? by httpConnectTimeout()

override val spaceKey: String? by confluenceSpace()
private val parentId: String? by option("--parent-id", help = "Id of parent page where root pages should be added")
Expand Down Expand Up @@ -87,6 +89,7 @@ class Upload : CliktCommand(name = "upload", help = "Converts source files and u
} else {
converter.convertDir(docs.toPath())
}

serviceProvider.createContentValidator().validate(result)
val confluenceClient = serviceProvider.createConfluenceClient(clientConfig, dryRun)
val publishUnder = resolveParent(confluenceClient, uploadConfig, directoryStoredParams)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ data class ConfluenceClientConfig(
val skipSsl: Boolean,
val auth: ConfluenceAuth,
val httpLogLevel: LogLevel = LogLevel.NONE,
val requestTimeout: Long? = null,
val requestTimeout: Long? = 30000,
val connectTimeout: Long? = 30000,
val socketTimeout: Long? = 30000
)
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ private suspend inline fun <reified T> HttpResponse.readApiResponse(expectSucces
parseAndThrowConfluencError()
}
val contentType = contentType()
if (contentType != null && ContentType.Application.Json.match(contentType)){
if (contentType != null && ContentType.Application.Json.match(contentType)) {
try {
return body<T>()
} catch (e: JsonConvertException) {
Expand All @@ -357,7 +357,7 @@ private suspend fun HttpResponse.parseAndThrowConfluencError(): Nothing {
}

private data class PageSearchResult(
val results: List<ConfluencePage>,
val results: List<ConfluencePage> = emptyList(),
val start: Int,
val limit: Int,
val size: Int
Expand All @@ -367,10 +367,12 @@ fun confluenceClient(
config: ConfluenceClientConfig
): ConfluenceClient {
val client = HttpClient(CIO) {
install(HttpTimeout) {
requestTimeoutMillis = config.requestTimeout
connectTimeoutMillis = config.connectTimeout
socketTimeoutMillis = config.socketTimeout
}
engine {
if (config.requestTimeout != null) {
requestTimeout = config.requestTimeout
}
if (config.skipSsl) {
https {
trustManager = object : X509TrustManager {
Expand Down