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

Parse Shoutcast ICY HTTP responses #1151

Closed
tli-invn opened this issue Jun 7, 2018 · 3 comments
Closed

Parse Shoutcast ICY HTTP responses #1151

tli-invn opened this issue Jun 7, 2018 · 3 comments

Comments

@tli-invn
Copy link

tli-invn commented Jun 7, 2018

I am currently using boost::beast to implement a ntrip 1.0 client. It has the request like:

GET /BUCU1 HTTP/1.0 User-Agent: NTRIP GNSSInternetRadio/1.2.0 Authorization: Basic aHVnb2JlbjpodWdvYmVuMTIz

And the response is like: ICY 200 OK

It has the non-standard http response.

I use the beast http client example code, it get this response in the buffer. But it generates a exception in the read function. The error is "Read, Bad version". I am wondering what is the best way to handle the non-standard http response.

void
    on_write(
        boost::system::error_code ec,
        std::size_t bytes_transferred)
{
    boost::ignore_unused(bytes_transferred);

    if (ec)
        return fail(ec, "write");


    // Receive the HTTP response
    // boost::beast::flat_buffer buffer_; // (Must persist between reads)
    // http::response <http::string_body> res_;

    http::async_read(socket_, buffer_, res_,
        std::bind(
            &session::on_read,
            shared_from_this(),
            std::placeholders::_1,
            std::placeholders::_2));
}

void
on_read(
boost::system::error_code ec,
std::size_t bytes_transferred)
{
boost::ignore_unused(bytes_transferred);

if (ec)
    return fail(ec, "read");         // ex

}

@vinniefalco
Copy link
Member

See: #595 (comment)

@vinniefalco vinniefalco changed the title Http client with customized response Parse Shoutcast ICY HTTP responses Jun 7, 2018
@vinniefalco
Copy link
Member

Let me spend a little time on this today and see what I can do

vinniefalco added a commit to vinniefalco/beast that referenced this issue Jun 10, 2018
fix boostorg#595, fix boostorg#1151

This provides a stream filter which converts the ICY HTTP
response handshake at the beginning of a stream to HTTP/1.1.
@vinniefalco
Copy link
Member

Please try the develop branch which has version 173. The class icy_stream may be used to wrap the socket and parse ICY responses:

boost::beast::icy_stream<boost::asio::ip::tcp::socket> stream(ioc);
...
boost::beast::http::response<boost::beast::http::string_body> res;
beast::http::read(stream, res);

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

No branches or pull requests

2 participants