How to use the @comunica/bus-http.ActorHttp.toNodeReadable function in @comunica/bus-http

To help you get started, we’ve selected a few @comunica/bus-http examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github comunica / comunica / packages / actor-rdf-source-identifier-hypermedia-qpf / lib / ActorRdfSourceIdentifierHypermediaQpf.ts View on Github external
public async test(action: IActionRdfSourceIdentifier): Promise {
    const sourceUrl = this.getSourceUrl(action);
    const headers: Headers = new Headers();
    headers.append('Accept', this.acceptHeader);

    const httpAction: IActionHttp = { context: action.context, input: sourceUrl, init: { headers } };
    const httpResponse: IActorHttpOutput = await this.mediatorHttp.mediate(httpAction);
    if (httpResponse.ok) {
      const stream = ActorHttp.toNodeReadable(httpResponse.body);
      const body = (await require('stream-to-string')(stream));

      // Check if body contains all required things
      let valid = true;
      for (const line of this.toContain) {
        if (body.indexOf(line) < 0) {
          valid = false;
          break;
        }
      }
      if (valid) {
        return { priority: this.priority };
      }
    }

    // Avoid memory leaks
github comunica / comunica / packages / actor-init-http / lib / ActorInitHttp.ts View on Github external
http.init.method = this.method;
    }
    if (this.headers) {
      const headers: Headers = new Headers();
      for (const value of this.headers) {
        const i: number = value.indexOf(':');
        headers.append(value.substr(0, i).toLowerCase(), value.substr(i + 2));
      }
      http.init.headers = headers;
    }

    const httpResponse: IActorHttpOutput = await this.mediatorHttp.mediate(http);
    const output: IActorOutputInit = {};
    // Wrap WhatWG readable stream into a Node.js readable stream
    // If the body already is a Node.js stream (in the case of node-fetch), don't do explicit conversion.
    const responseStream: NodeJS.ReadableStream = ActorHttp.toNodeReadable(httpResponse.body);
    if (httpResponse.status === 200) {
      output.stdout = responseStream.pipe(new PassThrough());
    } else {
      output.stderr = responseStream.pipe(new PassThrough());
    }
    return output;
  }

@comunica/bus-http

A comunica bus for 'http' events.

MIT
Latest version published 2 months ago

Package Health Score

84 / 100
Full package analysis

Popular @comunica/bus-http functions