Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a http client implementation. #1388

Closed

Conversation

peterharperuk
Copy link
Contributor

Implemented using the lwip http client.

Fixes #1386

*/
void *http_client_init(const char *hostname, pico_http_header_cb client_header_cb, pico_http_body_cb client_body_cb, void *arg);

/*! \brief Initialise the http client to perform a https request
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment should probably explain something about what _secure means

@peterharperuk
Copy link
Contributor Author

Other comments,

1/ Passing the hostname in http_client_init means you can't reuse the same "state" to make a request to a different host. Seems a bit restrictive? The only reason I can think for this is that your tls config might be related to the host you're talking to. It's easy enough to allocate "state" for each host?

2/ Can't run multiple requests at the same time? You could do this by calling http_client_init multiple times for the number of requests you want to have running at the same time. The lwip api just allocates a new state for each request and frees this in the callback. We could do the same but it seems wasteful when you want to make multiple requests one after another (to the same host).

@kilograham
Copy link
Contributor

Other comments,

1/ Passing the hostname in http_client_init means you can't reuse the same "state" to make a request to a different host. Seems a bit restrictive? The only reason I can think for this is that your tls config might be related to the host you're talking to. It's easy enough to allocate "state" for each host?

2/ Can't run multiple requests at the same time? You could do this by calling http_client_init multiple times for the number of requests you want to have running at the same time. The lwip api just allocates a new state for each request and frees this in the callback. We could do the same but it seems wasteful when you want to make multiple requests one after another (to the same host).

Yeah, perhaps have a friendly API which combines the underlying "state" init, and the actual request, but expose the underlying methods too.

I guess I need to understand what the thing we are initializing is (it's life time) to know what it should be called (is it actually a client instance, a connection, etc.?)

@peterharperuk
Copy link
Contributor Author

peterharperuk commented Jan 8, 2024

I guess I need to understand what the thing we are initializing is (it's life time)

It looks like the lwip api is per http request - which is a bit naff. This was just supposed to be a "helper" utility to make the lwip functionality a bit easier to use (and hide the lwip dependency). Originally it was just part of the example code but I thought that was a bit lazy and should maybe add it to the sdk. Maybe I should forget that.

Implemented using the lwip http client.

Fixes raspberrypi#1386
@peterharperuk
Copy link
Contributor Author

I pushed a new version. To make an http request is something like this...

PICO_HTTP_REQUEST_T req = {0};
req.hostname = HOST;
req.url = URL;
req.recv_fn = response_function;
int rc = http_client_request_sync(cyw43_arch_async_context(), &req);

I'm not sure this is adding a lot of value, so I might just move it back to pico-examples. What do you think?

@peterharperuk peterharperuk self-assigned this Jan 12, 2024
@peterharperuk
Copy link
Contributor Author

This has been moved into a http client example to demonstrate how to use the lwip http client

@peterharperuk peterharperuk modified the milestones: 1.6.0, none May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants