Example #1
0
        private void HandleRequest(Request request)
        {
            Exchange exchange = new ProxyExchange(this, request);

            exchange.Request = request;

            Response response = null;

            // ignore the request if it is reset or acknowledge
            // check if the proxy-uri is defined
            if (request.Type != MessageType.RST && request.Type != MessageType.ACK &&
                request.HasOption(OptionType.ProxyUri))
            {
                // get the response from the cache
                response = _cacheResource.GetResponse(request);

                // TODO update statistics
                //_statsResource.updateStatistics(request, response != null);
            }

            // check if the response is present in the cache
            if (response != null)
            {
                // link the retrieved response with the request to set the
                // parameters request-specific (i.e., token, id, etc)
                exchange.SendResponse(response);
                return;
            }
            else
            {
                // edit the request to be correctly forwarded if the proxy-uri is
                // set
                if (request.HasOption(OptionType.ProxyUri))
                {
                    try
                    {
                        ManageProxyUriRequest(request);
                    }
                    catch (Exception)
                    {
                        if (log.IsWarnEnabled)
                        {
                            log.Warn("Proxy-uri malformed: " + request.GetFirstOption(OptionType.ProxyUri).StringValue);
                        }

                        exchange.SendResponse(new Response(StatusCode.BadOption));
                    }
                }

                // handle the request as usual
                if (_proxyCoapResolver != null)
                {
                    _proxyCoapResolver.ForwardRequest(exchange);
                }
            }
        }
Example #2
0
        private void HandleRequest(Request request)
        {
            Exchange exchange = new ProxyExchange(this, request);
            exchange.Request = request;

            Response response = null;
            // ignore the request if it is reset or acknowledge
            // check if the proxy-uri is defined
            if (request.Type != MessageType.RST && request.Type != MessageType.ACK
                    && request.HasOption(OptionType.ProxyUri))
            {
                // get the response from the cache
                response = _cacheResource.GetResponse(request);

                // TODO update statistics
                //_statsResource.updateStatistics(request, response != null);
            }

            // check if the response is present in the cache
            if (response != null)
            {
                // link the retrieved response with the request to set the
                // parameters request-specific (i.e., token, id, etc)
                exchange.SendResponse(response);
                return;
            }
            else
            {
                // edit the request to be correctly forwarded if the proxy-uri is
                // set
                if (request.HasOption(OptionType.ProxyUri))
                {
                    try
                    {
                        ManageProxyUriRequest(request);
                    }
                    catch (Exception)
                    {
                        if (log.IsWarnEnabled)
                            log.Warn("Proxy-uri malformed: " + request.GetFirstOption(OptionType.ProxyUri).StringValue);

                        exchange.SendResponse(new Response(StatusCode.BadOption));
                    }
                }

                // handle the request as usual
                if (_proxyCoapResolver != null)
                    _proxyCoapResolver.ForwardRequest(exchange);
            }
        }