comparison src/luan/webserver/Connection.java @ 1148:49fb4e83484f

webserver - change headers to lower case
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 04 Feb 2018 17:11:06 -0700
parents 30d87b7d1d62
children 4beabb087be6
comparison
equal deleted inserted replaced
1147:30d87b7d1d62 1148:49fb4e83484f
61 //System.out.println(rawHead); 61 //System.out.println(rawHead);
62 request.rawHead = rawHead; 62 request.rawHead = rawHead;
63 RequestParser parser = new RequestParser(request); 63 RequestParser parser = new RequestParser(request);
64 parser.parseHead(); 64 parser.parseHead();
65 65
66 String lenStr = (String)request.headers.get("Content-Length"); 66 String lenStr = (String)request.headers.get("content-length");
67 if( lenStr != null ) { 67 if( lenStr != null ) {
68 int len = Integer.parseInt(lenStr); 68 int len = Integer.parseInt(lenStr);
69 byte[] body = new byte[len]; 69 byte[] body = new byte[len];
70 size -= endOfHeader; 70 size -= endOfHeader;
71 System.arraycopy(a,endOfHeader,body,0,size); 71 System.arraycopy(a,endOfHeader,body,0,size);
78 } 78 }
79 request.body = body; 79 request.body = body;
80 //System.out.println(new String(request.body)); 80 //System.out.println(new String(request.body));
81 } 81 }
82 82
83 String contentType = (String)request.headers.get("Content-Type"); 83 String contentType = (String)request.headers.get("content-type");
84 if( contentType != null ) { 84 if( contentType != null ) {
85 if( request.body == null ) { 85 if( request.body == null ) {
86 logger.error("body is null"); 86 logger.error("body is null");
87 } else { 87 } else {
88 if( "application/x-www-form-urlencoded".equals(contentType) ) { 88 if( "application/x-www-form-urlencoded".equals(contentType) ) {
95 } 95 }
96 } 96 }
97 } 97 }
98 98
99 Response response = server.handler.handle(request); 99 Response response = server.handler.handle(request);
100 response.headers.put("Connection","close"); 100 response.headers.put("connection","close");
101 response.headers.put("Content-Length",Long.toString(response.body.length)); 101 response.headers.put("content-length",Long.toString(response.body.length));
102 byte[] header = response.toHeaderString().getBytes(); 102 byte[] header = response.toHeaderString().getBytes();
103 103
104 OutputStream out = socket.getOutputStream(); 104 OutputStream out = socket.getOutputStream();
105 out.write(header); 105 out.write(header);
106 copyAll(response.body.content,out); 106 copyAll(response.body.content,out);