You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6 KiB

4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
  1. using Apewer.Web;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Net;
  5. using System.Text;
  6. namespace Apewer.AspNetBridge
  7. {
  8. /// <summary></summary>
  9. public class HttpResponseMessage
  10. {
  11. /// <summary></summary>
  12. public HttpContent Content { get; set; }
  13. /// <summary></summary>
  14. public HttpStatusCode StatusCode { get; set; }
  15. /// <exception cref="ArgumentOutOfRangeException"></exception>
  16. public HttpResponseMessage(HttpStatusCode statusCode = HttpStatusCode.OK)
  17. {
  18. var code = (int)StatusCode;
  19. if (code < 0 || code > 999) throw new ArgumentOutOfRangeException("statusCode");
  20. StatusCode = statusCode;
  21. }
  22. /// <summary></summary>
  23. public override string ToString() => "";
  24. /// <summary></summary>
  25. internal ApiModel ToModel()
  26. {
  27. var hrm = this;
  28. if (hrm == null) return new ApiStatusModel(204);
  29. if (hrm.Content == null) return new ApiStatusModel(204);
  30. var stream = hrm.Content.Stream;
  31. if (stream == null) return new ApiStatusModel(204);
  32. var model = new ApiStreamModel(stream);
  33. model.Status = (int)hrm.StatusCode;
  34. if (hrm.Content.Headers != null)
  35. {
  36. if (hrm.Content.Headers.ContentType != null) model.ContentType = hrm.Content.Headers.ContentType.MediaType;
  37. if (hrm.Content.Headers.ContentDisposition != null) model.Attachment = hrm.Content.Headers.ContentDisposition.FileName;
  38. }
  39. return model;
  40. }
  41. }
  42. }