public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status, bool validateHeaders = true, bool singleFieldHeaders = false) : base(version, validateHeaders, singleFieldHeaders) { Contract.Requires(status != null); this.status = status; }
public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status, HttpHeaders headers) : base(version, headers) { Contract.Requires(status != null); this.status = status; }
/// <inheritdoc /> protected override void SanitizeHeadersBeforeEncode(IHttpResponse msg, bool isAlwaysEmpty) { if (isAlwaysEmpty) { HttpResponseStatus status = msg.Status; if (status.CodeClass == HttpStatusClass.Informational || status.Code == StatusCodes.Status204NoContent) { // Stripping Content-Length: // See https://tools.ietf.org/html/rfc7230#section-3.3.2 _ = msg.Headers.Remove(HttpHeaderNames.ContentLength); // Stripping Transfer-Encoding: // See https://tools.ietf.org/html/rfc7230#section-3.3.1 _ = msg.Headers.Remove(HttpHeaderNames.TransferEncoding); } else if (status.Code == StatusCodes.Status205ResetContent) { // Stripping Transfer-Encoding: _ = msg.Headers.Remove(HttpHeaderNames.TransferEncoding); // Set Content-Length: 0 // https://httpstatuses.com/205 _ = msg.Headers.SetInt(HttpHeaderNames.ContentLength, 0); } } }
/// <inheritdoc /> protected override bool IsContentAlwaysEmpty(IHttpResponse msg) { // Correctly handle special cases as stated in: // https://tools.ietf.org/html/rfc7230#section-3.3.3 HttpResponseStatus status = msg.Status; if (status.CodeClass == HttpStatusClass.Informational) { if (status.Code == StatusCodes.Status101SwitchingProtocols) { // We need special handling for WebSockets version 00 as it will include an body. // Fortunally this version should not really be used in the wild very often. // See https://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-00#section-1.2 return(msg.Headers.Contains(HttpHeaderNames.SecWebsocketVersion)); } return(true); } switch (status.Code) { case StatusCodes.Status204NoContent: case StatusCodes.Status304NotModified: case StatusCodes.Status205ResetContent: return(true); default: return(false); } }
public IHttpResponse SetStatus(HttpResponseStatus value) { if (value is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); } this.status = value; return(this); }
public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status, IByteBuffer content, HttpHeaders headers, HttpHeaders trailingHeaders) : base(version, status, headers) { Contract.Requires(content != null); Contract.Requires(trailingHeaders != null); this.content = content; this.trailingHeaders = trailingHeaders; }
public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status, HttpHeaders headers) : base(version, headers) { if (status is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.status); } this.status = status; }
public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status, bool validateHeaders = true, bool singleFieldHeaders = false) : base(version, validateHeaders, singleFieldHeaders) { if (status is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.status); } this.status = status; }
public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status, IByteBuffer content, bool validateHeaders, bool singleFieldHeaders) : base(version, status, validateHeaders, singleFieldHeaders) { Contract.Requires(content != null); this.content = content; this.trailingHeaders = singleFieldHeaders ? new CombinedHttpHeaders(validateHeaders) : new DefaultHttpHeaders(validateHeaders); }
public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status, IByteBuffer content, bool validateHeaders, bool singleFieldHeaders) : base(version, status, validateHeaders, singleFieldHeaders) { if (content is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.content); } this.content = content; this.trailingHeaders = singleFieldHeaders ? new CombinedHttpHeaders(validateHeaders) : new DefaultHttpHeaders(validateHeaders); }
public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status, IByteBuffer content, HttpHeaders headers, HttpHeaders trailingHeaders) : base(version, status, headers) { if (content is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.content); } if (trailingHeaders is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.trailingHeaders); } this.content = content; this.trailingHeaders = trailingHeaders; }
protected override void SanitizeHeadersBeforeEncode(IHttpResponse msg, bool isAlwaysEmpty) { if (isAlwaysEmpty) { HttpResponseStatus status = msg.Status; if (status.CodeClass == HttpStatusClass.Informational || status.Code == HttpResponseStatus.NoContent.Code) { // Stripping Content-Length: // See https://tools.ietf.org/html/rfc7230#section-3.3.2 msg.Headers.Remove(HttpHeaderNames.ContentLength); // Stripping Transfer-Encoding: // See https://tools.ietf.org/html/rfc7230#section-3.3.1 msg.Headers.Remove(HttpHeaderNames.TransferEncoding); } } }
public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status) : this(version, status, Unpooled.Buffer(0)) { }
public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status, IByteBuffer content, bool validateHeaders) : this(version, status, content, validateHeaders, false) { }
protected sealed override IHttpMessage CreateMessage(AsciiString[] initialLine) => new DefaultHttpResponse( HttpVersion.ValueOf(initialLine[0]), HttpResponseStatus.ValueOf(initialLine[1].ParseInt(), initialLine[2]), this.ValidateHeaders);
public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status, bool validateHeaders, bool singleFieldHeaders) : this(version, status, ArrayPooled.Buffer(0), validateHeaders, singleFieldHeaders) { }
public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status, IByteBuffer content) : this(version, status, content, true, false) { }
public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status) : this(version, status, ArrayPooled.Buffer(0), true, false) { }
public IHttpResponse SetStatus(HttpResponseStatus value) { Contract.Requires(value != null); this.status = value; return(this); }
public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status, bool validateHeaders) : this(version, status, Unpooled.Buffer(0), validateHeaders, false) { }