You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/04/24 02:50:08 UTC

[GitHub] [apisix] crystal-lee opened a new issue, #6916: help request:

crystal-lee opened a new issue, #6916:
URL: https://github.com/apache/apisix/issues/6916

   ### Description
   
   I use go-runner to make a plugin in ext-plugin-post-req。And my plugin is used to get target url and redirect to target。
   So I do not need the upstream。But  if I do not set upstream , I get 503 Service Temporarily Unavailable。
   what should I do?
   
   ### Environment
   
   - APISIX version (run `apisix version`):2.13.1
   - Operating system (run `uname -a`):Linux 5fbc1a1f78bf 5.10.25-linuxkit #1 SMP Tue Mar 23 09:27:39 UTC 2021 x86_64 Linux
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`):nginx version: openresty/1.19.9.1
   - etcd version, if relevant (run `curl http://127.0.0.1:9090/v1/server_info`):
   - APISIX Dashboard version, if relevant:
   - Plugin runner version, for issues related to plugin runners:
   - LuaRocks version, for installation issues (run `luarocks --version`):/usr/local/bin/luarocks 3.8.0
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] tzssangglass commented on issue #6916: I want use ext-plugin-post-req plugin, and do not have upstream

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #6916:
URL: https://github.com/apache/apisix/issues/6916#issuecomment-1134073320

   > But if I do not set upstream , I get 503 Service Temporarily Unavailable。 what should I do?
   
   upstream is required, as required by the APISIX implementation mechanism.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] crystal-lee closed issue #6916: I want use ext-plugin-post-req plugin, and do not have upstream

Posted by GitBox <gi...@apache.org>.
crystal-lee closed issue #6916: I want use ext-plugin-post-req plugin, and do not have upstream
URL: https://github.com/apache/apisix/issues/6916


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] crystal-lee commented on issue #6916: I want use ext-plugin-post-req plugin, and do not have upstream

Posted by GitBox <gi...@apache.org>.
crystal-lee commented on issue #6916:
URL: https://github.com/apache/apisix/issues/6916#issuecomment-1133561098

   This is the code。The request do not be forwarded to the upstream, but I must set a upstream?
   
   ```
   func (p CBFTransfer) Filter(conf interface{}, w http.ResponseWriter, r pkgHTTP.Request) {
   	//跳转
   	Redirect(w, r, "http://www.baidu.com", http.StatusMovedPermanently)
   }
   ```
   ```
   func Redirect(w http.ResponseWriter, r pkgHTTP.Request, url string, code int) {
   	log.Infof("redirect to %s", url)
   	if u, err := urlpkg.Parse(url); err == nil {
   		// If url was relative, make its path absolute by
   		// combining with request path.
   		// The client would probably do this for us,
   		// but doing it ourselves is more reliable.
   		// See RFC 7231, section 7.1.2
   		if u.Scheme == "" && u.Host == "" {
   
   			oldpath := gconv.String(r.Path())
   			if oldpath == "" { // should not happen, but avoid a crash if it does
   				oldpath = "/"
   			}
   
   			// no leading http://server
   			if url == "" || url[0] != '/' {
   				// make relative path absolute
   				olddir, _ := path.Split(oldpath)
   				url = olddir + url
   			}
   
   			var query string
   			if i := strings.Index(url, "?"); i != -1 {
   				url, query = url[:i], url[i:]
   			}
   
   			// clean up but preserve trailing slash
   			trailing := strings.HasSuffix(url, "/")
   			url = path.Clean(url)
   			if trailing && !strings.HasSuffix(url, "/") {
   				url += "/"
   			}
   			url += query
   		}
   	}
   
   	h := w.Header()
   
   	// RFC 7231 notes that a short HTML body is usually included in
   	// the response because older user agents may not understand 301/307.
   	// Do it only if the request didn't already have a Content-Type header.
   	_, hadCT := h["Content-Type"]
   
   	h.Set("Location", hexEscapeNonASCII(url))
   	if !hadCT && (r.Method() == "GET" || r.Method() == "HEAD") {
   		h.Set("Content-Type", "text/html; charset=utf-8")
   	}
   	w.WriteHeader(code)
   
   	// Shouldn't send the body for POST or HEAD; that leaves GET.
   	if !hadCT && r.Method() == "GET" {
   		body := "<a href=\"" + htmlEscape(url) + "\">" + http.StatusText(code) + "</a>.\n"
   		fmt.Fprintln(w, body)
   	}
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] crystal-lee commented on issue #6916: I want use ext-plugin-post-req plugin, and do not have upstream

Posted by GitBox <gi...@apache.org>.
crystal-lee commented on issue #6916:
URL: https://github.com/apache/apisix/issues/6916#issuecomment-1134145623

   thanks ,i get it


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] soulbird commented on issue #6916: I want use ext-plugin-post-req plugin, and do not have upstream

Posted by GitBox <gi...@apache.org>.
soulbird commented on issue #6916:
URL: https://github.com/apache/apisix/issues/6916#issuecomment-1107697522

   If you have already operated `ResponseWriter`, the request should not be forwarded to the upstream. So, how do you implement `redirect to target`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org