示例#1
0
        public ZendeskDefaultConfiguration(string username, string token)
        {
            Headers = new Headers();

            var auth = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}/token:{1}", username, token)));

            Headers.AddHeader(AcceptCharset, "utf-8");
            Headers.AddHeader(Authorization, string.Format("Basic {0}", auth));
            Headers.AddHeader(AcceptKey, "application/json");
            Headers.AddHeader(ContentTypeKey, "application/json");
        }
        public ZendeskDefaultConfiguration(string username, string token)
        {
            Headers = new Headers();

            var auth = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}/token:{1}", username, token)));

            Headers.AddHeader(AcceptCharset, "utf-8");
            Headers.AddHeader(Authorization, string.Format("Basic {0}", auth));
            Headers.AddHeader(AcceptKey, "application/json");
            Headers.AddHeader(ContentTypeKey, "application/json");
        }
 public HtmlResult(string content, HttpResponseStatusCode responseStatusCode)
     : base(responseStatusCode)
 {
     Content = Encoding.UTF8.GetBytes(content);
     Headers.AddHeader(new HttpHeader(Constants.ContentTypeHeaderKey, Constants.HtmlContentTypeHeaderValue));
     Headers.AddHeader(new HttpHeader(Constants.ContentLengthHeaderKey, Content.Length.ToString()));
 }
示例#4
0
        private void ParseHeaders(string[] rawHeaders)
        {
            foreach (var rawHeader in rawHeaders)
            {
                string[] parts = rawHeader.Split(HttpHeaderNameValueSeparator, 2);

                if (parts[0] == HttpHeader.Cookie)
                {
                    ParseCookies(parts[1]);
                    continue;
                }

                if (parts.Length == 1 && parts[0] == string.Empty)
                {
                    break;
                }

                Headers.AddHeader(new HttpHeader(parts[0], parts[1]));
            }

            if (!Headers.ContainsHeader(HttpHeader.Host))
            {
                throw new BadRequestException();
            }
        }
示例#5
0
 public InlineResourceResult(byte[] content, HttpResponseStatusCode httpResponseStatusCode)
     : base(httpResponseStatusCode)
 {
     Headers.AddHeader(new HttpHeader(HttpHeader.ContentLength, content.Length.ToString()));
     Headers.AddHeader(new HttpHeader(HttpHeader.ContentDisposition, "inline"));
     Content = content;
 }
示例#6
0
        private void ParseHeaders(string[] requestLines)
        {
            bool isHostHeaderPresent = false;

            foreach (var currentLine in requestLines)
            {
                if (string.IsNullOrEmpty(currentLine))
                {
                    break;
                }

                string[] currentLineArray = currentLine.Split(": ");
                string   header           = currentLineArray[0];
                string   headerData       = currentLineArray[1];

                HttpHeader httpHeader = new HttpHeader(header, headerData);
                Headers.AddHeader(httpHeader);

                if (header == "Host")
                {
                    isHostHeaderPresent = true;
                }
            }

            if (isHostHeaderPresent == false)
            {
                throw new BadRequestException();
            }
        }
示例#7
0
        public void TestBuildHeaders()
        {
            var headers = new Headers();

            headers.AddHeader(HeaderNames.Created, "2004-09-21T03:01:52Z");

            headers.ShouldBe(Resource.Get("Xmpp.Shim.headers1.xml"));
        }
示例#8
0
        public void AddHeaderTakesInANameAndValueAndReturnsANewHeadersWithTheAdditionalHeader()
        {
            var testHeaders = new Headers("test", "header");

            var updatedHeaders = testHeaders.AddHeader("additional", "header");

            var addedHeader = updatedHeaders["additional"];

            Assert.Equal("additional", addedHeader.Name);
            Assert.Equal("header", addedHeader.Value);
        }
示例#9
0
        public void AddHeaderTakesInANameAndValueAndReplacesTheExistingHeaderWhenANamingConflictOccurs()
        {
            var testHeaders = new Headers("test", "header");

            var updatedHeaders = testHeaders.AddHeader("test", "NewValue");

            var changedHeader = updatedHeaders["test"];

            Assert.Equal("test", changedHeader.Name);
            Assert.Equal("NewValue", changedHeader.Value);
        }
示例#10
0
        public void TestHeaders2()
        {
            var headers = new Headers();

            headers.AddHeader(HeaderNames.Created, "2004-09-21T03:01:52Z");
            headers.ShouldBe(Resource.Get("Xmpp.Shim.headers1.xml"));

            var headers2 = new Headers();

            headers2[HeaderNames.Created].Value = "2004-09-21T03:01:52Z";
            headers2.ShouldBe(Resource.Get("Xmpp.Shim.headers1.xml"));
        }
示例#11
0
文件: Shim.cs 项目: enptcvr/agsXmpp-1
        internal Shim()
        {
            /*
             *  Example of an Urgent Message
             *
             *  <message
             *      from='[email protected]/orchard'
             *      to='*****@*****.**'
             *      type='chat'>
             *    <body>Wherefore are thou?!?</body>
             *    <headers xmlns='http://jabber.org/protocol/shim'>
             *      <header name='Urgency'>high</header>
             *    </headers>
             *  </message>
             */

            // Create the message aboute which includes the shim header urgency
            agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message();
            msg.From = new Jid("[email protected]/orchard");
            msg.To   = new Jid("*****@*****.**");
            msg.Type = MessageType.chat;
            msg.Body = "Wherefore are thou?!?";

            Headers headers = new Headers();

            headers.AddHeader("Urgency", "high");

            msg.Headers = headers;
            // or
            // msg.AddChild(headers);
            Program.Print(msg);

            // after we created this header we want to change the urgency of the existing message to low
            Headers heads = msg.Headers;

            if (heads != null)
            {
                heads.SetHeader("Urgency", "low");
            }

            Program.Print(msg);

            // Add another header
            // <header name='In-Reply-To'>[email protected]</header>
            msg.Headers.AddHeader("In-Reply-To", "*****@*****.**");
            Program.Print(msg);

            // Remove all Headers
            msg.Headers = null;
            Program.Print(msg);
        }
	private void ParseHeaders(string[] requestHeaders)
	{
	    foreach (var requestHeader in requestHeaders)
	    {
		string[] headerArgs = requestHeader.Split(": ", StringSplitOptions.RemoveEmptyEntries);
		if (headerArgs.Length == 2 && headerArgs[0] != Constants.CookieRequestHeaderKey)
		{
		    string headerKey = headerArgs[0];
		    string headerValue = headerArgs[1];
		    IHttpHeader header = new HttpHeader(headerKey, headerValue);
		    Headers.AddHeader(header);
		}
	    }
	    if (Headers.GetHeader(Constants.HostHeaderKey) == null) throw new BadRequestException();
	}
示例#13
0
        private static Headers GetRequestHeaders(string requestString)
        {
            var headers      = new Headers();
            var requestLines = requestString.Split("\r\n", StringSplitOptions.RemoveEmptyEntries);
            var headerLines  = requestLines.Skip(1);

            foreach (var headerString in headerLines)
            {
                var headerKeyAndValue = headerString.Split(": ");
                var name  = headerKeyAndValue[0];
                var value = headerKeyAndValue[1];
                headers = headers.AddHeader(name, value);
            }

            return(headers);
        }
示例#14
0
    public static Headers AsKafkaHeaders(this Metadata metadata)
    {
        var headers = new Headers();

        // ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator
        foreach (var entry in metadata)
        {
            if (entry.Key == MetaTags.MessageId)
            {
                continue;
            }

            headers.AddHeader(entry.Key, entry.Value?.ToString());
        }

        return(headers);
    }
示例#15
0
 public TextResult(byte[] content, HttpResponseStatusCode responseStatusCode,
                   string contentType = "text/plain; charset=utf-8") : base(responseStatusCode)
 {
     Headers.AddHeader(new HttpHeader("Content-Type", contentType));
     Content = content;
 }
示例#16
0
 public RedirectResult(string location, string content)
     : base(content, HttpResponseStatusCode.SeeOther)
 {
     Headers.AddHeader(new HttpHeader(Constants.LocationHeaderKey, location));
 }
示例#17
0
 public void AddHeader(String key, Object value)
 {
     Headers.AddHeader(key, value);
 }
示例#18
0
 public UnauthorizedResult(string content) : base(HttpResponseStatusCode.Unauthorized)
 {
     Content = Encoding.UTF8.GetBytes(content);
     Headers.AddHeader(new HttpHeader(Constants.ContentLengthHeaderKey, Content.Length.ToString()));
     Headers.AddHeader(new HttpHeader(Constants.WWWAuthenticateHeaderKey, "Basic"));
 }
 public HttpResponse(string content, HttpResponseStatusCode statusCode) : this(statusCode)
 {
     Content = Encoding.UTF8.GetBytes(content);
     Headers.AddHeader(new HttpHeader(
                           Constants.ContentLengthHeaderKey, Content.Length.ToString()));
 }
 public RedirectResult(string location) : base(HttpResponseStatusCode.SeeOther)
 {
     Headers.AddHeader(new HTTP.Headers.HttpHeader("Location", location));
 }
示例#21
0
 public HtmlResult(string content, HttpResponseStatusCode responseStatusCode = HttpResponseStatusCode.Ok) : base(responseStatusCode)
 {
     Headers.AddHeader(new HttpHeader("Content-Type", "text/html; charset=utf-8"));
     Content = Encoding.UTF8.GetBytes(content);
 }
示例#22
0
 public TextResult(byte[] content, HttpResponseStatusCode httpResponseStatusCode, string contentType = @"text/plain charset=utf-8")
     : base(httpResponseStatusCode)
 {
     Content = content;
     Headers.AddHeader(new HTTP.Headers.HttpHeader("Content-Type", contentType));
 }
示例#23
0
 public void AddHeader(HttpHeader header)
 {
     Headers.AddHeader(header);
 }
示例#24
0
 public InlineResourceResult(byte[] content) : base(HttpResponseStatusCode.OK)
 {
     Content = content;
     Headers.AddHeader(new HttpHeader(Constants.ContentDispositionHeaderKey, "inline"));
     Headers.AddHeader(new HttpHeader(Constants.ContentLengthHeaderKey, Content.Length.ToString()));
 }
示例#25
0
 public TextResult(string content, HttpResponseStatusCode httpResponseStatusCode, string contentType = @"text/plain charset=utf-8")
     : base(httpResponseStatusCode)
 {
     Headers.AddHeader(new HTTP.Headers.HttpHeader("Content-Type", contentType));
     Content = Encoding.UTF8.GetBytes(content);
 }
 public TextResponse(string content, HttpResponseStatusCode statusCode = HttpResponseStatusCode.OK)
     : base(content, statusCode)
 {
     Headers.AddHeader(new HttpHeader(Constants.ContentTypeHeaderKey, Constants.ContentTypeTextHeaderValue));
 }
 public NotFoundResult(string resourceType, string resourceName)
     : base(HttpResponseStatusCode.NotFound)
 {
     Content = Encoding.UTF8.GetBytes(string.Format(Constants.ResourceNotFoundMessage, resourceType, resourceName));
     Headers.AddHeader(new HttpHeader(Constants.HttpContentLengthKey, Content.Length.ToString()));
 }