Commit Graph

25 Commits

Author SHA1 Message Date
Damien George
fd03a0587f examples/network: Support full URLs in HTTP(S) client examples.
Not just the domain name.  This gives better HTTP 1.0 examples if someone
wants to copy them.

Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 12:28:58 +10:00
Damien George
d75705311a examples/network: Use SSLContext instead of old ssl.wrap_socket.
`ssl.wrap_socket()` is deprecated in CPython, so use `SSLContext` instead,
so the example is a good example to copy.

Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 12:28:58 +10:00
Damien George
c8385ef75a examples/network: Support IPv4 and IPv6 in HTTP client examples.
The main changes here are to pass the address family and socket type to
`getaddrinfo()`, and then use the result of the address lookup when
creating the socket, so it has the correct address family.

This allows both IPv4 and IPv6 to work, because the socket is created with
the correct AF_INETx type for the address.

Also add some more comments to the examples to explain what's going on.

Fixes issue #15580.

Signed-off-by: Damien George <damien@micropython.org>
2024-08-28 12:28:58 +10:00
Damien George
cc3550eeef examples/network: Add example of HTTPS client using non-blocking socket.
Non-blocking SSL streams can be difficult to get right, so provide a
working example, of a HTTPS client.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-13 11:37:00 +10:00
Damien George
bd610ff016 examples/network: Rename SSL examples to start with https.
It's better for discoverability to have these examples named `https_xxx.py`
rather than `http_xxx_ssl.py`.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-13 11:35:41 +10:00
Jim Mussared
5fd042e7d1 all: Replace all uses of umodule in Python code.
Applies to drivers/examples/extmod/port-modules/tools.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:24 +10:00
Christian Clauss
2a1db770ce all: Fix cases of Python variable assigned but never used.
This fixes ruff rule F841.
2023-05-02 16:36:05 +10:00
Damien George
69661f3343 all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
2020-02-28 10:33:03 +11:00
Damien George
ba12cdba85 examples/network: Add testing key/cert to SSL HTTP server example.
This example will now work on all ports with networking and ssl support,
with both axtls and mbedtls.
2019-12-18 15:04:00 +11:00
Paul Sokolovsky
00a9590e3a examples/http_client: Use read() instead of readall(). 2016-11-14 00:24:45 +03:00
Paul Sokolovsky
73b72799f3 examples/http_server_simplistic: Add "not suitable for real use" note. 2016-10-26 12:25:33 +03:00
Paul Sokolovsky
fa5ac678fc examples/network/http_client*: Use \r\n line-endings in request. 2016-10-09 19:36:04 +03:00
Paul Sokolovsky
3d19adf9b3 examples/network: Split recv- and read-based HTTP servers.
Name recv() based a "simplistic", as it can't work robustly in every
environment. All this is to let people concentreate on proper, read()-
based one (and to turn recv() based into a "negative showcase",
explaining what are the pitfalls of such approach).
2016-08-06 01:59:51 +03:00
Paul Sokolovsky
614deb82c7 examples/http_client*: Be sure to close socket.
Otherwise, on bare-metal/RTOS systems can lead to resource leaks.
2016-07-23 00:41:19 +03:00
Paul Sokolovsky
e3f0f31e07 examples/http_server*: Update for buffered-like streams (read line by line).
Since "read-exactly" stream refactor, where stream.read(N) will read
exactly N bytes (unless EOF), http_server* examples can't any longer do
client_socket.read(4096) and expect to get full request (it will block
on HTTP/1.1 client). Instead, read request line by line, as the HTTP
protocol requires.
2016-07-10 23:01:52 +03:00
Paul Sokolovsky
c2d885501f examples/network/: Use getaddrinfo() result in easy way.
Instead of extracting 4th element, extact last. Much easier to remember!
2016-05-03 00:45:37 +03:00
Paul Sokolovsky
8fcfaf6f22 examples/http_server_ssl.py: HTTPS server example. 2016-04-28 21:39:17 +03:00
Paul Sokolovsky
4f2d59e82f examples/http_client_ssl.py: HTTPS client example. 2016-04-02 23:19:03 +03:00
Paul Sokolovsky
ec5f8db49d examples/http_server.py: Bind to 0.0.0.0, to be accessible from other hosts.
This is helpful when running on deeply embedded targets, but may be
"security risk". Caveat emptor.
2016-04-02 23:14:19 +03:00
Paul Sokolovsky
c07a03a36d examples/http_server.py: Introduce main() function.
Allows to re-run code if it was imported as a module (e.g., on bare-metal
ports).
2016-04-02 20:57:58 +03:00
Paul Sokolovsky
aa3fb7b387 examples/http_server.py: Refactor/simplify for Python 3.5. 2016-04-02 20:53:29 +03:00
Paul Sokolovsky
fd2b71f972 examples/http_client.py: Introduce main() function.
Allows to re-run code if it was imported as a module (e.g., on bare-metal
ports).
2016-04-02 19:13:39 +03:00
Paul Sokolovsky
a5d07c3aba examples/http_client.py: Improve CPython compatibility in stream mode. 2016-04-02 17:28:42 +03:00
Paul Sokolovsky
cef073877b example/http_client.py: Remove unused code. 2016-04-01 21:10:06 +03:00
Paul Sokolovsky
cf4b72bf13 examples: http_client.py, http_server.py aren't just unix, move to network/. 2016-04-01 20:53:23 +03:00