Skip to content

Commit

Permalink
[fix] AdminProxy didn't work because Inbound was missing from the con…
Browse files Browse the repository at this point in the history
…texts
  • Loading branch information
pajama-coder committed Jul 19, 2022
1 parent 5429a26 commit 16fed95
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 21 deletions.
14 changes: 7 additions & 7 deletions src/admin-proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,30 @@ class AdminProxyHandler : public Filter {
}

virtual void process(Event *evt) override {
if (auto start = evt->as<MessageStart>()) {
if (m_pipeline) {
Filter::output(evt, m_pipeline->input());

} else if (auto start = evt->as<MessageStart>()) {
auto head = start->head()->as<http::RequestHead>();
if (!m_pipeline) {
auto &path = head->path()->str();
if (
utils::starts_with(path, "/api/") ||
utils::starts_with(path, "/repo/")
) {
m_pipeline = sub_pipeline(0, false, output());
m_pipeline = sub_pipeline(0, false, Filter::output());
}
}

if (m_pipeline) {
output(evt, m_pipeline->input());
Filter::output(evt, m_pipeline->input());
} else {
m_head = head;
}

} else if (m_pipeline) {
output(evt, m_pipeline->input());

} else if (evt->is<MessageEnd>() || evt->is<StreamEnd>()) {
if (m_head) {
output(m_proxy->handle(m_head));
Filter::output(m_proxy->handle(m_head));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/admin-proxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class AdminProxy {
public:
Module() : ModuleBase(0, "AdminProxy") {}
virtual auto new_context(pipy::Context *base) -> pipy::Context* override {
return new Context();
return new Context(base);
}
};

Expand Down
9 changes: 5 additions & 4 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ namespace pipy {

uint64_t Context::s_context_id = 0;

Context::Context()
: Context(nullptr, nullptr, nullptr)
Context::Context(Context *base)
: Context(base, nullptr, nullptr)
{
}

Context::Context(ContextGroup *group, Worker *worker, pjs::Object *global, ContextData *data)
Context::Context(Context *base, Worker *worker, pjs::Object *global, ContextData *data)
: pjs::Context(global, data ? data->elements() : nullptr)
, m_group(group ? group : new ContextGroup())
, m_group(base ? base->group() : new ContextGroup())
, m_worker(worker)
, m_data(data)
{
Expand All @@ -55,6 +55,7 @@ Context::Context(ContextGroup *group, Worker *worker, pjs::Object *global, Conte
}
}
}
if (base) m_inbound = base->m_inbound;
if (!++s_context_id) s_context_id++;
m_id = s_context_id;
Log::debug("[context %p] ++ id = %llu", this, m_id);
Expand Down
4 changes: 2 additions & 2 deletions src/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Context :
public List<Context>::Item
{
public:
Context();
Context(Context *base = nullptr);

auto id() const -> uint64_t { return m_id; }
auto data(int i) const -> ContextDataBase* { return m_data->at(i)->as<ContextDataBase>(); }
Expand All @@ -63,7 +63,7 @@ class Context :
private:
typedef pjs::PooledArray<pjs::Ref<pjs::Object>> ContextData;

Context(ContextGroup *group, Worker *worker, pjs::Object *global, ContextData *data = nullptr);
Context(Context *base, Worker *worker, pjs::Object *global, ContextData *data = nullptr);

uint64_t m_id;
ContextGroup* m_group;
Expand Down
2 changes: 1 addition & 1 deletion src/filters/http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class Demux :
public:
struct Options : public http2::Endpoint::Options {
size_t buffer_size = DATA_CHUNK_SIZE;
Options();
Options() {}
Options(pjs::Object *options);
};

Expand Down
7 changes: 1 addition & 6 deletions src/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,7 @@ auto Worker::new_runtime_context(Context *base) -> Context* {
data->at(i) = mod->new_context_data(proto);
}
}
auto ctx = new Context(
base ? base->group() : nullptr,
this, m_global_object, data
);
if (base) ctx->m_inbound = base->m_inbound;
return ctx;
return new Context(base, this, m_global_object, data);
}

bool Worker::solve(pjs::Context &ctx, pjs::Str *filename, pjs::Value &result) {
Expand Down

0 comments on commit 16fed95

Please sign in to comment.