mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
http2_request_example: Change the target http2 server to http2.github.io
and
perform only a `GET` request.
This commit is contained in:
parent
ab118fe8be
commit
b4fbd87f42
@ -1,8 +1,7 @@
|
||||
# HTTP/2 Request Example
|
||||
|
||||
Established HTTP/2 connection with https://http2.golang.org
|
||||
- Performs a GET on /clockstream
|
||||
- Performs a PUT on /ECHO
|
||||
Establish an HTTP/2 connection with https://http2.github.io
|
||||
- Performs a GET on /index.html
|
||||
|
||||
## How to use example
|
||||
Before project configuration and build, be sure to set the correct chip target using `idf.py set-target <chip_name>`.
|
||||
@ -36,37 +35,21 @@ See the Getting Started Guide for full steps to configure and use ESP-IDF to bui
|
||||
## Example Output
|
||||
|
||||
```
|
||||
I (9637) example_connect: - IPv4 address: 192.168.194.219
|
||||
I (9637) example_connect: - IPv6 address: fe80:0000:0000:0000:266f:28ff:fe80:2c74, type: ESP_IP6_ADDR_IS_LINK_LOCAL
|
||||
I (5609) example_connect: - IPv4 address: 192.168.0.103
|
||||
I (5609) example_connect: - IPv6 address: fe80:0000:0000:0000:ae67:b2ff:fe45:0194, type: ESP_IP6_ADDR_IS_LINK_LOCAL
|
||||
Connecting to server
|
||||
Connection done
|
||||
[data-prvd] Sending 11 bytes
|
||||
[echo-response] HELLO WORLD
|
||||
[echo-response] Frame fully received
|
||||
[echo-response] Frame fully received
|
||||
[echo-response] Stream Closed
|
||||
[get-response] # ~1KB of junk to force browsers to start rendering immediately:
|
||||
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
2021-09-07 08:22:10.73175944 +0000 UTC m=+530259.401042400
|
||||
|
||||
[get-response] <!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
.
|
||||
.
|
||||
.
|
||||
Body of index.html
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
</html>
|
||||
[get-response] Frame fully received
|
||||
[get-response] 2021-09-07 08:22:11.73205314 +0000 UTC m=+530260.401336111
|
||||
|
||||
[get-response] Frame fully received
|
||||
[get-response] 2021-09-07 08:22:12.7320106 +0000 UTC m=+530261.401293569
|
||||
|
||||
[get-response] Frame fully received
|
||||
[get-response] 2021-09-07 08:22:13.732013218 +0000 UTC m=+530262.401296183
|
||||
[get-response] Stream Closed
|
||||
```
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import http.client
|
||||
@ -11,7 +11,7 @@ import ttfw_idf
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
HTTP_OK = 200
|
||||
TEST_SERVER = 'http2.golang.org'
|
||||
TEST_SERVER = 'http2.github.io'
|
||||
|
||||
|
||||
def is_test_server_available(): # type: () -> bool
|
||||
@ -33,7 +33,7 @@ def test_examples_protocol_http2_request(env, extra_data): # type: (tiny_test_f
|
||||
"""
|
||||
steps: |
|
||||
1. join AP
|
||||
2. connect to http2.golang.org
|
||||
2. connect to http2.github.io
|
||||
3. send http2 request
|
||||
4. send http2 put response
|
||||
"""
|
||||
@ -45,15 +45,12 @@ def test_examples_protocol_http2_request(env, extra_data): # type: (tiny_test_f
|
||||
# start the test
|
||||
# check if test server is avilable
|
||||
test_server_available = is_test_server_available()
|
||||
# Skip the test if the server test server (http2.golang.org) is not available at the moment.
|
||||
# Skip the test if the server test server (http2.github.io) is not available at the moment.
|
||||
if test_server_available:
|
||||
Utility.console_log('test server \"{}\" is available'.format(TEST_SERVER))
|
||||
dut1.start_app()
|
||||
# check for connection
|
||||
dut1.expect('Connection done', timeout=30)
|
||||
# check for echo response
|
||||
dut1.expect('[echo-response] HELLO WORLD', timeout=30)
|
||||
dut1.expect('[echo-response] Frame fully received')
|
||||
dut1.expect('[echo-response] Stream Closed')
|
||||
# check for get response
|
||||
dut1.expect('[get-response] Frame fully received')
|
||||
else:
|
||||
|
@ -1,3 +1,3 @@
|
||||
idf_component_register(SRCS "http2_request_example_main.c"
|
||||
INCLUDE_DIRS "."
|
||||
EMBED_TXTFILES "golang_root_cert.pem")
|
||||
EMBED_TXTFILES "http2_github_io_root_cert.pem")
|
||||
|
@ -2,4 +2,4 @@
|
||||
# "main" pseudo-component makefile.
|
||||
#
|
||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
||||
COMPONENT_EMBED_TXTFILES := golang_root_cert.pem
|
||||
COMPONENT_EMBED_TXTFILES := http2_github_io_root_cert.pem
|
||||
|
@ -1,31 +0,0 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
||||
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
||||
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
||||
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
||||
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
|
||||
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
|
||||
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
|
||||
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
|
||||
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
|
||||
T8KOEUt+zwvo/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AV0Ae
|
||||
cPUeybQ=
|
||||
-----END CERTIFICATE-----
|
@ -1,6 +1,6 @@
|
||||
/* HTTP2 GET Example using nghttp2
|
||||
|
||||
Contacts http2.golang.org and executes the GET/PUT requests. A thin API
|
||||
Contacts http2.github.io and executes the GET request. A thin API
|
||||
wrapper on top of nghttp2, to properly demonstrate the interactions.
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
@ -26,15 +26,13 @@
|
||||
#include "sh2lib.h"
|
||||
|
||||
|
||||
extern const uint8_t server_root_cert_pem_start[] asm("_binary_golang_root_cert_pem_start");
|
||||
extern const uint8_t server_root_cert_pem_end[] asm("_binary_golang_root_cert_pem_end");
|
||||
extern const uint8_t server_root_cert_pem_start[] asm("_binary_http2_github_io_root_cert_pem_start");
|
||||
extern const uint8_t server_root_cert_pem_end[] asm("_binary_http2_github_io_root_cert_pem_end");
|
||||
|
||||
/* The HTTP/2 server to connect to */
|
||||
#define HTTP2_SERVER_URI "https://http2.golang.org"
|
||||
#define HTTP2_SERVER_URI "https://http2.github.io"
|
||||
/* A GET request that keeps streaming current time every second */
|
||||
#define HTTP2_STREAMING_GET_PATH "/clockstream"
|
||||
/* A PUT request that echoes whatever we had sent to it */
|
||||
#define HTTP2_PUT_PATH "/ECHO"
|
||||
#define HTTP2_STREAMING_GET_PATH "/index.html"
|
||||
|
||||
|
||||
int handle_get_response(struct sh2lib_handle *handle, const char *data, size_t len, int flags)
|
||||
@ -120,10 +118,6 @@ static void http2_task(void *args)
|
||||
|
||||
/* HTTP GET */
|
||||
sh2lib_do_get(&hd, HTTP2_STREAMING_GET_PATH, handle_get_response);
|
||||
|
||||
/* HTTP PUT */
|
||||
sh2lib_do_put(&hd, HTTP2_PUT_PATH, send_put_data, handle_echo_response);
|
||||
|
||||
while (1) {
|
||||
/* Process HTTP2 send/receive */
|
||||
if (sh2lib_execute(&hd) < 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user