// 32feet.NET - Personal Area Networking for .NET // // InTheHand.Net.ObexWebResponse // // Copyright (c) 2003-2020 In The Hand Ltd, All rights reserved. // This source code is licensed under the MIT License using System.Net; using System.IO; using System.Diagnostics.CodeAnalysis; namespace InTheHand.Net { /// /// Provides an OBEX implementation of the class. /// [SuppressMessage("Microsoft.Usage", "CA2237:MarkISerializableTypesWithSerializable", Justification = "Are we!?!")] public class ObexWebResponse : WebResponse { private MemoryStream responseStream; internal ObexWebResponse(MemoryStream stream, WebHeaderCollection headers, ObexStatusCode code) { responseStream = stream; Headers = headers; StatusCode = code; } /// /// Gets the headers associated with this response from the server. /// public override WebHeaderCollection Headers { get; } /// /// Gets the length of the content returned by the request. /// public override long ContentLength { get { string len = Headers["LENGTH"]; if (len != null && len != string.Empty) { return long.Parse(len); } return 0; } set { } } /// /// Gets the content type of the response. /// public override string ContentType { get { return Headers["TYPE"]; } set { } } /// /// Returns a status code to indicate the outcome of the request. /// /// - /// Note, if a error occurs locally then the status code /// is returned. /// Therefore that error code could signal local or remote errors. /// /// public ObexStatusCode StatusCode { get; } /// /// Gets the stream used to read the body of the response from the server. /// /// - /// A containing the body of the response. public override Stream GetResponseStream() { return responseStream; } /// /// Frees the resources held by the response. /// public override void Close() { if (responseStream != null) { responseStream.Close(); responseStream = null; } } } }