Skip to content

Instantly share code, notes, and snippets.

View bzp2010's full-sized avatar
:electron:

Zeping Bai bzp2010

:electron:
  • Mars
View GitHub Profile
@bzp2010
bzp2010 / APISIX-plugin-multi-dc.md
Last active October 13, 2023 09:45
APISIX cross-datacenter call plugin (dynamic upstream)

Apache APISIX's external service call multi-dc plugin demo

Logic

We define a configuration group in the plugin configuration that includes each data center and the services within it. It allows to configure a separate upstream for each service, while using the datacenter-level upstream as a fallback.

When the request arrives, we parse the content of the source Host and extract the target data center and services from it.

Then it will read that desired upstream from our predefined list of upstreams and set it as the upstream for this request. In this process, the request header and request body will be sent directly to the target service without being modified.

Code

use log::warn;
use proxy_wasm::traits::{Context, HttpContext};
use proxy_wasm::types::{Action, LogLevel};

proxy_wasm::main! {{
    proxy_wasm::set_log_level(LogLevel::Trace);
    proxy_wasm::set_http_context(|_, _| -> Box<dyn HttpContext> { Box::new(HttpCall) });
@bzp2010
bzp2010 / APISIX-mTLS-for-client-to-APISIX.md
Created September 17, 2022 06:11
APISIX mTLS for client to APISIX

APISIX mTLS for client to APISIX

Introduction

This gist provides a complete example of client-side authentication for Apache APISIX.

It includes the process of:

  • generating a certificate
  • configuring the certificate in APISIX
  • configuring the route in APISIX
@bzp2010
bzp2010 / APISIX-plugin-pipeline-request.md
Last active September 27, 2022 08:22
APISIX pipeline-request plugin demo

Apache APISIX's pipeline-request plugin demo

Logic

When handling client requests, the plugin will iterate through the nodes section of the configuration, requesting them in turn.

In the first request, it will send the complete method, query, header, and body of the client request, while in subsequent requests it will only send the last response with the POST method.

The successful response will be recorded in a temporary variable in last_resp, and each request in the loop will get the response body of the previous request from last_resp.body and overwrite the response body of the current request to last_resp.