Hello,
I am using STTP 3.8.15 with ZIO backend, Java 17 ZULU.
So, given this code
override def uploadFile(
connection: Connection,
path: String,
file: File,
overwrite: Boolean
): IO[BusinessError, Unit] =
sendRequest(s"File upload to $path", AcceptedContent.any)( // custom function
basicDBRequest
.post(uri"https://something/put")
.auth.bearer(connection.token.value)
.multipartBody(
multipart("path", path),
multipart("overwrite", overwrite),
multipartFile("contents", file)
),
noOpCallHandler[String, String]
).mapErrorCause(fromError)
.ignore
The server returns 400 with Content-Length header must be provided. This is required to avoid uploading partial data.
.
Using requestbin, I see that indeed there is no content-length
header sent:
transfer-encoding: chunked
accept: */*
accept-encoding: gzip, deflate
content-type: multipart/form-data; boundary=8f9cab0d-2f53-4d2b-b8b1-1414d7b7dbb2
I’ve tried to set one, but frankly, however I try to calculate and set it, I always get another error: Too many bytes in request body. Expected: 37131145, got: 37131695
- Shouldn’t the content-length header be sent automatically in this case? The length of the body is known as it’s an existing file.
- If not, how can I have calculate the body of such multipart request or ask STTP to define Content-Length?
I noticed, that with Java 11, the content-length
header is sent instead of Transfer-Encoding: chunked
. Am I able to configure STTP (and underlaying classes) to use content-length
header?
Thank you!
BTW the Slf4jLoggingBackend
does not log POST
requests, I see only GET ones. I have configured it this way for my tests
HttpClientZioBackend.layer().map(env =>
ZEnvironment(Slf4jLoggingBackend(
delegate = env.get[SttpClient],
beforeCurlInsteadOfShow = true,
logRequestBody = false,
logRequestHeaders = true,
logResponseBody = false,
logResponseHeaders = true,
beforeRequestSendLogLevel = LogLevel.Warn,
responseLogLevel = _ => LogLevel.Warn,
responseExceptionLogLevel = LogLevel.Warn
))
)