Skip to content

Commit

Permalink
Merge pull request #474 from zazuko/sp-reenable-stream
Browse files Browse the repository at this point in the history
Add stream support back
  • Loading branch information
ludovicm67 authored Aug 22, 2024
2 parents adf284b + a257043 commit 49917a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-donkeys-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zazuko/trifid-plugin-sparql-proxy": patch
---

Enable stream support back
19 changes: 10 additions & 9 deletions packages/sparql-proxy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Readable } from 'node:stream'
import { performance } from 'node:perf_hooks'
import { Worker } from 'node:worker_threads'
import { sparqlGetRewriteConfiguration } from 'trifid-core'
// import replaceStream from 'string-replace-stream'
import replaceStream from 'string-replace-stream'
import rdf from '@zazuko/env-node'

const defaultConfiguration = {
Expand Down Expand Up @@ -250,16 +250,17 @@ const factory = async (trifid) => {

const contentType = response.headers.get('content-type')

let responseStream = await response.text() // response.body
/** @type {any} */
let responseStream = response.body
if (rewriteResponse && options.rewriteResults) {
responseStream = responseStream.replaceAll(rewriteResponse.origin, rewriteResponse.replacement)
// responseStream = Readable
// .from(responseStream)
// .pipe(replaceStream(
// rewriteResponse.origin,
// rewriteResponse.replacement,
// ))
responseStream = Readable
.from(responseStream)
.pipe(replaceStream(
rewriteResponse.origin,
rewriteResponse.replacement,
))
}
responseStream = Readable.fromWeb(responseStream)

reply
.status(response.status)
Expand Down

0 comments on commit 49917a2

Please sign in to comment.