alexcrichton / curl-rust

Rust bindings to libcurl
MIT License
1k stars 234 forks source link

more easily get access to headers in Easy2 client #544

Open GlenDC opened 5 months ago

GlenDC commented 5 months ago

In the Easy struct there is a header_function (https://docs.rs/curl/0.4.44/curl/easy/struct.Easy.html#method.header_function) that allows one to get access to all headers. This option is however not available to Easy2.

Would it be possible to expose this somehow? as currently I need to use something very hacky. I use show_headers and parse it myself from the body... Which feels like a pretty wrong approach of having to do stuff and currently only works because I am focussing on a fairly easy HTTP/1.1 usage.

sagebind commented 5 months ago

When using Easy2, you are meant to access incoming response headers by implementing the header method on your Handler. Under the hood, Easy::header_function gets the header data using this mechanism (since Easy is implemented on top of Easy2).

Note that both of these methods are streaming -- you don't call them to get the headers, but rather libcurl calls you with the headers as they are received in real time.

GlenDC commented 5 months ago

Awesome, that’s exactly what I need. There are even some more functions in there that help me out. Thanks!!! Perfect.