170 lines
6.7 KiB
HTML
170 lines
6.7 KiB
HTML
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>
|
|
bindings/http/receiver_structured.js - Documentation
|
|
</title>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
|
|
<script>hljs.initHighlightingOnLoad();</script>
|
|
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
|
|
|
|
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
|
|
<link type="text/css" rel="stylesheet" href="styles/collapse.css">
|
|
|
|
|
|
|
|
</head>
|
|
|
|
<body>
|
|
<svg style="display: none;">
|
|
<defs>
|
|
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
|
|
<path d="M0 0h24v24H0z" fill="none"/>
|
|
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
|
|
</symbol>
|
|
</defs>
|
|
</svg>
|
|
|
|
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
<label for="nav-trigger" class="navicon-button x">
|
|
<div class="navicon"></div>
|
|
</label>
|
|
|
|
<label for="nav-trigger" class="overlay"></label>
|
|
|
|
<div class="top-nav-wrapper">
|
|
<ul>
|
|
<li >
|
|
<a href="index.html">
|
|
|
|
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
|
|
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
|
|
<path d="M0 0h24v24H0z" fill="none"/>
|
|
</svg>
|
|
|
|
|
|
</a>
|
|
</li>
|
|
|
|
|
|
|
|
</ul>
|
|
</div>
|
|
|
|
<nav>
|
|
<h3 class="reference-title">
|
|
cloudevents-sdk
|
|
</h3>
|
|
|
|
|
|
<h3>
|
|
Resources
|
|
</h3>
|
|
|
|
<a href="concepts.html">Concepts</a>
|
|
|
|
|
|
|
|
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="StructuredHTTPReceiver-nav"><a href="StructuredHTTPReceiver.html">StructuredHTTPReceiver</a><ul class='methods'><li data-type="method" id="StructuredHTTPReceiver-check-nav"><a href="StructuredHTTPReceiver.html#check">check</a></li><li data-type="method" id="StructuredHTTPReceiver-parse-nav"><a href="StructuredHTTPReceiver.html#parse">parse</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#headerMap">headerMap</a></li></ul>
|
|
</nav>
|
|
|
|
<div id="main">
|
|
|
|
<h1 class="page-title">
|
|
bindings/http/receiver_structured.js
|
|
</h1>
|
|
|
|
|
|
|
|
|
|
|
|
<section>
|
|
<article>
|
|
<pre class="prettyprint source linenums"><code>const ReceiverV1 = require("./v1/receiver_structured_1.js");
|
|
const ReceiverV3 = require("./v03/receiver_structured_0_3.js");
|
|
|
|
const { SPEC_V03, SPEC_V1 } = require("./constants.js");
|
|
const { check, parse } = require("./validation/structured.js");
|
|
|
|
/** @typedef {import("../../cloudevent")} CloudEvent */
|
|
|
|
/**
|
|
* A utility class used to receive structured CloudEvents
|
|
* over HTTP.
|
|
* @see {StructuredReceiver}
|
|
*/
|
|
class StructuredHTTPReceiver {
|
|
/**
|
|
* Creates a new StructuredHTTPReceiver. Supports Cloud Events specification
|
|
* versions 0.3 and 1.0 (default).
|
|
*
|
|
* @param {string} version the Cloud Events specification version. Default: 1.0.
|
|
*/
|
|
constructor(version = SPEC_V1) {
|
|
if (version === SPEC_V1) {
|
|
this.receiver = new ReceiverV1();
|
|
} else if (version === SPEC_V03) {
|
|
this.receiver = new ReceiverV3();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Checks whether the provided payload and headers conform to the Cloud Events
|
|
* specification version supported by this instance.
|
|
*
|
|
* @param {object} payload the cloud event data payload
|
|
* @param {object} headers the HTTP headers received for this cloud event
|
|
* @returns {boolean} true if the payload and header combination are valid
|
|
* @throws {ValidationError} if the payload and header combination do not conform to the spec
|
|
*/
|
|
check(payload, headers) {
|
|
return check(payload, headers, this.receiver);
|
|
}
|
|
|
|
/**
|
|
* Creates a new CloudEvent instance based on the provided payload and headers.
|
|
*
|
|
* @param {object} payload the cloud event data payload
|
|
* @param {object} headers the HTTP headers received for this cloud event
|
|
* @returns {CloudEvent} a new CloudEvent instance for the provided headers and payload
|
|
* @throws {ValidationError} if the payload and header combination do not conform to the spec
|
|
*/
|
|
parse(payload, headers) {
|
|
return parse(payload, headers, this.receiver);
|
|
}
|
|
}
|
|
|
|
module.exports = StructuredHTTPReceiver;
|
|
</code></pre>
|
|
</article>
|
|
</section>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<br class="clear">
|
|
|
|
<footer>
|
|
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.4</a>
|
|
</footer>
|
|
|
|
<script src="scripts/linenumber.js"></script>
|
|
<script src="scripts/pagelocation.js"></script>
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|