Skip to content

Commit

Permalink
fix(sparql-proxy): add stream support back
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovicm67 committed Aug 22, 2024
1 parent adf284b commit a257043
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 a257043

Please sign in to comment.