package com.ociweb.gl.impl.stage;

import com.ociweb.gl.api.Headable;
import com.ociweb.pronghorn.network.config.HTTPContentType;
import com.ociweb.pronghorn.network.config.HTTPContentTypeDefaults;
import com.ociweb.pronghorn.network.config.HTTPHeader;
import com.ociweb.pronghorn.network.config.HTTPSpecification;
import com.ociweb.pronghorn.pipe.ChannelReader;

public class HeaderTypeCapture implements Headable {

	private HTTPContentType type;
	private HTTPSpecification<?, ?, ?, ?> httpSpec;
	
	public HeaderTypeCapture(HTTPSpecification<?, ?, ?, ?> httpSpec) {
		this.httpSpec = httpSpec;
	}
	
	@Override
	public void read(HTTPHeader header, ChannelReader reader) {
		
		short type = reader.readShort();
		if ((type<0) || (type>=httpSpec.contentTypes.length)) {
			this.type = HTTPContentTypeDefaults.UNKNOWN;
		} else {
			this.type = (HTTPContentType)httpSpec.contentTypes[type];
		}
		
	}

	/**
	 *
	 * @return type
	 */
	public HTTPContentType type() {
		return type;
	}

}

@@ -976,10 +976,150 @@
 pe;%0A%09%7D%0A%0A
+%09@Override%0A%09public void read(HTTPHeader value, ChannelReader reader, long fieldId) %7B%0A%09%09read(value,reader.structured().read(fieldId));%09%09%0A%09%7D%0A%0A
 %7D%0A

add new method to read by fieldId