diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-07-29 10:58:22 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-07-29 10:58:22 +1200 |
commit | 4315f0dc46e0c09e945658a6c47ce45ba576641d (patch) | |
tree | 0b56b131eb9ddf8a1a880636041cd80dbf75ac3e | |
parent | 4f875a6fb51aa1eb7aebc779d2b971f74a53e901 (diff) | |
download | traccar-server-4315f0dc46e0c09e945658a6c47ce45ba576641d.tar.gz traccar-server-4315f0dc46e0c09e945658a6c47ce45ba576641d.tar.bz2 traccar-server-4315f0dc46e0c09e945658a6c47ce45ba576641d.zip |
Include content length in OsmAnd response
-rw-r--r-- | src/org/traccar/protocol/OsmAndProtocolDecoder.java | 15 |
1 files changed, 12 insertions, 3 deletions
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; |