From 4315f0dc46e0c09e945658a6c47ce45ba576641d Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 29 Jul 2016 10:58:22 +1200 Subject: Include content length in OsmAnd response --- src/org/traccar/protocol/OsmAndProtocolDecoder.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java index f46511b27..5d59c3b41 100644 --- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java +++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java @@ -15,9 +15,11 @@ */ package org.traccar.protocol; +import org.eclipse.jetty.http.HttpHeader; import org.jboss.netty.channel.Channel; import org.jboss.netty.handler.codec.http.DefaultHttpResponse; import org.jboss.netty.handler.codec.http.HttpRequest; +import org.jboss.netty.handler.codec.http.HttpResponse; import org.jboss.netty.handler.codec.http.HttpResponseStatus; import org.jboss.netty.handler.codec.http.HttpVersion; import org.jboss.netty.handler.codec.http.QueryStringDecoder; @@ -40,6 +42,14 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder { super(protocol); } + private void sendResponse(Channel channel, HttpResponseStatus status) { + if (channel != null) { + HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status); + response.headers().add(HttpHeader.CONTENT_LENGTH.asString(), 0); + channel.write(response); + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -64,8 +74,7 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder { DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, value); if (deviceSession == null) { if (channel != null) { - channel.write( - new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST)); + sendResponse(channel, HttpResponseStatus.BAD_REQUEST); } return null; } @@ -124,7 +133,7 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder { } if (channel != null) { - channel.write(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK)); + sendResponse(channel, HttpResponseStatus.OK); } return position; -- cgit v1.2.3