@@ -8,6 +8,7 @@ import { HttpTransportType, ITransport, TransferFormat } from "../src/ITransport
8
8
import { getUserAgentHeader } from "../src/Utils" ;
9
9
10
10
import { HttpError } from "../src/Errors" ;
11
+ import { ILogger , LogLevel } from "../src/ILogger" ;
11
12
import { NullLogger } from "../src/Loggers" ;
12
13
import { EventSourceConstructor , WebSocketConstructor } from "../src/Polyfills" ;
13
14
@@ -192,9 +193,9 @@ describe("HttpConnection", () => {
192
193
const connection = new HttpConnection ( "http://tempuri.org" , options ) ;
193
194
await expect ( connection . start ( TransferFormat . Text ) )
194
195
. rejects
195
- . toThrow ( "Unexpected status code returned from negotiate 999" ) ;
196
+ . toThrow ( "Unexpected status code returned from negotiate ' 999' " ) ;
196
197
} ,
197
- "Failed to start the connection: Error: Unexpected status code returned from negotiate 999" ) ;
198
+ "Failed to start the connection: Error: Unexpected status code returned from negotiate ' 999' " ) ;
198
199
} ) ;
199
200
200
201
it ( "all transport failure errors get aggregated" , async ( ) => {
@@ -1151,6 +1152,53 @@ describe("HttpConnection", () => {
1151
1152
} , "Failed to start the connection: Error: nope" ) ;
1152
1153
} ) ;
1153
1154
1155
+ it ( "logMessageContent displays correctly with binary data" , async ( ) => {
1156
+ await VerifyLogger . run ( async ( logger ) => {
1157
+ const availableTransport = { transport : "LongPolling" , transferFormats : [ "Text" , "Binary" ] } ;
1158
+
1159
+ let sentMessage = "" ;
1160
+ const captureLogger : ILogger = {
1161
+ log : ( logLevel : LogLevel , message : string ) => {
1162
+ if ( logLevel === LogLevel . Trace && message . search ( "data of length" ) > 0 ) {
1163
+ sentMessage = message ;
1164
+ }
1165
+
1166
+ logger . log ( logLevel , message ) ;
1167
+ } ,
1168
+ } ;
1169
+
1170
+ let httpClientGetCount = 0 ;
1171
+ const options : IHttpConnectionOptions = {
1172
+ ...commonOptions ,
1173
+ httpClient : new TestHttpClient ( )
1174
+ . on ( "POST" , ( ) => ( { connectionId : "42" , availableTransports : [ availableTransport ] } ) )
1175
+ . on ( "GET" , ( ) => {
1176
+ httpClientGetCount ++ ;
1177
+ if ( httpClientGetCount === 1 ) {
1178
+ // First long polling request must succeed so start completes
1179
+ return "" ;
1180
+ }
1181
+ return Promise . resolve ( ) ;
1182
+ } )
1183
+ . on ( "DELETE" , ( ) => new HttpResponse ( 202 ) ) ,
1184
+ logMessageContent : true ,
1185
+ logger : captureLogger ,
1186
+ transport : HttpTransportType . LongPolling ,
1187
+ } as IHttpConnectionOptions ;
1188
+
1189
+ const connection = new HttpConnection ( "http://tempuri.org" , options ) ;
1190
+ connection . onreceive = ( ) => null ;
1191
+ try {
1192
+ await connection . start ( TransferFormat . Binary ) ;
1193
+ await connection . send ( new Uint8Array ( [ 0x68 , 0x69 , 0x20 , 0x3a , 0x29 ] ) ) ;
1194
+ } finally {
1195
+ await connection . stop ( ) ;
1196
+ }
1197
+
1198
+ expect ( sentMessage ) . toBe ( "(LongPolling transport) sending data. Binary data of length 5. Content: '0x68 0x69 0x20 0x3a 0x29'." ) ;
1199
+ } ) ;
1200
+ } ) ;
1201
+
1154
1202
describe ( ".constructor" , ( ) => {
1155
1203
it ( "throws if no Url is provided" , async ( ) => {
1156
1204
// Force TypeScript to let us call the constructor incorrectly :)
@@ -1413,7 +1461,7 @@ describe("TransportSendQueue", () => {
1413
1461
1414
1462
const queue = new TransportSendQueue ( transport ) ;
1415
1463
1416
- const first = queue . send ( new Uint8Array ( [ 4 , 5 , 6 ] ) ) ;
1464
+ const first = queue . send ( new Uint8Array ( [ 4 , 5 , 6 ] ) . buffer ) ;
1417
1465
// This should allow first to enter transport.send
1418
1466
promiseSource1 . resolve ( ) ;
1419
1467
// Wait until we're inside transport.send
@@ -1428,8 +1476,8 @@ describe("TransportSendQueue", () => {
1428
1476
await Promise . all ( [ first , second , third ] ) ;
1429
1477
1430
1478
expect ( sendMock . mock . calls . length ) . toBe ( 2 ) ;
1431
- expect ( sendMock . mock . calls [ 0 ] [ 0 ] ) . toEqual ( new Uint8Array ( [ 4 , 5 , 6 ] ) ) ;
1432
- expect ( sendMock . mock . calls [ 1 ] [ 0 ] ) . toEqual ( new Uint8Array ( [ 7 , 8 , 10 , 12 , 14 ] ) ) ;
1479
+ expect ( sendMock . mock . calls [ 0 ] [ 0 ] ) . toEqual ( new Uint8Array ( [ 4 , 5 , 6 ] ) . buffer ) ;
1480
+ expect ( sendMock . mock . calls [ 1 ] [ 0 ] ) . toEqual ( new Uint8Array ( [ 7 , 8 , 10 , 12 , 14 ] ) . buffer ) ;
1433
1481
1434
1482
await queue . stop ( ) ;
1435
1483
} ) ;
0 commit comments