• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
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__ping_data.html" title="websocket::ping_data">
10<link rel="next" href="boost__beast__websocket__seed_prng.html" title="websocket::seed_prng">
11</head>
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>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="boost__beast__websocket__ping_data.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__seed_prng.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
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>
29<p>
30        <a class="indexterm" name="idm46057502375232"></a>
31      </p>
32<p>
33        Returns <code class="computeroutput"><span class="keyword">true</span></code> if the specified
34        HTTP request is a WebSocket Upgrade.
35      </p>
36<h5>
37<a name="beast.ref.boost__beast__websocket__is_upgrade.h0"></a>
38        <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      </h5>
40<p>
41        Defined in header <code class="literal">&lt;<a href="../../../../../../boost/beast/websocket/rfc6455.hpp" target="_top">boost/beast/websocket/rfc6455.hpp</a>&gt;</code>
42      </p>
43<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span>
44    <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">&gt;</span>
45<span class="keyword">bool</span>
46<span class="identifier">is_upgrade</span><span class="special">(</span>
47    <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">&lt;</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">&lt;</span> <span class="identifier">Allocator</span> <span class="special">&gt;&gt;</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">req</span><span class="special">);</span>
48</pre>
49<h5>
50<a name="beast.ref.boost__beast__websocket__is_upgrade.h1"></a>
51        <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      </h5>
53<p>
54        This function returns <code class="computeroutput"><span class="keyword">true</span></code> when
55        the passed HTTP Request indicates a WebSocket Upgrade. It does not validate
56        the contents of the fields: it just trivially accepts requests which could
57        only possibly be a valid or invalid WebSocket Upgrade message. Callers who
58        wish to manually read HTTP requests in their server implementation can use
59        this function to determine if the request should be routed to an instance
60        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      </p>
62<h5>
63<a name="beast.ref.boost__beast__websocket__is_upgrade.h2"></a>
64        <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>
65      </h5>
66<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">&amp;</span> <span class="identifier">sock</span><span class="special">)</span>
67<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">flat_buffer</span> <span class="identifier">buffer</span><span class="special">;</span>
69    <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">&lt;</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">&gt;</span> <span class="identifier">req</span><span class="special">;</span>
70    <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>
71    <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>
72    <span class="special">{</span>
73        <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">&lt;</span><span class="keyword">decltype</span><span class="special">(</span><span class="identifier">sock</span><span class="special">)&gt;</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>
74        <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>
75    <span class="special">}</span>
76<span class="special">}</span>
77</pre>
78<h5>
79<a name="beast.ref.boost__beast__websocket__is_upgrade.h3"></a>
80        <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>
81      </h5>
82<div class="informaltable"><table class="table">
83<colgroup>
84<col>
85<col>
86</colgroup>
87<thead><tr>
88<th>
89                <p>
90                  Name
91                </p>
92              </th>
93<th>
94                <p>
95                  Description
96                </p>
97              </th>
98</tr></thead>
99<tbody><tr>
100<td>
101                <p>
102                  <code class="computeroutput"><span class="identifier">req</span></code>
103                </p>
104              </td>
105<td>
106                <p>
107                  The HTTP Request object to check.
108                </p>
109              </td>
110</tr></tbody>
111</table></div>
112<h5>
113<a name="beast.ref.boost__beast__websocket__is_upgrade.h4"></a>
114        <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
115        Value</a>
116      </h5>
117<p>
118        <code class="computeroutput"><span class="keyword">true</span></code> if the request is a WebSocket
119        Upgrade.
120      </p>
121</div>
122<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
123<td align="left"></td>
124<td align="right"><div class="copyright-footer">Copyright © 2016-2019 Vinnie
125      Falco<p>
126        Distributed under the Boost Software License, Version 1.0. (See accompanying
127        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>)
128      </p>
129</div></td>
130</tr></table>
131<hr>
132<div class="spirit-nav">
133<a accesskey="p" href="boost__beast__websocket__ping_data.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__seed_prng.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
134</div>
135</body>
136</html>
137