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

Logger receives empty Request if https is used on http server. #1374

Closed
karlisolte opened this issue Aug 29, 2022 · 4 comments
Closed

Logger receives empty Request if https is used on http server. #1374

karlisolte opened this issue Aug 29, 2022 · 4 comments

Comments

@karlisolte
Copy link

karlisolte commented Aug 29, 2022

If I try to access http server with https protocol the logger registered with set_logger on server:

  • is invoked not once, but 12(!) times. (With #define CPPHTTPLIB_THREAD_POOL_COUNT 1 it seems to be 8 times.)
  • Parameter Request is empty (request.remote_addr and others are empty). I want to know who tired to access server and log it. Edit: I now understood why most fields are empty (like path as server never receives that information), but remote_addr should be possible to include?!

Also with this code:

    server.Get("/foo", [this](auto& request, auto& response) {
        LOG("handling request");
    });
    server.set_logger([this](auto& request, auto& response) {
        LOG("received request");
    });

The "handling request" gets logged before "received request". At least in my case that is not convenient.

@karlisolte
Copy link
Author

It was invoked several times because browser apparently did several requests. With curl it is invoked just once. The other 2 questions however remain.

@yhirose
Copy link
Owner

yhirose commented Aug 30, 2022

What does it mean Edit: I now understood why most fields are empty (like path as server never receives that information), but remote_addr should be possible to include?. Could you provide more detail?

@karlisolte
Copy link
Author

As per my understanding when client tries to access server using https it first tries to set up TLS and only then sends the actual HTTP request. If that fails server will never know what was client's requests hence it makes sense why HTTP related fields in Request are empty when logger callback gets invoked.

Server on the other hand should know what was remote_addr and remote_port that tried to set up TLS and failed and it would be useful to include this information in Request parameter if possible.

@yhirose
Copy link
Owner

yhirose commented Sep 4, 2022

Same as #870

@yhirose yhirose closed this as completed Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants