Ejemplo n.º 1
0
        public void SendRequestToDevice(System.Collections.IDictionary plistBody)
        {
            HttpRequestHead head = new HttpRequestHead();

            head.Headers = new Dictionary <string, string>();
            head.Method  = "POST";
            head.Path    = "/event";
            head.Version = new Version(1, 1);
            var requestBytes = ResponseMessageHelper.GetBytes(head, plistBody);

            this.scheduler.Post(() => SendRequest(requestBytes));
        }
Ejemplo n.º 2
0
        public void OnRequest(HttpRequestHead request, IDataProducer requestBody, IHttpResponseDelegate response)
        {
            var ea = new RequestReceivedEventArgs();

            ea.RequestHead  = request;
            ea.ResponseHead = ResponseMessageHelper.GetHttpResponseHead();

            string contentType = string.Empty;

            if (ea.RequestHead.Headers.ContainsKey("Content-Type"))
            {
                contentType = ea.RequestHead.Headers["Content-Type"];
            }
            int contentSize = 0;

            if (ea.RequestHead.Headers.ContainsKey("Content-Length"))
            {
                int.TryParse(ea.RequestHead.Headers["Content-Length"], out contentSize);
            }
            BufferedConsumer bc = new BufferedConsumer(bodyContents =>
            {
                try
                {
                    ea.RequestBody = bodyContents;
                    //Called when request body is read to end
                    if (RequestReceived != null)
                    {
                        RequestReceived(this, ea);
                    }
                    var bp = ea.ResponseBodyProducer as BufferedProducer;
                    if (bp != null)
                    {
                        ea.ResponseHead.Headers["Content-Length"] = bp.GetContentLength().ToString();
                    }
                }
                finally
                {
                    response.OnResponse(ea.ResponseHead, ea.ResponseBodyProducer);
                }
            }, error =>
            {
            }, contentType, contentSize);

            //Gets complete HTTP Request and runs code defined over
            requestBody.Connect(bc);
        }