package com.ociweb.oe.foglight.api;

import com.ociweb.gl.api.HTTPRequestReader;
import com.ociweb.gl.api.Headable;
import com.ociweb.gl.api.Payloadable;
import com.ociweb.gl.api.RestListener;
import com.ociweb.iot.maker.FogCommandChannel;
import com.ociweb.iot.maker.FogRuntime;
import com.ociweb.pronghorn.network.config.HTTPHeaderDefaults;
import com.ociweb.pronghorn.pipe.ChannelReader;

public class RestBehaviorEmptyResponse implements RestListener {

	final byte[] cookieHeader = HTTPHeaderDefaults.COOKIE.rootBytes();
	final byte[] fieldName;
	private final FogCommandChannel cmd;
	
	public RestBehaviorEmptyResponse(FogRuntime runtime, byte[] myArgName) {
		this.fieldName = myArgName;		
		this.cmd = runtime.newCommandChannel(NET_RESPONDER);
	}
	
	Payloadable reader = new Payloadable() {
		
		@Override
		public void read(ChannelReader reader) {
			
			System.out.println("POST: "+reader.readUTFOfLength(reader.available()));
			
		}			
	};

	private Headable headReader = new Headable() {

		@Override
		public void read(int id, ChannelReader reader) { 
			
			System.out.println("COOKIE: "+reader.readUTFOfLength(reader.available()));
						
		}
		
	};


	@Override
	public boolean restRequest(HTTPRequestReader request) {
		
	    int argInt = request.getInt(fieldName);
	    System.out.println("Arg Int: "+argInt);
		
		request.openHeaderData(cookieHeader, headReader);
		
		if (request.isVerbPost()) {
			request.openPayloadData(reader );
		}
		
		//no body just a 200 ok response.
		return cmd.publishHTTPResponse(request, 200);

	}

}

@@ -273,16 +273,71 @@
 untime;%0A
+import com.ociweb.pronghorn.network.config.HTTPHeader;%0A
 import c
@@ -1085,14 +1085,25 @@
 ead(
-int id
+HTTPHeader header
 , Ch

update to add new signature change