<commit_before>package org.latte.scripting.hostobjects;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.codec.binary.Base64;
import org.mortbay.jetty.Request;
import org.mozilla.javascript.ScriptableObject;

public class RequestProxy extends ScriptableObject {
	private class Params extends ScriptableObject {
		protected Params(HttpServletRequest request) {			
			if(request.getParameterMap().size() > 0) {
				for(String key : (Set<String>)request.getParameterMap().keySet()) {
					Object value = request.getParameterMap().get(key);
					
					if(request.getContentType().startsWith("multipart/form-data")) {
						if(value instanceof String) {
							File tmp = (File)request.getAttribute(key);	
							File file = new File(tmp.getAbsoluteFile() + ((String)value).substring(((String)value).indexOf(".")));
							tmp.renameTo(file);
							ScriptableObject.putProperty(this, key, file.getAbsolutePath());
						}
						else {
							ScriptableObject.putProperty(this, key, new String((byte[])value));
						}
					}
					else {
						ScriptableObject.putProperty(this, key, ((String[])value)[0]);
					}
				}
			}
		}
		
		@Override
		public String getClassName() {
			return "Params";
		}
		
	}
	
	public RequestProxy(HttpServletRequest request) throws IOException {
		ScriptableObject.putProperty(this, "hostname", request.getRemoteHost());
		ScriptableObject.putProperty(this, "url", request.getRequestURI());
		ScriptableObject.putProperty(this, "params", new Params(request));	
		
		String authorization = (String)request.getHeader("Authorization");
		if(authorization != null && authorization.startsWith("Basic"))  ScriptableObject.putProperty(this, "authorization", new String(new Base64().decode(authorization.split(" ")[1].getBytes())));
		
		if("application/json".equals(request.getContentType())) {
			StringBuffer sb = new StringBuffer();
			BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream()));
			String line;
			while((line = br.readLine()) != null) {
				sb.append(line);
			}<commit_msg>fixed hostname resolution<commit_after>package org.latte.scripting.hostobjects;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.codec.binary.Base64;
import org.mortbay.jetty.Request;
import org.mozilla.javascript.ScriptableObject;

public class RequestProxy extends ScriptableObject {
	private class Params extends ScriptableObject {
		protected Params(HttpServletRequest request) {			
			if(request.getParameterMap().size() > 0) {
				for(String key : (Set<String>)request.getParameterMap().keySet()) {
					Object value = request.getParameterMap().get(key);
					
					if(request.getContentType().startsWith("multipart/form-data")) {
						if(value instanceof String) {
							File tmp = (File)request.getAttribute(key);	
							File file = new File(tmp.getAbsoluteFile() + ((String)value).substring(((String)value).indexOf(".")));
							tmp.renameTo(file);
							ScriptableObject.putProperty(this, key, file.getAbsolutePath());
						}
						else {
							ScriptableObject.putProperty(this, key, new String((byte[])value));
						}
					}
					else {
						ScriptableObject.putProperty(this, key, ((String[])value)[0]);
					}
				}
			}
		}
		
		@Override
		public String getClassName() {
			return "Params";
		}
		
	}
	
	public RequestProxy(HttpServletRequest request) throws IOException {
		ScriptableObject.putProperty(this, "hostname", InetAddress.getByName(request.getRemoteAddr()).getHostAddress());
		ScriptableObject.putProperty(this, "url", request.getRequestURI());
		ScriptableObject.putProperty(this, "params", new Params(request));	
		
		String authorization = (String)request.getHeader("Authorization");
		if(authorization != null && authorization.startsWith("Basic"))  ScriptableObject.putProperty(this, "authorization", new String(new Base64().decode(authorization.split(" ")[1].getBytes())));
		
		if("application/json".equals(request.getContentType())) {
			StringBuffer sb = new StringBuffer();
			BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream()));
			String line;
			while((line = br.readLine()) != null) {
				sb.append(line);
			}
{'fraction_non_alphanumeric': 0.13726362625139044, 'fraction_numerical': 0.003114571746384872, 'mean_word_length': 4.6270337922403, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '251380', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1286, 'n_words': 234}