Closed thanatos closed 6 years ago
If I can get some time, I'd like to fix this, and I'd also like to PR the fix. "uwsgi_curl
" could have been much more useful to me today, and could be very useful in the future for debugging my uwsgi
servers since it allows me to isolate them from nginx
.
I'd like to fix this by making it more "curl"-like, in that it takes a URL as a primary argument. E.g.,
# Unix sockets
uwsgi_curl unix:///path/to/unix/socket
# TCP/IPv6
uwsgi_curl tcp://[::1]:3030/path/to/request
# TCP/IPv4
uwsgi_curl tcp://127.0.01:3030/path/to/request
# domain names are fine
uwsgi_curl tcp://localhost:3030/path/to/request
I would, in such a PR, bump the major, as this would be a breaking change to uwsgi_curl
's command line interface. I think it would be a much more featureful and ultimately useful interface.
@thanatos Hi, file sockets are not supported atm, but it can be implemented. What SO answer you are referring to?
This issue is about 5 months old, but I ran into the same problem. I used socat
as a workaround in the meantime.
socat TCP-LISTEN:8888,reuseaddr,fork UNIX-CLIENT:/run/uwsgi/example.socket
#in another terminal or background socat
uwsgi_curl localhost:8888 /
I implemented file sockets over at my fork (permalink).
$ uwsgi_curl unix:///tmp/socket GET /test --timeout 5
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 7
Success
exit code 0
(no error)
$ uwsgi_curl tcp://host/proxy_a GET /404
HTTP/1.1 404 NOT FOUND
Content-Type: text/html; charset=utf-8
Content-Length: 2s7
<h1>OMG IT IS GONE LOL</h1>
exit code 1
(error)
$ uwsgi_curl tcp://127.0.0.1:8080/proxy_b GET /test
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 7
Success
exit code 0
(no error)
I will add some more features I need in the following days, and would create a PR.
Pull requests are welcome! 😉
Status: I now implemented providing headers, just like the original curl. the latest version can be installed and tested via
$ pip install -e git://github.com/luckydonald-forks/uwsgi-tools.git@master#egg=uwsgi-tools
$ uwsgi_curl unix:///tmp/lel.sock GET /something -H 'X-Header: Yes' -H Test:foobar -H 'X-Never-Gonna: Give you up!';
Would result in the following headers to be sent:
X-Header: Yes
Test: foobar
X-Never-Gonna: Give you up!
Woop!
@luckydonald Let me know if you are going to make a PR with your changes or just want to run a separate fork.
@luckydonald Hm, I have been looking into your fork and I think I won't be able to merge all of your code while asking you to do quite a lot of changes would not be a good thing to do. I will take just some part of it. I have noticed some version-related issues in your code and the proxy part is broken atm. But anyway awesome work, thanks for helping! ❤️
Fixed in v1.1.0, released today. Please, give it a try and see if it works for you. I decided not to use schemes to keep it simple. IPv6 should also work now in uwsgi_curl I believe, but I did miss to test that.
Thanks @luckydonald for inspiration!
Although, this would probably be cleaner:
uwsgi_curl -H Host:host.name 127.0.01:3030/request/path
uwsgi_curl -H Host:host.name 127.0.01:3030 /request/path
uwsgi_curl -H Host:host.name [::1]:3030/request/path
uwsgi_curl -H Host:host.name /path/to/unix/socket /request/path
Also, uWSGI seems not supporting UDP for web requests. Does anyone really need it?
This is my first time using the tool, so it's possible I'm not invoking it correctly. However, my command appears to match that of SO answers. Regardless, it shouldn't just crash.
Edit:
cli()
doesn't return an exit code forsys.exit()
, but this is a red herringconnect
line is hard-wired to a TCP socket. I'm stuck with a Unix socket.