Skip to content

How to perform as an HTTP client using libhttp? #74

@HsuJv

Description

@HsuJv

Hi dear @lammertb ,

I'm trying to embed the libhttp in my own projects to act as both the server & client.

But actually, I encountered some challenges when trying to connect to an HTTPS server using libhttp.

  1. At first I only had an instance of struct lh_ctx_t to set up the server, which I then passed to httplib_connect_client. Everything went well, except that it crashed when I tried to call httplib_stop (src/httplib_free_context.c:100). It was trying to clean up SSL_CTX, which was overwritten by another context when it acted as an HTTPS client.
  2. Then I literally realized that I should call httplib_create_client_context to generate another instance of struct lh_ctx_t for each client connection. But this time it crashes again in httplib_close_connection (src/httplib_close_connection.c:124) because there is no place to initialize client_ctx->workerthreadids. Also, client_ctx is always in the CTX_STATUS_TERMINATED status after creation and cannot be CTX_STATUS_RUNNING, which prevents me from sending Hello to other servers.

Could you please give me some advice?

Thanks in advance.

Regards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions