0

I am having some trouble understanding the cpp netlib documentation.

member name  type               description
headers      vector<header>     Vector of headers.

A header is a struct of type response_header<http::tags::http_server>. 
An instance always has the members name and value both of which are of type string_type.
string_type is boost::network::string<http::tags::http_server>::type.

In my code when I try to access the headers:

http_server::response_header headers[] = request.headers;

the above doesn't compile. I understand this might seem pretty basic, but I am new to c++. Can anyone guide me on how to iterate through the headers from request?

2 Answers 2

1
class handler;
typedef http::async_server<handler> server;
for (server::request::vector_type::iterator it = request.headers.begin(); it != request.headers.end(); ++it) {
    printf("%s: %s", it->name.c_str(), it->value.c_str());
}
Sign up to request clarification or add additional context in comments.

1 Comment

Why did you use printf?:)
0

I figured out the solution, for the sake of anyone else googling this. It seems that the documentation is wrong. Request_header should be used when parsing a request not response header

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.