/// <summary>
        /// Create a <see cref="HttpMessageException"/> based on the http status.
        /// </summary>
        /// <param name="status">The status code which throws the warning</param>
        /// <param name="response">The original response, in Json</param>
        /// <param name="addition">The addition to the message. </param>
        /// <returns>a throwable <see cref="HttpMessageException"/></returns>
        public static HttpMessageException Build(HttpStatusCode status, HttpMessageType type, string response, string responseLocation, string addition = "")
        {
            string statusMessage;

            switch (status)
            {
            case HttpStatusCode.Ambiguous:
                statusMessage = string.Format(WarningMessages.Ambiguous, responseLocation, addition);
                break;

            case HttpStatusCode.NoContent:
                statusMessage = string.Format(WarningMessages.NoContent, responseLocation, addition);
                break;

            case HttpStatusCode.NotFound:
                statusMessage = string.Format(WarningMessages.NotFound, responseLocation, addition);
                break;

            case HttpStatusCode.Accepted:
                statusMessage = string.Format(WarningMessages.Accepted, responseLocation, addition);
                break;

            case HttpStatusCode.Conflict:
                statusMessage = string.Format(WarningMessages.Conflict, responseLocation, addition);
                break;

            default:
                statusMessage = string.Format(WarningMessages.Generic, responseLocation, addition);
                break;
            }

            var message = BuildResponseString(type, statusMessage, response);

            return(new HttpMessageException(status, message, statusMessage));
        }
        private static HttpMessage BuildResponseString(HttpMessageType type, string msg, string response)
        {
            var typeString = type.ToString();
            var message    = msg;
            var body       = response;


            return(new HttpMessage {
                Body = body, Message = message, Type = typeString
            });
        }
Beispiel #3
0
        private HttpStatusLine ParseRequestStatusLine(string[] sections)
        {
            HttpStatusLine statusLine = new HttpRequestStatusLine
            {
                Method  = sections[0],
                Uri     = sections[1],
                Version = sections[2]
            };

            _type = HttpMessageType.Request;
            return(statusLine);
        }
Beispiel #4
0
        public static void AddRequestBody <T>(this IRestRequest restRequest, HttpMessageType httpMessageType, T obj)
        {
            switch (httpMessageType)
            {
            case HttpMessageType.MSGPACK:
                restRequest.AddParameter(string.Empty, obj.SerializeMsgPack(),
                                         JobConstant.Msgpack_ContentType, ParameterType.RequestBody);
                break;

            case HttpMessageType.JSON:
                restRequest.AddParameter(string.Empty, obj.SerializeSnakeCaseObject(),
                                         JobConstant.Json_ContentType, ParameterType.RequestBody);
                break;
            }
        }
Beispiel #5
0
        private HttpStatusLine ParseResponseStatusLine(string[] sections)
        {
            HttpStatusLine statusLine = null;

            if (sections[0].StartsWith("http", System.StringComparison.InvariantCultureIgnoreCase))
            {
                string version       = sections[0];
                int    statusCode    = 0;
                string statusMessage = sections[2];

                if (int.TryParse(sections[1], out statusCode))
                {
                    statusLine = new HttpResponseStatusLine()
                    {
                        Version       = sections[0],
                        StatusCode    = statusCode,
                        StatusMessage = sections[2]
                    };
                    _type = HttpMessageType.Response;
                }
            }
            return(statusLine);
        }
Beispiel #6
0
 public HttpMessageStartLine(HttpMessageType type, Memory <char> rawContent, Memory <char> protocolVersion)
 {
     Type            = type;
     RawContent      = rawContent;
     ProtocolVersion = protocolVersion;
 }
Beispiel #7
0
 public HttpResponseStartLine(HttpMessageType type, Memory <char> rawContent, Memory <char> protocolVersion, Memory <char> code, Memory <char> content)
     : base(type, rawContent, protocolVersion)
 {
     Code    = code;
     Content = content;
 }
 public static Exception Build(HttpStatusCode oK, HttpMessageType info, object p)
 {
     throw new NotImplementedException();
 }
 public HttpRequestStartLine(HttpMessageType type, Memory <char> rawContent, Memory <char> protocolVersion, Memory <char> method, Memory <char> addressee)
     : base(type, rawContent, protocolVersion)
 {
     Addressee = addressee;
     Method    = method;
 }