andreif / uwsgi-tools

curl and proxy for remote uwsgi app server
BSD 3-Clause "New" or "Revised" License
43 stars 11 forks source link

uwsgi_curl just crashes #2

Closed thanatos closed 6 years ago

thanatos commented 7 years ago

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.

$ env/bin/uwsgi_curl /path/to/a/uwsgi/socket /
Traceback (most recent call last):
  File "env/bin/uwsgi_curl", line 11, in <module>
    sys.exit(cli())
  File "/home/roy/env/local/lib/python2.7/site-packages/uwsgi_tools/curl.py", line 48, in cli
    print(curl(args.uwsgi_addr[0], args.url))
  File "/home/roy/env/local/lib/python2.7/site-packages/uwsgi_tools/curl.py", line 32, in curl
    return ask_uwsgi(addr_and_port, var)
  File "/home/roy/env/local/lib/python2.7/site-packages/uwsgi_tools/curl.py", line 7, in ask_uwsgi
    s.connect(parse_addr(addr_and_port))
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
TypeError: an integer is required

Edit:

  1. cli() doesn't return an exit code for sys.exit(), but this is a red herring
  2. the connect line is hard-wired to a TCP socket. I'm stuck with a Unix socket.
thanatos commented 7 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.

andreif commented 7 years ago

@thanatos Hi, file sockets are not supported atm, but it can be implemented. What SO answer you are referring to?

dcode commented 7 years ago

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 /
luckydonald commented 6 years ago

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.

andreif commented 6 years ago

Pull requests are welcome! 😉

luckydonald commented 6 years ago

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!

andreif commented 6 years ago

@luckydonald Let me know if you are going to make a PR with your changes or just want to run a separate fork.

andreif commented 6 years ago

@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! ❤️

andreif commented 6 years ago

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!

andreif commented 6 years ago

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?