use base64 for HTTP headers (#1795)

* use base64 for HTTP headers

* fe for base64 headers

Co-authored-by: Matt Hill <matthewonthemoon@gmail.com>
This commit is contained in:
Aiden McClelland
2022-09-12 13:20:49 -06:00
committed by GitHub
parent 5564154da2
commit 36911d7ed6
5 changed files with 22 additions and 15 deletions

View File

@@ -18,6 +18,7 @@ import { AuthService } from '../auth.service'
import { DOCUMENT } from '@angular/common'
import { DataModel } from '../patch-db/data-model'
import { PatchDB, Update } from 'patch-db-client'
import * as Base64 from 'base64-js'
@Injectable()
export class LiveApiService extends ApiService {
@@ -415,15 +416,22 @@ export class LiveApiService extends ApiService {
}
const res = await this.http.rpcRequest<T>(options)
const encoded = res.headers.get('x-patch-updates')
const encodedUpdates = res.headers.get('x-patch-updates')
const encodedError = res.headers.get('x-patch-error')
if (encoded) {
const updates: Update<DataModel>[] = JSON.parse(
decodeURIComponent(encoded),
if (encodedUpdates) {
const decoded = new TextDecoder().decode(
Base64.toByteArray(encodedUpdates),
)
const updates: Update<DataModel>[] = JSON.parse(decoded)
this.patchStream$.next(updates)
}
if (encodedError) {
const error = new TextDecoder().decode(Base64.toByteArray(encodedError))
console.error(error)
}
const rpcRes = res.body
if (isRpcError(rpcRes)) {