/**
 *
 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either 
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public 
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 * 
 **/
/**
 * Implements the CFML Function gethttprequestdata
 */
package lucee.runtime.functions.other;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

import lucee.runtime.PageContext;
import lucee.runtime.exp.PageException;
import lucee.runtime.ext.function.Function;
import lucee.runtime.net.http.ReqRspUtil;
import lucee.runtime.type.KeyImpl;
import lucee.runtime.type.Struct;
import lucee.runtime.type.StructImpl;
import lucee.runtime.type.util.KeyConstants;

public final class GetHTTPRequestData implements Function {

	private static final long serialVersionUID = 1365182999286292317L;
	
	public static Struct call(PageContext pc ) throws PageException {
		return call(pc,true);
	}
	public static Struct call(PageContext pc, boolean includeBody) throws PageException {
		Struct sct=new StructImpl();
		Struct headers=new StructImpl();
		HttpServletRequest req = pc.getHttpServletRequest();
		String charset = pc.getWebCharset().name();
		// headers
		Enumeration e = req.getHeaderNames();
		while(e.hasMoreElements()) {
			String key=e.nextElement().toString();
			headers.set(KeyImpl.init(ReqRspUtil.decode(key, charset,false)),ReqRspUtil.decode(req.getHeader(key),charset,false));
		}
		sct.set(KeyConstants._headers, headers);
		sct.set(KeyConstants._protocol,req.getProtocol());
		sct.set(KeyConstants._method,req.getMethod());
		if(includeBody)sct.set(KeyConstants._content,ReqRspUtil.getRequestBody(pc,false,""));
		return sct;
	}
}
@@ -1371,17 +1371,16 @@
 92317L;%0A
-%09
 %0A%09public
@@ -1413,17 +1413,16 @@
 ntext pc
- 
 ) throws
@@ -1455,16 +1455,17 @@
 call(pc,
+ 
 true);%0A%09
@@ -1466,16 +1466,17 @@
 ue);%0A%09%7D%0A
+%0A
 %09public 
@@ -1554,16 +1554,17 @@
 ption %7B%0A
+%0A
 %09%09Struct
@@ -1567,17 +1567,19 @@
 ruct sct
-=
+ = 
 new Stru
@@ -1604,17 +1604,19 @@
  headers
-=
+ = 
 new Stru
@@ -1823,17 +1823,19 @@
 ring key
-=
+ = 
 e.nextEl
@@ -1917,16 +1917,17 @@
 set,
+ 
 false)),
 ReqR
@@ -1922,16 +1922,17 @@
 false)),
+ 
 ReqRspUt
@@ -1960,24 +1960,25 @@
 er(key),
+ 
 charset,
 false));
@@ -1969,16 +1969,17 @@
 charset,
+ 
 false));
@@ -1983,16 +1983,17 @@
 ));%0A%09%09%7D%0A
+%0A
 %09%09sct.se
@@ -2060,16 +2060,17 @@
 rotocol,
+ 
 req.getP
@@ -2112,16 +2112,17 @@
 _method,
+ 
 req.getM
@@ -2131,16 +2131,17 @@
 hod());%0A
+%0A
 %09%09if(inc
@@ -2149,16 +2149,20 @@
 udeBody)
+%0A%09%09%09
 sct.set(
@@ -2183,16 +2183,17 @@
 content,
+ 
 ReqRspUt
@@ -2217,20 +2217,23 @@
 (pc,
+ 
 false,
+ 
 %22%22));%0A
+%0A
 %09%09re

format only