3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>websocket::is_upgrade</title>
5 <link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../../index.html" title="Chapter 1. Boost.Beast">
8 <link rel="up" href="../ref.html" title="This Page Intentionally Left Blank 2/2">
9 <link rel="prev" href="boost__beast__websocket__frame_type.html" title="websocket::frame_type">
10 <link rel="next" href="boost__beast__websocket__permessage_deflate.html" title="websocket::permessage_deflate">
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../../more/index.htm">More</a></td>
22 <div class="spirit-nav">
23 <a accesskey="p" href="boost__beast__websocket__frame_type.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="boost__beast__websocket__permessage_deflate.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
26 <div class="titlepage"><div><div><h4 class="title">
27 <a name="beast.ref.boost__beast__websocket__is_upgrade"></a><a class="link" href="boost__beast__websocket__is_upgrade.html" title="websocket::is_upgrade">websocket::is_upgrade</a>
28 </h4></div></div></div>
30 <a class="indexterm" name="idm45873475082896"></a>
31 Returns <code class="computeroutput"><span class="keyword">true</span></code>
32 if the specified HTTP request is a WebSocket Upgrade.
35 <a name="beast.ref.boost__beast__websocket__is_upgrade.h0"></a>
36 <span class="phrase"><a name="beast.ref.boost__beast__websocket__is_upgrade.synopsis"></a></span><a class="link" href="boost__beast__websocket__is_upgrade.html#beast.ref.boost__beast__websocket__is_upgrade.synopsis">Synopsis</a>
39 Defined in header <code class="literal"><<a href="../../../../../../boost/beast/websocket/rfc6455.hpp" target="_top">boost/beast/websocket/rfc6455.hpp</a>></code>
41 <pre class="programlisting"><span class="keyword">template</span><span class="special"><</span>
42 <span class="keyword">class</span> <a href="https://en.cppreference.com/w/cpp/named_req/Allocator" target="_top"><span class="emphasis"><em>Allocator</em></span></a><span class="special">></span>
43 <span class="keyword">bool</span>
44 <span class="identifier">is_upgrade</span><span class="special">(</span>
45 <span class="identifier">beast</span><span class="special">::</span><span class="identifier">http</span><span class="special">::</span><span class="identifier">header</span><span class="special"><</span> <span class="keyword">true</span><span class="special">,</span> <span class="identifier">http</span><span class="special">::</span><span class="identifier">basic_fields</span><span class="special"><</span> <span class="identifier">Allocator</span> <span class="special">>></span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">req</span><span class="special">);</span>
48 <a name="beast.ref.boost__beast__websocket__is_upgrade.h1"></a>
49 <span class="phrase"><a name="beast.ref.boost__beast__websocket__is_upgrade.description"></a></span><a class="link" href="boost__beast__websocket__is_upgrade.html#beast.ref.boost__beast__websocket__is_upgrade.description">Description</a>
52 This function returns <code class="computeroutput"><span class="keyword">true</span></code> when
53 the passed HTTP Request indicates a WebSocket Upgrade. It does not validate
54 the contents of the fields: it just trivially accepts requests which could
55 only possibly be a valid or invalid WebSocket Upgrade message. Callers who
56 wish to manually read HTTP requests in their server implementation can use
57 this function to determine if the request should be routed to an instance
58 of <a class="link" href="boost__beast__websocket__stream.html" title="websocket::stream"><code class="computeroutput"><span class="identifier">websocket</span><span class="special">::</span><span class="identifier">stream</span></code></a>.
61 <a name="beast.ref.boost__beast__websocket__is_upgrade.h2"></a>
62 <span class="phrase"><a name="beast.ref.boost__beast__websocket__is_upgrade.example"></a></span><a class="link" href="boost__beast__websocket__is_upgrade.html#beast.ref.boost__beast__websocket__is_upgrade.example">Example</a>
64 <pre class="programlisting"><span class="keyword">void</span> <span class="identifier">handle_connection</span><span class="special">(</span><span class="identifier">net</span><span class="special">::</span><span class="identifier">ip</span><span class="special">::</span><span class="identifier">tcp</span><span class="special">::</span><span class="identifier">socket</span><span class="special">&</span> <span class="identifier">sock</span><span class="special">)</span>
65 <span class="special">{</span>
66 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">beast</span><span class="special">::</span><span class="identifier">flat_buffer</span> <span class="identifier">buffer</span><span class="special">;</span>
67 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">beast</span><span class="special">::</span><span class="identifier">http</span><span class="special">::</span><span class="identifier">request</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">beast</span><span class="special">::</span><span class="identifier">http</span><span class="special">::</span><span class="identifier">string_body</span><span class="special">></span> <span class="identifier">req</span><span class="special">;</span>
68 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">beast</span><span class="special">::</span><span class="identifier">http</span><span class="special">::</span><span class="identifier">read</span><span class="special">(</span><span class="identifier">sock</span><span class="special">,</span> <span class="identifier">buffer</span><span class="special">,</span> <span class="identifier">req</span><span class="special">);</span>
69 <span class="keyword">if</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">beast</span><span class="special">::</span><span class="identifier">websocket</span><span class="special">::</span><span class="identifier">is_upgrade</span><span class="special">(</span><span class="identifier">req</span><span class="special">))</span>
70 <span class="special">{</span>
71 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">beast</span><span class="special">::</span><span class="identifier">websocket</span><span class="special">::</span><span class="identifier">stream</span><span class="special"><</span><span class="keyword">decltype</span><span class="special">(</span><span class="identifier">sock</span><span class="special">)></span> <span class="identifier">ws</span><span class="special">{</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">sock</span><span class="special">)};</span>
72 <span class="identifier">ws</span><span class="special">.</span><span class="identifier">accept</span><span class="special">(</span><span class="identifier">req</span><span class="special">);</span>
73 <span class="special">}</span>
74 <span class="special">}</span>
77 <a name="beast.ref.boost__beast__websocket__is_upgrade.h3"></a>
78 <span class="phrase"><a name="beast.ref.boost__beast__websocket__is_upgrade.parameters"></a></span><a class="link" href="boost__beast__websocket__is_upgrade.html#beast.ref.boost__beast__websocket__is_upgrade.parameters">Parameters</a>
80 <div class="informaltable"><table class="table">
100 <code class="computeroutput"><span class="identifier">req</span></code>
105 The HTTP Request object to check.
111 <a name="beast.ref.boost__beast__websocket__is_upgrade.h4"></a>
112 <span class="phrase"><a name="beast.ref.boost__beast__websocket__is_upgrade.return_value"></a></span><a class="link" href="boost__beast__websocket__is_upgrade.html#beast.ref.boost__beast__websocket__is_upgrade.return_value">Return
116 <code class="computeroutput"><span class="keyword">true</span></code> if the request is a WebSocket
120 Convenience header <code class="literal"><<a href="../../../../../../boost/beast/websocket.hpp" target="_top">boost/beast/websocket.hpp</a>></code>
123 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
124 <td align="left"></td>
125 <td align="right"><div class="copyright-footer">Copyright © 2016-2019 Vinnie
127 Distributed under the Boost Software License, Version 1.0. (See accompanying
128 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
133 <div class="spirit-nav">
134 <a accesskey="p" href="boost__beast__websocket__frame_type.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="boost__beast__websocket__permessage_deflate.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>