Comments (8)
- you can get/set the header via Request.Header, see https://pkg.go.dev/github.com/apache/[email protected]/pkg/http#Header
- you can stop the request with headers, see
- currently, there is no way to set response header without stopping the request (the
core.response.set_header(k, v)
in your example). Maybe you can open an issue to track it?
from apisix-go-plugin-runner.
- you can get/set the header via Request.Header, see https://pkg.go.dev/github.com/apache/[email protected]/pkg/http#Header
- you can stop the request with headers, see
- currently, there is no way to set response header without stopping the request (the
core.response.set_header(k, v)
in your example). Maybe you can open an issue to track it?
I want to proxy all the responses. Is there any way to do that?
from apisix-go-plugin-runner.
I wrote a demo, but I found that the response body is empty ,For example, if I add this plugin to luacode.com, and I request a.com, the plugin will request b.com and do the processing, now the processing is successful but there is no response content from luacode.com.
package plugins
import (
"encoding/json"
"fmt"
pkgHTTP "github.com/apache/apisix-go-plugin-runner/pkg/http"
"github.com/apache/apisix-go-plugin-runner/pkg/log"
"github.com/apache/apisix-go-plugin-runner/pkg/plugin"
"github.com/sirupsen/logrus"
"net/http"
"time"
)
func init() {
err := plugin.RegisterPlugin(&ForwardAuth{})
if err != nil {
log.Fatalf("failed to register plugin ForwardAuth: %s", err)
}
}
// ForwardAuth is a demo to show how to return data directly instead of proxying
// it to the upstream.
type ForwardAuth struct {
}
type ForwardAuthConf struct {
Body string `json:"body"`
}
func (p *ForwardAuth) Name() string {
return "forward-auth"
}
func (p *ForwardAuth) ParseConf(in []byte) (interface{}, error) {
conf := ForwardAuthConf{}
err := json.Unmarshal(in, &conf)
return conf, err
}
func (p *ForwardAuth) Filter(conf interface{}, w http.ResponseWriter, r pkgHTTP.Request) {
req, err := http.NewRequest("GET", "http://b.com", nil)
if err != nil {
logrus.Errorf("send request failed err:%v", err)
return
}
//req.Header.Set("Cookie", r.Header().Get("Cookie"))
client := http.Client{
Timeout: 5 * time.Second,
}
resp, err := client.Do(req)
if err != nil {
logrus.Errorf("get response failed err:%v", err)
return
}
if resp == nil {
logrus.Errorf("response is nil")
return
}
defer resp.Body.Close()
if len(resp.Header) > 0 {
for k, v := range resp.Header {
if v != nil {
w.Header().Set(k, v[0])
}
}
}
w.Header().Add("X-Resp-A6-Runner", "Go")
return
}
not use plugin
after use pulgin
from apisix-go-plugin-runner.
1.I found that after I use core.response.set_header(k, v) then the response body of the service I requested was empty.
2.What do you mean by this? @spacewander
- you can stop the request with headers, see
- currently, there is no way to set response header without stopping the request (the
core.response.set_header(k, v)
in your example). Maybe you can open an issue to track it?
from apisix-go-plugin-runner.
Currently, setting response data will mean stopping the current process and returning immediately without proxying the request to upstream.
from apisix-go-plugin-runner.
Currently, setting response data will mean stopping the current process and returning immediately without proxying the request to upstream.
How should I change to proxy the request to upstream ?
I've tried both severless-plugin and go-plugin-runner plugins to support forward-auth,But none of these are currently met, And not having this plugin would cause all our services not being accessible
from apisix-go-plugin-runner.
@GhangZh try w.Header().Add("X-Resp-A6-Runner", "Go")
change to r.Header().Set("X-Resp-A6-Runner", "Go")
from apisix-go-plugin-runner.
Thanks, change to r.Header().Set("X-Resp-A6-Runner", "Go") solved my problem
from apisix-go-plugin-runner.
Related Issues (20)
- 通过ext-plugin-pre-req插件为什么不能修改请求body。迫切的需要呀。apisix-go-plugin-runner
- how to use ext-plugin-pre-req change apisix request body。 base on apisix-go-plugin-runner
- request help: The plugin is registered, but cannot be viewed through v1/schema HOT 4
- request help: The ext-plugin-post-resp is not working properly HOT 1
- 插件中写了读取了req.Body(), 当body内容大于100多KB的时候,nginx worker内存会持续上升
- request help: how to rewrite request body? HOT 2
- request help: request id 和 通过 response 取的 request id 不一样 ,是否有什么规则? HOT 5
- 请求帮助:我需要将response与对应的request关联起来
- close
- request help: support get cookies method in request interface
- request help: I found the ext-plugin-post-resp will not execute if write response on ext-plugin-pre-req, is there any way to let ext-plugin-post-resp execute in this case?
- 当前5.0版本Go Plugin在最新的apisix:3.6.0上无法运行
- ext-plugin-post-resp processing content-type have problem HOT 1
- request help: How to get the cert and cacert from the plugin request
- request help: Need to rewrite the http request method HOT 3
- bug: Logging using `pkg/log` does not work
- request help: APISIX 无法正确启动go-runner HOT 2
- request help: How to get pkgHTTP.Request in ResponseFilter? HOT 2
- bug: request body rewrite cannot automatically modify content-length request header.
- request help: Request header modification sometimes does not take effect in ext-plugin-pre-req
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apisix-go-plugin-runner.