| 281 | } |
| 282 | |
| 283 | static int |
| 284 | ts_lua_transform_handler(TSCont contp, ts_lua_http_transform_ctx *transform_ctx, TSEvent event, int n) |
| 285 | { |
| 286 | TSVConn output_conn; |
| 287 | TSVIO input_vio; |
| 288 | TSIOBufferReader input_reader = nullptr; |
| 289 | TSIOBufferBlock blk; |
| 290 | int64_t toread, towrite, blk_len, upstream_done, input_avail, input_wm_bytes, l; |
| 291 | const char *start; |
| 292 | const char *res; |
| 293 | size_t res_len; |
| 294 | int ret, eos, write_down, rc, top, empty_input; |
| 295 | ts_lua_coroutine *crt; |
| 296 | ts_lua_cont_info *ci; |
| 297 | |
| 298 | lua_State *L; |
| 299 | TSMutex mtxp; |
| 300 | |
| 301 | ci = &transform_ctx->cinfo; |
| 302 | crt = &ci->routine; |
| 303 | |
| 304 | mtxp = crt->mctx->mutexp; |
| 305 | L = crt->lua; |
| 306 | |
| 307 | output_conn = TSTransformOutputVConnGet(contp); |
| 308 | input_vio = TSVConnWriteVIOGet(contp); |
| 309 | |
| 310 | empty_input = 0; |
| 311 | if (!TSVIOBufferGet(input_vio)) { |
| 312 | if (transform_ctx->output.vio) { |
| 313 | Dbg(dbg_ctl, "[%s] reenabling output VIO after input VIO does not exist", __FUNCTION__); |
| 314 | TSVIONBytesSet(transform_ctx->output.vio, transform_ctx->total); |
| 315 | TSVIOReenable(transform_ctx->output.vio); |
| 316 | return 0; |
| 317 | } else { |
| 318 | Dbg(dbg_ctl, "[%s] no input VIO and output VIO", __FUNCTION__); |
| 319 | empty_input = 1; |
| 320 | } |
| 321 | } else { // input VIO exists |
| 322 | input_wm_bytes = TSIOBufferWaterMarkGet(TSVIOBufferGet(input_vio)); |
| 323 | if (transform_ctx->upstream_watermark_bytes >= 0 && transform_ctx->upstream_watermark_bytes != input_wm_bytes) { |
| 324 | Dbg(dbg_ctl, "[%s] Setting input_vio watermark to %" PRId64 " bytes", __FUNCTION__, transform_ctx->upstream_watermark_bytes); |
| 325 | TSIOBufferWaterMarkSet(TSVIOBufferGet(input_vio), transform_ctx->upstream_watermark_bytes); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | if (empty_input == 0) { |
| 330 | input_reader = TSVIOReaderGet(input_vio); |
| 331 | } |
| 332 | |
| 333 | if (!transform_ctx->output.buffer) { |
| 334 | transform_ctx->output.buffer = TSIOBufferCreate(); |
| 335 | transform_ctx->output.reader = TSIOBufferReaderAlloc(transform_ctx->output.buffer); |
| 336 | |
| 337 | transform_ctx->reserved.buffer = TSIOBufferCreate(); |
| 338 | transform_ctx->reserved.reader = TSIOBufferReaderAlloc(transform_ctx->reserved.buffer); |
| 339 | |
| 340 | if (empty_input == 0) { |
no test coverage detected