resty | Simple HTTP and REST client library for Go | HTTP library
kandi X-RAY | resty Summary
kandi X-RAY | resty Summary
Simple HTTP and REST client library for Go (inspired by Ruby rest-client). Features section describes in detail about Resty capabilities.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of resty
resty Key Features
resty Examples and Code Snippets
Community Discussions
Trending Discussions on resty
QUESTION
I am trying to handle incoming HTTP requests by Nginx and Lua. I need to read a blue from Redis in each request and currently, I open a Redis connection in every request by this code:
...ANSWER
Answered 2021-May-09 at 07:40It is impossible to share a cosocket object (and, therefore, a redis object, check this answer for details) between different requests:
The cosocket object created by this API function has exactly the same lifetime as the Lua handler creating it. So never pass the cosocket object to any other Lua handler (including ngx.timer callback functions) and never share the cosocket object between different Nginx requests.
However, nginx/ngx_lua uses a connection pool internally:
Before actually resolving the host name and connecting to the remote backend, this method will always look up the connection pool for matched idle connections created by previous calls of this method
That being said, you just need to use sock:setkeepalive() instead of sock:close() for persistent connections. The redis object interface has a corresponding method: red:set_keepalive().
You'll still need to create a redis object on a per request basis, but this will help to avoid a connection overhead.
QUESTION
I have a docker-compose that run two containers, one an Nginx with Lua-module and another is a simple Redis, here is the docker-compose file:
...ANSWER
Answered 2021-May-02 at 12:26I found the solution but I did not the root cause of problem:
I changed my Nginx-Lua image from danday74/nginx-lua to fabiocicerchia/nginx-lua, and It worked like a charm. the first one was created on Nginx version 1.16 and the last one was created by Nginx 1.19.
QUESTION
I am trying to create a kong plugin. It works great when running as part of kong server but when I am trying to write some unit tests with busted, resty.openssl.digest
func load fails. More specifically while loading the version.lua
I am not sure what exactly I am missing. Maybe some link which is supposed to link openSSL's C functions to lua.
Here is a minimal snippet to reproduce the problem.
...ANSWER
Answered 2021-Apr-24 at 23:03You should ffi.load
your .so library before using functions from it.
QUESTION
I have an nginx/openresty client to a keycloack server for authorization using openid. I am using lua-resty-openidc to allow access to services behind the proxy.
The user can access his profile at
https:///auth/realms//account
and logout through
https:///auth/realms//protocol/openid-connect/logout
The problem is that, even after logout, the user can still access the services behind the server, basically it seems the token he gets from keycloak is still valid or something.... This is also a behaviour that has been observed by other users, see for example this question on how to logout from keycloak the comments from ch271828n
How can I ensure that after logout the user will no longer be able to get access until he logs in anew?
...ANSWER
Answered 2021-Apr-22 at 13:49I had to check the lua source code, but I think I have figured the logout behaviour out: Lua-resty-openidc establishes sessions, and they are terminated when a specific url access is detected (it is controlled by opts.logout_path
which we will need to be set to an address in the path of service, e.g. .../service/logout)
In essence, there are two urls that need to be hit, one for keycloack logout, and one for openresty session logout. Accessing the keycloack logout url https:///auth/realms//protocol/openid-connect/logout
is done by lua after we access the opts.logout_path at https:///service/logout
So after setting up everything correctly, all we have to do to logout is hit https:///service/logout
. This will destroy the session and log us out.
I think we need to set opts.revoke_tokens_on_logout
to true
, Also note that from my experiments, for some reason, setting up a redirect_after_logout_uri
may result in the user not signing out due to redirections.
Here is an example of what we need to have for nginx.conf to make this work....
QUESTION
when making a request to an url from within my nginx the response of this request is always not present. It seems that the request is not sended.
This is my nginx.conf
...ANSWER
Answered 2021-Mar-24 at 19:00no resolver defined to resolve "www.google.de"
You need to configure the resolver
:
https://github.com/openresty/lua-nginx-module#tcpsockconnect
In case of domain names, this method will use Nginx core's dynamic resolver to parse the domain name without blocking and it is required to configure the resolver directive in the nginx.conf file like this:
QUESTION
I've asked here but thought I'd post on SO as well:
given this code:
...ANSWER
Answered 2021-Jan-26 at 18:06There are two errors in your code.
It is not possible to pass the cosocket object between Lua handlers (emphasis added by me):
The cosocket object created by this API function has exactly the same lifetime as the Lua handler creating it. So never pass the cosocket object to any other Lua handler (including ngx.timer callback functions) and never share the cosocket object between different Nginx requests.
https://github.com/openresty/lua-nginx-module#ngxsockettcp
In your case, the reference to the cosocket object is stored in the
client
table (client._sock
).ngx.print
/ngx.say
are not available in thengx.timer.*
context.https://github.com/openresty/lua-nginx-module#ngxsay (check the context: section).
You can use
ngx.log
instead (it writes to nginx log, seterror_log stderr debug;
innginx.conf
to print logs to stderr).
The following code works as expected:
QUESTION
I have managed to successfully setup my API automation tests in Go using Resty and execute a GET request.
I am however struggling to get a POST API test to return a 200 instead I receive a 400 error message. I'm not sure what I'm doing wrong.
Please see my code below. (The POST request works in Postman by the way!)
...ANSWER
Answered 2020-Dec-06 at 14:33You need to add a Content-Type. This should work:
QUESTION
Here is working example of openresty nginx.conf file. In this example I make request to redis multiple times. As you can see I request data from redis first to check if domain can get SSL then again to get what backend to proxy request to, and then I've added S3 proxy and I would need to request data from redis again. I'm new to OpenResty and Lua and I wonder if it is possible to fetch data from redis once and use it multiple times across the script?
...ANSWER
Answered 2020-Dec-01 at 14:52OpenResty run Lua hooks in a sandbox, so one cannot use global variables to share data.
You shall use Data Sharing within an Nginx Worker It is usual practice to cache anything on Lua module level, possibly with some reasonable expiration period if data stored in Redis may be changed.
BTW - don't use XXX_by_lua directives - you should take care about nginx escaping rules, use XXX_by_lua_block.
Additional example:
QUESTION
Lately i was playing with openresty and lua-resty-auto-ssl and can't find how to disable TLS 1.0 and TLS 1.1, (and add ciphers). I just read whole internet twice, and found nothing. In nginx is simple one line ssl_protocols TLSv1.3 TLSv1.2;
but its not affecting lua-resty-auto-ssl i have no idea how to do it, would be nice if someone could shed some light on this topic.
ANSWER
Answered 2020-Nov-03 at 18:45I just found answer here:
lua_ssl_protocols TLSv1.2 TLSv1.3;
QUESTION
I'm using the kubernetes nginx ingress controller
...ANSWER
Answered 2020-Oct-26 at 09:30I finally ended with creating a new method in openidc.lua, which apparently contains all necessary stuff to call jwt.lua. Not sure what's missing from calling it directly from nginx.tmpl though.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install resty
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page