forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlua_filter.cc
More file actions
659 lines (570 loc) · 23 KB
/
lua_filter.cc
File metadata and controls
659 lines (570 loc) · 23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
#include "extensions/filters/http/lua/lua_filter.h"
#include <memory>
#include "envoy/http/codes.h"
#include "common/buffer/buffer_impl.h"
#include "common/common/assert.h"
#include "common/common/enum_to_int.h"
#include "common/crypto/utility.h"
#include "common/http/message_impl.h"
namespace Envoy {
namespace Extensions {
namespace HttpFilters {
namespace Lua {
namespace {
// Okay to return non-const reference because this doesn't ever get changed.
NoopCallbacks& noopCallbacks() {
static NoopCallbacks* callbacks = new NoopCallbacks();
return *callbacks;
}
void buildHeadersFromTable(Http::HeaderMap& headers, lua_State* state, int table_index) {
// Build a header map to make the request. We iterate through the provided table to do this and
// check that we are getting strings.
lua_pushnil(state);
while (lua_next(state, table_index) != 0) {
// Uses 'key' (at index -2) and 'value' (at index -1).
const char* key = luaL_checkstring(state, -2);
// Check if the current value is a table, we iterate through the table and add each element of
// it as a header entry value for the current key.
if (lua_istable(state, -1)) {
lua_pushnil(state);
while (lua_next(state, -2) != 0) {
const char* value = luaL_checkstring(state, -1);
headers.addCopy(Http::LowerCaseString(key), value);
lua_pop(state, 1);
}
} else {
const char* value = luaL_checkstring(state, -1);
headers.addCopy(Http::LowerCaseString(key), value);
}
// Removes 'value'; keeps 'key' for next iteration. This is the input for lua_next() so that
// it can push the next key/value pair onto the stack.
lua_pop(state, 1);
}
}
Http::AsyncClient::Request* makeHttpCall(lua_State* state, Filter& filter,
Http::AsyncClient::Callbacks& callbacks) {
const std::string cluster = luaL_checkstring(state, 2);
luaL_checktype(state, 3, LUA_TTABLE);
size_t body_size;
const char* body = luaL_optlstring(state, 4, nullptr, &body_size);
int timeout_ms = luaL_checkint(state, 5);
if (timeout_ms < 0) {
luaL_error(state, "http call timeout must be >= 0");
}
if (filter.clusterManager().get(cluster) == nullptr) {
luaL_error(state, "http call cluster invalid. Must be configured");
}
auto headers = std::make_unique<Http::RequestHeaderMapImpl>();
buildHeadersFromTable(*headers, state, 3);
Http::RequestMessagePtr message(new Http::RequestMessageImpl(std::move(headers)));
// Check that we were provided certain headers.
if (message->headers().Path() == nullptr || message->headers().Method() == nullptr ||
message->headers().Host() == nullptr) {
luaL_error(state, "http call headers must include ':path', ':method', and ':authority'");
}
if (body != nullptr) {
message->body() = std::make_unique<Buffer::OwnedImpl>(body, body_size);
message->headers().setContentLength(body_size);
}
absl::optional<std::chrono::milliseconds> timeout;
if (timeout_ms > 0) {
timeout = std::chrono::milliseconds(timeout_ms);
}
return filter.clusterManager().httpAsyncClientForCluster(cluster).send(
std::move(message), callbacks, Http::AsyncClient::RequestOptions().setTimeout(timeout));
}
} // namespace
StreamHandleWrapper::StreamHandleWrapper(Filters::Common::Lua::Coroutine& coroutine,
Http::HeaderMap& headers, bool end_stream, Filter& filter,
FilterCallbacks& callbacks)
: coroutine_(coroutine), headers_(headers), end_stream_(end_stream), filter_(filter),
callbacks_(callbacks), yield_callback_([this]() {
if (state_ == State::Running) {
throw Filters::Common::Lua::LuaException("script performed an unexpected yield");
}
}) {}
Http::FilterHeadersStatus StreamHandleWrapper::start(int function_ref) {
// We are on the top of the stack.
coroutine_.start(function_ref, 1, yield_callback_);
Http::FilterHeadersStatus status =
(state_ == State::WaitForBody || state_ == State::HttpCall || state_ == State::Responded)
? Http::FilterHeadersStatus::StopIteration
: Http::FilterHeadersStatus::Continue;
if (status == Http::FilterHeadersStatus::Continue) {
headers_continued_ = true;
}
return status;
}
Http::FilterDataStatus StreamHandleWrapper::onData(Buffer::Instance& data, bool end_stream) {
ASSERT(!end_stream_);
end_stream_ = end_stream;
saw_body_ = true;
if (state_ == State::WaitForBodyChunk) {
ENVOY_LOG(trace, "resuming for next body chunk");
Filters::Common::Lua::LuaDeathRef<Filters::Common::Lua::BufferWrapper> wrapper(
Filters::Common::Lua::BufferWrapper::create(coroutine_.luaState(), data), true);
state_ = State::Running;
coroutine_.resume(1, yield_callback_);
} else if (state_ == State::WaitForBody && end_stream_) {
ENVOY_LOG(debug, "resuming body due to end stream");
callbacks_.addData(data);
state_ = State::Running;
coroutine_.resume(luaBody(coroutine_.luaState()), yield_callback_);
} else if (state_ == State::WaitForTrailers && end_stream_) {
ENVOY_LOG(debug, "resuming nil trailers due to end stream");
state_ = State::Running;
coroutine_.resume(0, yield_callback_);
}
if (state_ == State::HttpCall || state_ == State::WaitForBody) {
ENVOY_LOG(trace, "buffering body");
return Http::FilterDataStatus::StopIterationAndBuffer;
} else if (state_ == State::Responded) {
return Http::FilterDataStatus::StopIterationNoBuffer;
} else {
headers_continued_ = true;
return Http::FilterDataStatus::Continue;
}
}
Http::FilterTrailersStatus StreamHandleWrapper::onTrailers(Http::HeaderMap& trailers) {
ASSERT(!end_stream_);
end_stream_ = true;
trailers_ = &trailers;
if (state_ == State::WaitForBodyChunk) {
ENVOY_LOG(debug, "resuming nil body chunk due to trailers");
state_ = State::Running;
coroutine_.resume(0, yield_callback_);
} else if (state_ == State::WaitForBody) {
ENVOY_LOG(debug, "resuming body due to trailers");
state_ = State::Running;
coroutine_.resume(luaBody(coroutine_.luaState()), yield_callback_);
}
if (state_ == State::WaitForTrailers) {
// Mimic a call to trailers which will push the trailers onto the stack and then resume.
state_ = State::Running;
coroutine_.resume(luaTrailers(coroutine_.luaState()), yield_callback_);
}
Http::FilterTrailersStatus status = (state_ == State::HttpCall || state_ == State::Responded)
? Http::FilterTrailersStatus::StopIteration
: Http::FilterTrailersStatus::Continue;
if (status == Http::FilterTrailersStatus::Continue) {
headers_continued_ = true;
}
return status;
}
int StreamHandleWrapper::luaRespond(lua_State* state) {
ASSERT(state_ == State::Running);
if (headers_continued_) {
luaL_error(state, "respond() cannot be called if headers have been continued");
}
luaL_checktype(state, 2, LUA_TTABLE);
size_t body_size;
const char* raw_body = luaL_optlstring(state, 3, nullptr, &body_size);
auto headers = std::make_unique<Http::ResponseHeaderMapImpl>();
buildHeadersFromTable(*headers, state, 2);
uint64_t status;
if (headers->Status() == nullptr ||
!absl::SimpleAtoi(headers->Status()->value().getStringView(), &status) || status < 200 ||
status >= 600) {
luaL_error(state, ":status must be between 200-599");
}
Buffer::InstancePtr body;
if (raw_body != nullptr) {
body = std::make_unique<Buffer::OwnedImpl>(raw_body, body_size);
headers->setContentLength(body_size);
}
// Once we respond we treat that as the end of the script even if there is more code. Thus we
// yield.
callbacks_.respond(std::move(headers), body.get(), state);
state_ = State::Responded;
return lua_yield(state, 0);
}
int StreamHandleWrapper::luaHttpCall(lua_State* state) {
ASSERT(state_ == State::Running);
const int async_flag_index = 6;
if (!lua_isnone(state, async_flag_index) && !lua_isboolean(state, async_flag_index)) {
luaL_error(state, "http call asynchronous flag must be 'true', 'false', or empty");
}
if (lua_toboolean(state, async_flag_index)) {
return luaHttpCallAsynchronous(state);
} else {
return luaHttpCallSynchronous(state);
}
}
int StreamHandleWrapper::luaHttpCallSynchronous(lua_State* state) {
http_request_ = makeHttpCall(state, filter_, *this);
if (http_request_) {
state_ = State::HttpCall;
return lua_yield(state, 0);
} else {
// Immediate failure case. The return arguments are already on the stack.
ASSERT(lua_gettop(state) >= 2);
return 2;
}
}
int StreamHandleWrapper::luaHttpCallAsynchronous(lua_State* state) {
makeHttpCall(state, filter_, noopCallbacks());
return 0;
}
void StreamHandleWrapper::onSuccess(Http::ResponseMessagePtr&& response) {
ASSERT(state_ == State::HttpCall || state_ == State::Running);
ENVOY_LOG(debug, "async HTTP response complete");
http_request_ = nullptr;
// We need to build a table with the headers as return param 1. The body will be return param 2.
lua_newtable(coroutine_.luaState());
response->headers().iterate(
[](const Http::HeaderEntry& header, void* context) -> Http::HeaderMap::Iterate {
lua_State* state = static_cast<lua_State*>(context);
lua_pushlstring(state, header.key().getStringView().data(),
header.key().getStringView().length());
lua_pushlstring(state, header.value().getStringView().data(),
header.value().getStringView().length());
lua_settable(state, -3);
return Http::HeaderMap::Iterate::Continue;
},
coroutine_.luaState());
// TODO(mattklein123): Avoid double copy here.
if (response->body() != nullptr) {
lua_pushstring(coroutine_.luaState(), response->bodyAsString().c_str());
} else {
lua_pushnil(coroutine_.luaState());
}
// In the immediate failure case, we are just going to immediately return to the script. We
// have already pushed the return arguments onto the stack.
if (state_ == State::HttpCall) {
state_ = State::Running;
markLive();
try {
coroutine_.resume(2, yield_callback_);
markDead();
} catch (const Filters::Common::Lua::LuaException& e) {
filter_.scriptError(e);
}
if (state_ == State::Running) {
headers_continued_ = true;
callbacks_.continueIteration();
}
}
}
void StreamHandleWrapper::onFailure(Http::AsyncClient::FailureReason) {
ASSERT(state_ == State::HttpCall || state_ == State::Running);
ENVOY_LOG(debug, "async HTTP failure");
// Just fake a basic 503 response.
Http::ResponseMessagePtr response_message(
new Http::ResponseMessageImpl(Http::createHeaderMap<Http::ResponseHeaderMapImpl>(
{{Http::Headers::get().Status,
std::to_string(enumToInt(Http::Code::ServiceUnavailable))}})));
response_message->body() = std::make_unique<Buffer::OwnedImpl>("upstream failure");
onSuccess(std::move(response_message));
}
int StreamHandleWrapper::luaHeaders(lua_State* state) {
ASSERT(state_ == State::Running);
if (headers_wrapper_.get() != nullptr) {
headers_wrapper_.pushStack();
} else {
headers_wrapper_.reset(HeaderMapWrapper::create(state, headers_,
[this] {
// If we are about to do a modifiable header
// operation, blow away the route cache. We
// could be a little more intelligent about
// when we do this so the performance would be
// higher, but this is simple and will get the
// job done for now. This is a NOP on the
// encoder path.
if (!headers_continued_) {
callbacks_.onHeadersModified();
}
return !headers_continued_;
}),
true);
}
return 1;
}
int StreamHandleWrapper::luaBody(lua_State* state) {
ASSERT(state_ == State::Running);
if (end_stream_) {
if (!buffered_body_ && saw_body_) {
return luaL_error(state, "cannot call body() after body has been streamed");
} else if (callbacks_.bufferedBody() == nullptr) {
ENVOY_LOG(debug, "end stream. no body");
return 0;
} else {
if (body_wrapper_.get() != nullptr) {
body_wrapper_.pushStack();
} else {
body_wrapper_.reset(
Filters::Common::Lua::BufferWrapper::create(state, *callbacks_.bufferedBody()), true);
}
return 1;
}
} else if (saw_body_) {
return luaL_error(state, "cannot call body() after body streaming has started");
} else {
ENVOY_LOG(debug, "yielding for full body");
state_ = State::WaitForBody;
buffered_body_ = true;
return lua_yield(state, 0);
}
}
int StreamHandleWrapper::luaBodyChunks(lua_State* state) {
ASSERT(state_ == State::Running);
if (saw_body_) {
luaL_error(state, "cannot call bodyChunks after body processing has begun");
}
// We are currently at the top of the stack. Push a closure that has us as the upvalue.
lua_pushcclosure(state, static_luaBodyIterator, 1);
return 1;
}
int StreamHandleWrapper::luaBodyIterator(lua_State* state) {
ASSERT(state_ == State::Running);
if (end_stream_) {
ENVOY_LOG(debug, "body complete. no more body chunks");
return 0;
} else {
ENVOY_LOG(debug, "yielding for next body chunk");
state_ = State::WaitForBodyChunk;
return lua_yield(state, 0);
}
}
int StreamHandleWrapper::luaTrailers(lua_State* state) {
ASSERT(state_ == State::Running);
if (end_stream_ && trailers_ == nullptr) {
ENVOY_LOG(debug, "end stream. no trailers");
return 0;
} else if (trailers_ != nullptr) {
if (trailers_wrapper_.get() != nullptr) {
trailers_wrapper_.pushStack();
} else {
trailers_wrapper_.reset(HeaderMapWrapper::create(state, *trailers_, []() { return true; }),
true);
}
return 1;
} else {
ENVOY_LOG(debug, "yielding for trailers");
state_ = State::WaitForTrailers;
return lua_yield(state, 0);
}
}
int StreamHandleWrapper::luaMetadata(lua_State* state) {
ASSERT(state_ == State::Running);
if (metadata_wrapper_.get() != nullptr) {
metadata_wrapper_.pushStack();
} else {
metadata_wrapper_.reset(
Filters::Common::Lua::MetadataMapWrapper::create(state, callbacks_.metadata()), true);
}
return 1;
}
int StreamHandleWrapper::luaStreamInfo(lua_State* state) {
ASSERT(state_ == State::Running);
if (stream_info_wrapper_.get() != nullptr) {
stream_info_wrapper_.pushStack();
} else {
stream_info_wrapper_.reset(StreamInfoWrapper::create(state, callbacks_.streamInfo()), true);
}
return 1;
}
int StreamHandleWrapper::luaConnection(lua_State* state) {
ASSERT(state_ == State::Running);
if (connection_wrapper_.get() != nullptr) {
connection_wrapper_.pushStack();
} else {
connection_wrapper_.reset(
Filters::Common::Lua::ConnectionWrapper::create(state, callbacks_.connection()), true);
}
return 1;
}
int StreamHandleWrapper::luaLogTrace(lua_State* state) {
const char* message = luaL_checkstring(state, 2);
filter_.scriptLog(spdlog::level::trace, message);
return 0;
}
int StreamHandleWrapper::luaLogDebug(lua_State* state) {
const char* message = luaL_checkstring(state, 2);
filter_.scriptLog(spdlog::level::debug, message);
return 0;
}
int StreamHandleWrapper::luaLogInfo(lua_State* state) {
const char* message = luaL_checkstring(state, 2);
filter_.scriptLog(spdlog::level::info, message);
return 0;
}
int StreamHandleWrapper::luaLogWarn(lua_State* state) {
const char* message = luaL_checkstring(state, 2);
filter_.scriptLog(spdlog::level::warn, message);
return 0;
}
int StreamHandleWrapper::luaLogErr(lua_State* state) {
const char* message = luaL_checkstring(state, 2);
filter_.scriptLog(spdlog::level::err, message);
return 0;
}
int StreamHandleWrapper::luaLogCritical(lua_State* state) {
const char* message = luaL_checkstring(state, 2);
filter_.scriptLog(spdlog::level::critical, message);
return 0;
}
int StreamHandleWrapper::luaVerifySignature(lua_State* state) {
// Step 1: get hash function
absl::string_view hash = luaL_checkstring(state, 2);
// Step 2: get key pointer
auto ptr = lua_touserdata(state, 3);
// Step 3: get signature
const char* signature = luaL_checkstring(state, 4);
int sig_len = luaL_checknumber(state, 5);
const std::vector<uint8_t> sig_vec(signature, signature + sig_len);
// Step 4: get clear text
const char* clear_text = luaL_checkstring(state, 6);
int text_len = luaL_checknumber(state, 7);
const std::vector<uint8_t> text_vec(clear_text, clear_text + text_len);
// Step 5: verify signature
auto crypto = reinterpret_cast<Envoy::Common::Crypto::CryptoObject*>(ptr);
auto& crypto_util = Envoy::Common::Crypto::UtilitySingleton::get();
auto output = crypto_util.verifySignature(hash, *crypto, sig_vec, text_vec);
lua_pushboolean(state, output.result_);
if (output.result_) {
lua_pushnil(state);
} else {
lua_pushlstring(state, output.error_message_.data(), output.error_message_.length());
}
return 2;
}
int StreamHandleWrapper::luaImportPublicKey(lua_State* state) {
// Get byte array and the length.
const char* str = luaL_checkstring(state, 2);
int n = luaL_checknumber(state, 3);
std::vector<uint8_t> key(str, str + n);
if (public_key_wrapper_.get() != nullptr) {
public_key_wrapper_.pushStack();
} else {
auto& crypto_util = Envoy::Common::Crypto::UtilitySingleton::get();
Envoy::Common::Crypto::CryptoObjectPtr crypto_ptr = crypto_util.importPublicKey(key);
public_key_wrapper_.reset(PublicKeyWrapper::create(state, std::move(crypto_ptr)), true);
}
return 1;
}
FilterConfig::FilterConfig(const std::string& lua_code, ThreadLocal::SlotAllocator& tls,
Upstream::ClusterManager& cluster_manager)
: cluster_manager_(cluster_manager), lua_state_(lua_code, tls) {
lua_state_.registerType<Filters::Common::Lua::BufferWrapper>();
lua_state_.registerType<Filters::Common::Lua::MetadataMapWrapper>();
lua_state_.registerType<Filters::Common::Lua::MetadataMapIterator>();
lua_state_.registerType<Filters::Common::Lua::ConnectionWrapper>();
lua_state_.registerType<Filters::Common::Lua::SslConnectionWrapper>();
lua_state_.registerType<HeaderMapWrapper>();
lua_state_.registerType<HeaderMapIterator>();
lua_state_.registerType<StreamInfoWrapper>();
lua_state_.registerType<DynamicMetadataMapWrapper>();
lua_state_.registerType<DynamicMetadataMapIterator>();
lua_state_.registerType<StreamHandleWrapper>();
lua_state_.registerType<PublicKeyWrapper>();
request_function_slot_ = lua_state_.registerGlobal("envoy_on_request");
if (lua_state_.getGlobalRef(request_function_slot_) == LUA_REFNIL) {
ENVOY_LOG(info, "envoy_on_request() function not found. Lua filter will not hook requests.");
}
response_function_slot_ = lua_state_.registerGlobal("envoy_on_response");
if (lua_state_.getGlobalRef(response_function_slot_) == LUA_REFNIL) {
ENVOY_LOG(info, "envoy_on_response() function not found. Lua filter will not hook responses.");
}
}
void Filter::onDestroy() {
destroyed_ = true;
if (request_stream_wrapper_.get()) {
request_stream_wrapper_.get()->onReset();
}
if (response_stream_wrapper_.get()) {
response_stream_wrapper_.get()->onReset();
}
}
Http::FilterHeadersStatus Filter::doHeaders(StreamHandleRef& handle,
Filters::Common::Lua::CoroutinePtr& coroutine,
FilterCallbacks& callbacks, int function_ref,
Http::HeaderMap& headers, bool end_stream) {
if (function_ref == LUA_REFNIL) {
return Http::FilterHeadersStatus::Continue;
}
coroutine = config_->createCoroutine();
handle.reset(StreamHandleWrapper::create(coroutine->luaState(), *coroutine, headers, end_stream,
*this, callbacks),
true);
Http::FilterHeadersStatus status = Http::FilterHeadersStatus::Continue;
try {
status = handle.get()->start(function_ref);
handle.markDead();
} catch (const Filters::Common::Lua::LuaException& e) {
scriptError(e);
}
return status;
}
Http::FilterDataStatus Filter::doData(StreamHandleRef& handle, Buffer::Instance& data,
bool end_stream) {
Http::FilterDataStatus status = Http::FilterDataStatus::Continue;
if (handle.get() != nullptr) {
try {
handle.markLive();
status = handle.get()->onData(data, end_stream);
handle.markDead();
} catch (const Filters::Common::Lua::LuaException& e) {
scriptError(e);
}
}
return status;
}
Http::FilterTrailersStatus Filter::doTrailers(StreamHandleRef& handle, Http::HeaderMap& trailers) {
Http::FilterTrailersStatus status = Http::FilterTrailersStatus::Continue;
if (handle.get() != nullptr) {
try {
handle.markLive();
status = handle.get()->onTrailers(trailers);
handle.markDead();
} catch (const Filters::Common::Lua::LuaException& e) {
scriptError(e);
}
}
return status;
}
void Filter::scriptError(const Filters::Common::Lua::LuaException& e) {
scriptLog(spdlog::level::err, e.what());
request_stream_wrapper_.reset();
response_stream_wrapper_.reset();
}
void Filter::scriptLog(spdlog::level::level_enum level, const char* message) {
switch (level) {
case spdlog::level::trace:
ENVOY_LOG(trace, "script log: {}", message);
return;
case spdlog::level::debug:
ENVOY_LOG(debug, "script log: {}", message);
return;
case spdlog::level::info:
ENVOY_LOG(info, "script log: {}", message);
return;
case spdlog::level::warn:
ENVOY_LOG(warn, "script log: {}", message);
return;
case spdlog::level::err:
ENVOY_LOG(error, "script log: {}", message);
return;
case spdlog::level::critical:
ENVOY_LOG(critical, "script log: {}", message);
return;
case spdlog::level::off:
NOT_IMPLEMENTED_GCOVR_EXCL_LINE;
}
}
void Filter::DecoderCallbacks::respond(Http::ResponseHeaderMapPtr&& headers, Buffer::Instance* body,
lua_State*) {
callbacks_->encodeHeaders(std::move(headers), body == nullptr);
if (body && !parent_.destroyed_) {
callbacks_->encodeData(*body, true);
}
}
void Filter::EncoderCallbacks::respond(Http::ResponseHeaderMapPtr&&, Buffer::Instance*,
lua_State* state) {
// TODO(mattklein123): Support response in response path if nothing has been continued
// yet.
luaL_error(state, "respond not currently supported in the response path");
}
} // namespace Lua
} // namespace HttpFilters
} // namespace Extensions
} // namespace Envoy