Setting ContentType in the HTTP responses (#1149)
* Also making auth test work in IE
This commit is contained in:
parent
a862959566
commit
68aa609650
|
|
@ -484,8 +484,8 @@ describe('hubConnection', function () {
|
|||
var message = '你好,世界!';
|
||||
|
||||
var hubConnection;
|
||||
getJwtToken('http://' + document.location.host + '/generateJwtToken')
|
||||
.then(jwtToken => {
|
||||
getJwtToken('http://' + document.location.host + '/generateJwtToken', done,
|
||||
function(jwtToken) {
|
||||
var options = {
|
||||
transport: transportType,
|
||||
logging: signalR.LogLevel.Trace,
|
||||
|
|
@ -493,23 +493,24 @@ describe('hubConnection', function () {
|
|||
return jwtToken;
|
||||
}
|
||||
};
|
||||
|
||||
hubConnection = new signalR.HubConnection('/authorizedhub', options);
|
||||
hubConnection.onclose(function (error) {
|
||||
expect(error).toBe(undefined);
|
||||
done();
|
||||
});
|
||||
return hubConnection.start();
|
||||
})
|
||||
.then(function () {
|
||||
return hubConnection.invoke('Echo', message);
|
||||
})
|
||||
.then(function (response) {
|
||||
expect(response).toEqual(message);
|
||||
return hubConnection.stop();
|
||||
})
|
||||
.catch(function (e) {
|
||||
fail(e);
|
||||
done();
|
||||
hubConnection.start()
|
||||
.then(function() {
|
||||
return hubConnection.invoke('Echo', message);
|
||||
})
|
||||
.then(function(response) {
|
||||
expect(response).toEqual(message);
|
||||
return hubConnection.stop();
|
||||
})
|
||||
.catch(function(e) {
|
||||
fail(e);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -539,25 +540,25 @@ describe('hubConnection', function () {
|
|||
});
|
||||
});
|
||||
|
||||
function getJwtToken(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let xhr = new XMLHttpRequest();
|
||||
function getJwtToken(url, done, callback) {
|
||||
let xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open('GET', url, true);
|
||||
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
xhr.send();
|
||||
xhr.onload = () => {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
resolve(xhr.response || xhr.responseText);
|
||||
}
|
||||
else {
|
||||
reject(new Error(xhr.statusText));
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = () => {
|
||||
reject(new Error(xhr.statusText));
|
||||
xhr.open('GET', url, true);
|
||||
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
xhr.send();
|
||||
xhr.onload = function () {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
callback(xhr.response || xhr.responseText);
|
||||
}
|
||||
});
|
||||
else {
|
||||
fail();
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function() {
|
||||
fail();
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
}
|
||||
else
|
||||
{
|
||||
context.Response.ContentType = "text/plain";
|
||||
context.Response.StatusCode = StatusCodes.Status405MethodNotAllowed;
|
||||
}
|
||||
}
|
||||
|
|
@ -78,6 +79,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
}
|
||||
else
|
||||
{
|
||||
context.Response.ContentType = "text/plain";
|
||||
context.Response.StatusCode = StatusCodes.Status405MethodNotAllowed;
|
||||
}
|
||||
}
|
||||
|
|
@ -167,6 +169,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
|
||||
// The connection was disposed
|
||||
context.Response.StatusCode = StatusCodes.Status404NotFound;
|
||||
context.Response.ContentType = "plain/text";
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -414,6 +417,8 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
return;
|
||||
}
|
||||
|
||||
context.Response.ContentType = "text/plain";
|
||||
|
||||
var transport = (TransportType?)connection.Metadata[ConnectionMetadataNames.Transport];
|
||||
if (transport == TransportType.WebSockets)
|
||||
{
|
||||
|
|
@ -447,6 +452,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
{
|
||||
if ((supportedTransports & transportType) == 0)
|
||||
{
|
||||
context.Response.ContentType = "text/plain";
|
||||
context.Response.StatusCode = StatusCodes.Status404NotFound;
|
||||
_logger.TransportNotSupported(connection.ConnectionId, transportType);
|
||||
await context.Response.WriteAsync($"{transportType} transport not supported by this end point type");
|
||||
|
|
@ -461,6 +467,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
}
|
||||
else if (transport != transportType)
|
||||
{
|
||||
context.Response.ContentType = "text/plain";
|
||||
context.Response.StatusCode = StatusCodes.Status400BadRequest;
|
||||
_logger.CannotChangeTransport(connection.ConnectionId, transport.Value, transportType);
|
||||
await context.Response.WriteAsync("Cannot change transports mid-connection");
|
||||
|
|
@ -495,6 +502,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
{
|
||||
// There's no connection ID: bad request
|
||||
context.Response.StatusCode = StatusCodes.Status400BadRequest;
|
||||
context.Response.ContentType = "text/plain";
|
||||
await context.Response.WriteAsync("Connection ID required");
|
||||
return null;
|
||||
}
|
||||
|
|
@ -503,6 +511,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
{
|
||||
// No connection with that ID: Not Found
|
||||
context.Response.StatusCode = StatusCodes.Status404NotFound;
|
||||
context.Response.ContentType = "text/plain";
|
||||
await context.Response.WriteAsync("No Connection with that ID");
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,12 +35,11 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Transports
|
|||
{
|
||||
await _application.Completion;
|
||||
_logger.LongPolling204(_connectionId, context.TraceIdentifier);
|
||||
context.Response.ContentType = "text/plain";
|
||||
context.Response.StatusCode = StatusCodes.Status204NoContent;
|
||||
return;
|
||||
}
|
||||
|
||||
// REVIEW: What should the content type be?
|
||||
|
||||
var contentLength = 0;
|
||||
var buffers = new List<byte[]>();
|
||||
// We're intentionally not checking cancellation here because we need to drain messages we've got so far,
|
||||
|
|
@ -54,6 +53,7 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Transports
|
|||
}
|
||||
|
||||
context.Response.ContentLength = contentLength;
|
||||
context.Response.ContentType = "application/octet-stream";
|
||||
|
||||
foreach (var buffer in buffers)
|
||||
{
|
||||
|
|
@ -80,12 +80,14 @@ namespace Microsoft.AspNetCore.Sockets.Internal.Transports
|
|||
_logger.PollTimedOut(_connectionId, context.TraceIdentifier);
|
||||
|
||||
context.Response.ContentLength = 0;
|
||||
context.Response.ContentType = "text/plain";
|
||||
context.Response.StatusCode = StatusCodes.Status200OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Case 3
|
||||
_logger.LongPolling204(_connectionId, context.TraceIdentifier);
|
||||
context.Response.ContentType = "text/plain";
|
||||
context.Response.StatusCode = StatusCodes.Status204NoContent;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue