fix #2171 by adding HttpTransportType.None (#2172)

This commit is contained in:
Andrew Stanton-Nurse 2018-05-02 14:34:23 -07:00 committed by GitHub
parent 622e133a8a
commit b1010b7bd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 13 deletions

View File

@ -223,27 +223,35 @@ describe("HttpConnection", () => {
});
eachTransport((requestedTransport: HttpTransportType) => {
// OPTIONS is not sent when WebSockets transport is explicitly requested
if (requestedTransport === HttpTransportType.WebSockets) {
return;
}
it(`cannot be started if requested ${HttpTransportType[requestedTransport]} transport not available on server`, async (done) => {
it(`cannot be started if requested ${HttpTransportType[requestedTransport]} transport not available on server`, async () => {
const negotiateResponse = {
availableTransports: [
{ transport: "WebSockets", transferFormats: [ "Text", "Binary" ] },
{ 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 = {
...commonOptions,
httpClient: new TestHttpClient()
.on("POST", (r) => ({ connectionId: "42", availableTransports: [] }))
.on("GET", (r) => ""),
.on("POST", (r) => negotiateResponse)
.on("GET", (r) => new HttpResponse(204)),
transport: requestedTransport,
} as IHttpConnectionOptions;
const connection = new HttpConnection("http://tempuri.org", options);
try {
await connection.start(TransferFormat.Text);
fail();
done();
fail("Expected connection.start to throw!");
} catch (e) {
expect(e.message).toBe("Unable to initialize any of the available transports.");
done();
}
});
});

View File

@ -1,14 +1,17 @@
// 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.
// 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. */
export enum HttpTransportType {
/** Specifies no transport preference. */
None = 0,
/** Specifies the WebSockets transport. */
WebSockets,
WebSockets = 1,
/** Specifies the Server-Sent Events transport. */
ServerSentEvents,
ServerSentEvents = 2,
/** Specifies the Long Polling transport. */
LongPolling,
LongPolling = 4,
}
/** Specifies the transfer format for a connection. */