@@ -28,7 +28,7 @@ import type { IToDeviceEvent } from "../sync-accumulator";
2828import { MatrixEvent } from "../models/event" ;
2929import { CryptoBackend , OnSyncCompletedData } from "../common-crypto/CryptoBackend" ;
3030import { logger } from "../logger" ;
31- import { IHttpOpts , IRequestOpts , MatrixHttpApi , Method } from "../http-api" ;
31+ import { IHttpOpts , MatrixHttpApi , Method } from "../http-api" ;
3232import { QueryDict } from "../utils" ;
3333
3434/**
@@ -54,7 +54,7 @@ export class RustCrypto implements CryptoBackend {
5454
5555 public constructor (
5656 private readonly olmMachine : RustSdkCryptoJs . OlmMachine ,
57- private readonly http : MatrixHttpApi < IHttpOpts > ,
57+ private readonly http : MatrixHttpApi < IHttpOpts & { onlyData : true } > ,
5858 _userId : string ,
5959 _deviceId : string ,
6060 ) { }
@@ -181,21 +181,21 @@ export class RustCrypto implements CryptoBackend {
181181 }
182182 }
183183
184- private async rawJsonRequest (
185- method : Method ,
186- path : string ,
187- queryParams : QueryDict ,
188- body : string ,
189- opts : IRequestOpts = { } ,
190- ) : Promise < string > {
191- // unbeknownst to HttpApi, we are sending JSON
192- if ( ! opts . headers ) opts . headers = { } ;
193- opts . headers [ "Content-Type" ] = "application/json" ;
194-
195- // we use the full prefix
196- if ( ! opts . prefix ) opts . prefix = "" ;
197-
198- const resp = await this . http . authedRequest ( method , path , queryParams , body , opts ) ;
199- return await resp . text ( ) ;
184+ private async rawJsonRequest ( method : Method , path : string , queryParams : QueryDict , body : string ) : Promise < string > {
185+ const opts = {
186+ // inhibit the JSON stringification and parsing within HttpApi.
187+ json : false ,
188+
189+ // nevertheless, we are sending, and accept, JSON.
190+ headers : {
191+ "Content-Type" : "application/json" ,
192+ "Accept" : "application/json" ,
193+ } ,
194+
195+ // we use the full prefix
196+ prefix : "" ,
197+ } ;
198+
199+ return await this . http . authedRequest < string > ( method , path , queryParams , body , opts ) ;
200200 }
201201}
0 commit comments