コード例 #1
0
        public static void SetStatus(IHeaderDictionary destination, Status status)
        {
            // Overwrite any previously set status
            destination[GrpcProtocolConstants.StatusTrailer] = status.StatusCode.ToTrailerString();

            string escapedDetail;
            if (!string.IsNullOrEmpty(status.Detail))
            {
                // https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#responses
                // The value portion of Status-Message is conceptually a Unicode string description of the error,
                // physically encoded as UTF-8 followed by percent-encoding.
                escapedDetail = PercentEncodingHelpers.PercentEncode(status.Detail);
            }
			else
			{
			    escapedDetail = null;
			}

            destination[GrpcProtocolConstants.MessageTrailer] = escapedDetail;
        }
コード例 #2
0
        public static void SetStatusTrailers(HttpResponse response, Status status)
        {
            // Use SetTrailer here because we want to overwrite any that was set earlier
            SetTrailer(response, GrpcProtocolConstants.StatusTrailer, status.StatusCode.ToTrailerString());

            string escapedDetail;

            if (!string.IsNullOrEmpty(status.Detail))
            {
                // https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#responses
                // The value portion of Status-Message is conceptually a Unicode string description of the error,
                // physically encoded as UTF-8 followed by percent-encoding.
                escapedDetail = PercentEncodingHelpers.PercentEncode(status.Detail);
            }
            else
            {
                escapedDetail = null;
            }

            SetTrailer(response, GrpcProtocolConstants.MessageTrailer, escapedDetail);
        }