diff --git a/Sources/CrestLib/Operation.swift b/Sources/CrestLib/Operation.swift index 862db74..59ef30d 100644 --- a/Sources/CrestLib/Operation.swift +++ b/Sources/CrestLib/Operation.swift @@ -127,6 +127,7 @@ final class ResponseDelegate: HTTPClientResponseDelegate { var needNewline = false func didReceiveHead(task: HTTPClient.Task, _ head: HTTPResponseHead) -> EventLoopFuture { + outputResponseHeaders(head) if head.status != .ok { error = OperationError.httpError(head.status) } else { @@ -136,28 +137,6 @@ final class ResponseDelegate: HTTPClientResponseDelegate { prettyPrintIsPossible = true } } - if Configuration.shared.showResponseHeaders { - print("Headers:") - print(" \(head.version) \(head.status.code) \(head.status)".uppercased()) - var maxLen = 0 - for header in head.headers { - let len = header.name.count - if len > maxLen && len <= 25 { - maxLen = len - } - } - if maxLen > 25 { - maxLen = 25 - } - for header in head.headers { - var name = header.name + ":" - if name.count < maxLen+1 { - name = name.padding(toLength: maxLen+1, withPad: " ", startingAt: 0) - } - print(" \(name) \(header.value)") - } - print("Content:") - } } return task.eventLoop.makeSucceededVoidFuture() } @@ -196,6 +175,31 @@ final class ResponseDelegate: HTTPClientResponseDelegate { || contentType.starts(with: "text/xml") || contentType.starts(with: "application/json") } + + func outputResponseHeaders(_ head: HTTPResponseHead) { + if Configuration.shared.showResponseHeaders { + print("Headers:") + print(" \(head.version) \(head.status.code) \(head.status)".uppercased()) + var maxLen = 0 + for header in head.headers { + let len = header.name.count + if len > maxLen && len <= 25 { + maxLen = len + } + } + if maxLen > 25 { + maxLen = 25 + } + for header in head.headers { + var name = header.name + ":" + if name.count < maxLen+1 { + name = name.padding(toLength: maxLen+1, withPad: " ", startingAt: 0) + } + print(" \(name) \(header.value)") + } + print("Content:") + } + } }