parent
622e133a8a
commit
b1010b7bd5
|
|
@ -223,27 +223,35 @@ describe("HttpConnection", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
eachTransport((requestedTransport: HttpTransportType) => {
|
eachTransport((requestedTransport: HttpTransportType) => {
|
||||||
// OPTIONS is not sent when WebSockets transport is explicitly requested
|
it(`cannot be started if requested ${HttpTransportType[requestedTransport]} transport not available on server`, async () => {
|
||||||
if (requestedTransport === HttpTransportType.WebSockets) {
|
const negotiateResponse = {
|
||||||
return;
|
availableTransports: [
|
||||||
}
|
{ transport: "WebSockets", transferFormats: [ "Text", "Binary" ] },
|
||||||
it(`cannot be started if requested ${HttpTransportType[requestedTransport]} transport not available on server`, async (done) => {
|
{ transport: "ServerSentEvents", transferFormats: [ "Text" ] },
|
||||||
|
{ transport: "LongPolling", transferFormats: [ "Text", "Binary" ] },
|
||||||
|
],
|
||||||
|
connectionId: "abc123",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Remove the requested transport from the response
|
||||||
|
negotiateResponse.availableTransports = negotiateResponse.availableTransports
|
||||||
|
.filter((f) => f.transport !== HttpTransportType[requestedTransport]);
|
||||||
|
|
||||||
const options: IHttpConnectionOptions = {
|
const options: IHttpConnectionOptions = {
|
||||||
...commonOptions,
|
...commonOptions,
|
||||||
httpClient: new TestHttpClient()
|
httpClient: new TestHttpClient()
|
||||||
.on("POST", (r) => ({ connectionId: "42", availableTransports: [] }))
|
.on("POST", (r) => negotiateResponse)
|
||||||
.on("GET", (r) => ""),
|
.on("GET", (r) => new HttpResponse(204)),
|
||||||
transport: requestedTransport,
|
transport: requestedTransport,
|
||||||
} as IHttpConnectionOptions;
|
} as IHttpConnectionOptions;
|
||||||
|
|
||||||
const connection = new HttpConnection("http://tempuri.org", options);
|
const connection = new HttpConnection("http://tempuri.org", options);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await connection.start(TransferFormat.Text);
|
await connection.start(TransferFormat.Text);
|
||||||
fail();
|
fail("Expected connection.start to throw!");
|
||||||
done();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
expect(e.message).toBe("Unable to initialize any of the available transports.");
|
expect(e.message).toBe("Unable to initialize any of the available transports.");
|
||||||
done();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,17 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
// This will be treated as a bit flag in the future, so we keep it using power-of-two values.
|
||||||
/** Specifies a specific HTTP transport type. */
|
/** Specifies a specific HTTP transport type. */
|
||||||
export enum HttpTransportType {
|
export enum HttpTransportType {
|
||||||
|
/** Specifies no transport preference. */
|
||||||
|
None = 0,
|
||||||
/** Specifies the WebSockets transport. */
|
/** Specifies the WebSockets transport. */
|
||||||
WebSockets,
|
WebSockets = 1,
|
||||||
/** Specifies the Server-Sent Events transport. */
|
/** Specifies the Server-Sent Events transport. */
|
||||||
ServerSentEvents,
|
ServerSentEvents = 2,
|
||||||
/** Specifies the Long Polling transport. */
|
/** Specifies the Long Polling transport. */
|
||||||
LongPolling,
|
LongPolling = 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Specifies the transfer format for a connection. */
|
/** Specifies the transfer format for a connection. */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue