public HttpServletRequestImpl(string method, Map <string, string> requestHeader, Map <string, string[]> parameterMap, HttpServletResponseImpl resp, WebApplication webApp) : this(method, requestHeader, resp, webApp) { this.parameterMap = parameterMap; }
public HttpServletRequestImpl(Map <string, string> requestHeader, Map <string, byte[][]> byteParameterMap, List <Part> partList, HttpServletResponseImpl resp, WebApplication webApp) : this("POST", requestHeader, resp, webApp) { this.partList = partList; this.byteParameterMap = byteParameterMap; }
private HttpServletRequestImpl(string method, Map <string, string> requestHeader, HttpServletResponseImpl resp, WebApplication webApp) { this.method = method; this.cookies = parseCookies(requestHeader.get("COOKIE")); this.response = resp; this.webApp = webApp; this.session = getSessionInternal(); if (this.session != null) { addSessionCookie(); } }
public static void doService(string method, string query, ServletInfo info, Map <string, string> requestHeader, Stream input, Stream output) { if (info.servlet == null) { info.servlet = createServlet(info); } MemoryStream outputBuffer = new MemoryStream(); HttpServletResponseImpl resp = new HttpServletResponseImpl(outputBuffer); HttpServletRequest req; if (method == "GET") { Map <string, string[]> map; map = stringToMap(query); req = new HttpServletRequestImpl("GET", requestHeader, map, resp, info.webApp); } else if (method == "POST") { string contentType = requestHeader.get("CONTENT-TYPE"); int contentLength = Int32.Parse(requestHeader.get("CONTENT-LENGTH")); if (contentType.ToUpper().StartsWith("MULTIPART/FORM-DATA")) { req = MultiPartParser.parse(requestHeader, input, contentType, contentLength, resp, info.webApp); } else { Map <string, string[]> map; string line = readToSize(input, contentLength); map = stringToMap(line); req = new HttpServletRequestImpl("POST", requestHeader, map, resp, info.webApp); } } else { throw new Exception("BAD METHOD:" + method); } info.servlet.service(req, resp); if (resp.status == HttpServletResponse.SC_OK) { ResponseHeaderGenerator hg = new ResponseHeaderGeneratorImpl(resp.cookies); SendResponse.sendOkResponseHeader(output, resp.contentType, hg); if (resp.printWriter != null) { resp.printWriter.Flush(); } byte[] outputBytes = outputBuffer.ToArray(); foreach (byte b in outputBytes) { output.WriteByte(b); } } else if (resp.status == HttpServletResponse.SC_FOUND) { string redirectLocation; if (resp.redirectLocation.StartsWith("/")) { string host = requestHeader.get("HOST"); redirectLocation = "http://" + ((host != null) ? host : Constants.SERVER_NAME) + resp.redirectLocation; } else { redirectLocation = resp.redirectLocation; } SendResponse.sendFoundResponse(output, redirectLocation); } }
public static HttpServletRequestImpl parse(Map <string, string> requestHeader, Stream input, string contentTypeStr, int contentLength, HttpServletResponseImpl resp, WebApplication webApp) { ContentType contentType = Util.parseContentType(contentTypeStr); string boundary = "--" + contentType.getAttribute("BOUNDARY"); List <Part> partList = new List <Part>(); int length = contentLength; length = readToBoundary(input, boundary, length, null); HashMap <string, byte[][]> parameterMap = new HashMap <string, byte[][]>(); int cnt = 0; for ( ;;) { Map <string, string> headerMap = new HashMap <string, string>(); string line; while ((line = Util.readLine(input)) != null) { length -= line.Length + 2; // 2はCR+LF分 if (line == "") { break; } Util.parseHeader(headerMap, line); } ContentType cd = Util.parseContentType(headerMap.get("CONTENT-DISPOSITION")); string quotedName = cd.getAttribute("NAME"); string name = quotedName.Substring(1, quotedName.Length - 1); string ct = headerMap.get("CONTENT-TYPE"); byte[][] dataOut = new byte[1][]; length = readToBoundary(input, "\r\n" + boundary, length, dataOut); PartImpl part = new PartImpl(ct, headerMap, dataOut[0], name); partList.Add(part); if (ct == null) { byte[][] array = parameterMap.get(name); if (array == null) { parameterMap.Add(name, new byte[][] { dataOut[0] }); } else { byte[][] newArray = new byte[array.Length + 1][]; Array.Copy(array, 0, newArray, 0, array.Length); newArray[array.Length] = dataOut[0]; if (parameterMap.ContainsKey(name)) { // 送信されたパラメータ名が重複した場合はカウント値を追加する // 例外回避のため cnt++; parameterMap.Add(name + cnt.ToString(), newArray); } else { parameterMap.Add(name, newArray); } } } if (length == 0) { break; } } HttpServletRequestImpl req = new HttpServletRequestImpl(requestHeader, parameterMap, partList, resp, webApp); return(req); }