/usr/share/doc/cockpit/guide/cockpit-http.html is in cockpit-doc 164-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>cockpit.js: HTTP Client</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Cockpit Guide">
<link rel="up" href="api-base1.html" title="API: base1">
<link rel="prev" href="cockpit-file.html" title="cockpit.js: File Access">
<link rel="next" href="cockpit-spawn.html" title="cockpit.js: Spawning Processes">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
<td><a accesskey="p" href="cockpit-file.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="api-base1.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">Cockpit Guide</th>
<td><a accesskey="n" href="cockpit-spawn.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry">
<a name="cockpit-http"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2>cockpit.js: HTTP Client</h2>
<p>cockpit.js: HTTP Client — HTTP and REST API communication</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<h2>Synopsis</h2>
<p>Cockpit allows access to local HTTP and REST services via this API.</p>
</div>
<div class="refsection">
<a name="cockpit-http-constructor"></a><h2>cockpit.http()</h2>
<pre class="programlisting">
http = cockpit.http(endpoint, [options])
http = cockpit.http(options)
</pre>
<p>Create a new HTTP client. The <code class="code">endpoint</code> can be a file path starting with
<code class="code">/</code> to connect to a unix socket, or it can be a port number to connect to.</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><code class="code">"address"</code></span></p></td>
<td><p>Connect to an address other than localhost. Must be a valid host name or IP address.
To use this option you also must provide a port number.</p></td>
</tr>
<tr>
<td><p><span class="term"><code class="code">"connection"</code></span></p></td>
<td><p>A connection identifier. Subsequent channel requests with the same
identifier will try to use the same connection if it is still open.</p></td>
</tr>
<tr>
<td><p><span class="term"><code class="code">"superuser"</code></span></p></td>
<td>
<p>Set to <code class="code">"require"</code> to open this channel as root. If the
currently logged in user is not permitted to become root (eg: via <code class="code">pkexec</code>)
then the <code class="code">channel</code> will immediately be
<a class="link" href="cockpit-channels.html#cockpit-channels-close-ev" title="channel.onclose">closed</a> with a <code class="code">"access-denied"</code>
problem code.</p>
<p>Set to <code class="code">"try"</code> to try to make the request as root, but if that fails,
fall back to perform an unprivileged request.</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsection">
<a name="cockpit-http-get"></a><h2>http.get()</h2>
<pre class="programlisting">
request = http.get(path, [params, [headers]])
</pre>
<p>Perform an HTTP GET request for the given <code class="code">path</code>. If the <code class="code">params</code>
is specified it should be a plain javascript object, which will be turned into a query string.</p>
<p>Optionally a plain javascript object containing headers can be included in the
<code class="code">headers</code> argument.</p>
<p>The return value is a
<a class="ulink" href="https://www.promisejs.org/" target="_top">promise</a>
that will complete if the request happens successfully, or fail if there's a problem.</p>
</div>
<div class="refsection">
<a name="cockpit-http-post"></a><h2>http.post()</h2>
<pre class="programlisting">
request = http.post(path, body, [headers])
</pre>
<p>Perform an HTTP POST request for the given <code class="code">path</code>. The <code class="code">body</code>
can be a string, or a javascript plain object, which will be encoded as JSON data. If
<code class="code">body</code> is <code class="code">undefined</code> or <code class="code">null</code> then an empty HTTP body
will be sent.</p>
<p>Optionally a plain javascript object containing headers can be included in the
<code class="code">headers</code> argument.</p>
<p>The return value is a
<a class="ulink" href="https://www.promisejs.org/" target="_top">promise</a>
that will complete if the request happens successfully, or fail if there's a problem.</p>
</div>
<div class="refsection">
<a name="cockpit-http-request"></a><h2>http.request()</h2>
<pre class="programlisting">
request = http.request(options)
</pre>
<p>Perform an HTTP request. The <code class="code">options</code> can contain the following:</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><code class="code">"body"</code></span></p></td>
<td><p>The HTTP request body. If you do not specify a body, then you must
call <a class="link" href="cockpit-http.html#cockpit-http-input" title="request.input()">request.input()</a> to complete the body
and allow the request to start.</p></td>
</tr>
<tr>
<td><p><span class="term"><code class="code">"headers"</code></span></p></td>
<td><p>A javascript plain object containing HTTP headers.</p></td>
</tr>
<tr>
<td><p><span class="term"><code class="code">"method"</code></span></p></td>
<td><p>The HTTP method. Defaults to <code class="code">"GET"</code>.</p></td>
</tr>
<tr>
<td><p><span class="term"><code class="code">"params"</code></span></p></td>
<td><p>A javascript plain object containing query string parameters.</p></td>
</tr>
<tr>
<td><p><span class="term"><code class="code">"path"</code></span></p></td>
<td><p>The HTTP path. Defaults to <code class="code">/</code>.</p></td>
</tr>
</tbody>
</table></div>
<p>The return value is a
<a class="ulink" href="https://www.promisejs.org/" target="_top">promise</a>
that will complete if the request happens successfully, or fail if there's a problem.</p>
</div>
<div class="refsection">
<a name="cockpit-http-done"></a><h2>request.done()</h2>
<pre class="programlisting">
request.done(function(data) { ... })
</pre>
<p>This is a standard
<a class="ulink" href="https://www.promisejs.org/" target="_top">promise</a>
method. It sets up a handler to be called when the request finishes successfully.</p>
<p>The <code class="code">data</code> argument contains the body result of the request.
If it a string, unless the process was opened in binary mode, in which case the
<code class="code">data</code> is an array of bytes. If a
<code class="code"><a class="link" href="cockpit-http.html#cockpit-http-stream" title="request.stream()">request.stream()</a></code>
handler is set up, then any standard output data consumed by the handler will not
be included in the <code class="code">data</code> argument.</p>
</div>
<div class="refsection">
<a name="cockpit-http-fail"></a><h2>request.fail()</h2>
<pre class="programlisting">
request.fail(function(exception[, data]) { ... })
</pre>
<p>This is a standard
<a class="ulink" href="http://api.jquery.com/category/deferred-object/" target="_top">jQuery promise</a> method.
It sets up a handler to be called when the request fails, or returns an error code.</p>
<p>The <code class="code">exception</code> object passed to the handler can have the
following fields:</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><code class="code">problem</code></span></p></td>
<td><p>A <a class="link" href="cockpit-error.html#cockpit-problems" title="Problem Codes">problem code</a> string when
a problem occurred starting or communicating with the server. This is <code class="code">null</code>
if the process exited or was terminated.</p></td>
</tr>
<tr>
<td><p><span class="term"><code class="code">status</code></span></p></td>
<td><p>The numeric status of the response. This is <code class="code">null</code> if
no response was received.</p></td>
</tr>
<tr>
<td><p><span class="term"><code class="code">reason</code></span></p></td>
<td><p>A string reason returned in the response. This is <code class="code">null</code> if
no response was received.</p></td>
</tr>
<tr>
<td><p><span class="term"><code class="code">message</code></span></p></td>
<td><p>A string message returned in the response. This is <code class="code">null</code> if
no response was received.</p></td>
</tr>
</tbody>
</table></div>
<p>If the request returned a response body, it will be available in
the <code class="code">data</code> argument. Otherwise this argument will be <code class="code">undefined</code>.</p>
</div>
<div class="refsection">
<a name="cockpit-http-always"></a><h2>request.always()</h2>
<pre class="programlisting">
request.always(function() { ... })
</pre>
<p>This is a standard
<a class="ulink" href="http://api.jquery.com/category/deferred-object/" target="_top">jQuery promise</a> method.
It sets up a handler to be called when the process completes, whether it exits successfully,
fails, terminates, or exits with a failure.</p>
</div>
<div class="refsection">
<a name="cockpit-http-response"></a><h2>request.response()</h2>
<pre class="programlisting">
request.response(function(status, headers) { ... })
</pre>
<p>This sets up a handler to be called when the HTTP request gets the initial response
from the server. The <code class="code">status</code> argument is the HTTP status integer, and the
<code class="code">headers</code> is a plain javascript object containing the headers of the
response.</p>
</div>
<div class="refsection">
<a name="cockpit-http-stream"></a><h2>request.stream()</h2>
<pre class="programlisting">
request.stream(function(data) { ... })
</pre>
<p>This sets up a handler to be called when the request returns output data. The
handler will be called multiple times.</p>
<p>Only one handler may be registered at a time. Registering an additional handler
replaces the previous one. The handler receives either string <code class="code">data</code> or
an array of binary bytes as its argument. A stream handler may return a number, which
indicates the number of characters or bytes consumed from <code class="code">data</code>. Any data
not consumed will be included again the next time the handler is called.</p>
<p>If a <code class="code">request.stream()</code> handler is set up, then the
<code class="code"><a class="link" href="cockpit-http.html#cockpit-http-done" title="request.done()">request.done()</a></code> handlers will
only get any remaining data not consumed by the stream handler.</p>
</div>
<div class="refsection">
<a name="cockpit-http-input"></a><h2>request.input()</h2>
<pre class="programlisting">
request.input(data, [stream])
</pre>
<p>This method writes <code class="code">data</code> to the HTTP request body. It is only valid
if no <code class="code">"body"</code> has been specified in
<a class="link" href="cockpit-http.html#cockpit-http-request" title="http.request()">http.request()</a> options. If <code class="code">stream</code>
is <code class="code">true</code> then this function can be called again to provide further data.</p>
</div>
<div class="refsection">
<a name="cockpit-http-close"></a><h2>request.close()</h2>
<pre class="programlisting">
request.close([problem])
</pre>
<p>Cancel the request. If <code class="code">problem</code> is specified it should be a
standard <a class="link" href="cockpit-error.html#cockpit-problems" title="Problem Codes">problem code</a> string.</p>
</div>
<div class="refsection">
<a name="cockpit-http-close-all"></a><h2>http.close()</h2>
<pre class="programlisting">
http.close([problem])
</pre>
<p>Cancel all outstanding requests with the given problem code. This is useful when
you know that the server is going down soon.
</p>
</div>
</div>
<div class="footer"><hr></div>
</body>
</html>
|