| 333 | } |
| 334 | |
| 335 | Result HttpAsyncFileServer::putFile(HttpAsyncFileServer::Stream& stream, HttpConnection& connection, |
| 336 | StringSpan filePath) |
| 337 | { |
| 338 | StringPath path; |
| 339 | SC_TRY(path.assign(directory.view())); |
| 340 | SC_TRY(path.append("/")); |
| 341 | SC_TRY(path.append(filePath)); |
| 342 | const size_t totalFileUploadBytes = static_cast<size_t>(connection.request.getBodyBytesRemaining()); |
| 343 | FileDescriptor fd; |
| 344 | SC_TRY(fd.open(path.view(), FileOpen::Write)); |
| 345 | if (totalFileUploadBytes == 0) |
| 346 | { |
| 347 | SC_TRY(fd.close()); |
| 348 | return connection.response.sendEmpty(201); |
| 349 | } |
| 350 | |
| 351 | SC_TRY(stream.writableFileStream.init(connection.buffersPool, *eventLoop, fd)); |
| 352 | SC_TRY(stream.writableFileStream.request.executeOn(stream.writableFileStreamTask, *threadPool)); |
| 353 | fd.detach(); |
| 354 | stream.writableFileStream.setAutoCloseDescriptor(true); |
| 355 | |
| 356 | HttpConnection& asyncConnection = static_cast<HttpConnection&>(connection); |
| 357 | |
| 358 | stream.putFileListener.connection = &asyncConnection; |
| 359 | const bool addedFinishListener = |
| 360 | stream.writableFileStream.eventFinish.addListener<HttpAsyncFileServer::Stream::PutFileListener, |
| 361 | &HttpAsyncFileServer::Stream::PutFileListener::onFinish>( |
| 362 | stream.putFileListener); |
| 363 | SC_HTTP_ASSERT_RELEASE(addedFinishListener); |
| 364 | |
| 365 | connection.pipeline.source = &connection.request.getReadableStream(); |
| 366 | connection.pipeline.sinks[0] = &stream.writableFileStream; |
| 367 | SC_TRY(connection.pipeline.pipe()); |
| 368 | SC_TRY(connection.pipeline.start()); |
| 369 | return Result(true); |
| 370 | } |
| 371 | |
| 372 | void HttpAsyncFileServer::Stream::PutFileListener::onFinish() |
| 373 | { |
nothing calls this directly
no test coverage detected