Mercurial Hosting > luan
comparison src/goodjava/webserver/Connection.java @ 1513:a0a74f5f490a
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 24 May 2020 19:44:58 -0600 |
parents | 471ef3e6a84e |
children | fa066aaa068c |
comparison
equal
deleted
inserted
replaced
1512:31b543826ca9 | 1513:a0a74f5f490a |
---|---|
27 | 27 |
28 private void handle() { | 28 private void handle() { |
29 try { | 29 try { |
30 Request request = new Request(); | 30 Request request = new Request(); |
31 Response response; | 31 Response response; |
32 String contentType = null; | |
32 try { | 33 try { |
33 { | 34 { |
34 InputStream in = socket.getInputStream(); | 35 InputStream in = socket.getInputStream(); |
35 byte[] a = new byte[8192]; | 36 byte[] a = new byte[8192]; |
36 int endOfHeader; | 37 int endOfHeader; |
81 } | 82 } |
82 request.body = body; | 83 request.body = body; |
83 //System.out.println(new String(request.body)); | 84 //System.out.println(new String(request.body)); |
84 } | 85 } |
85 | 86 |
86 String contentType = (String)request.headers.get("content-type"); | 87 contentType = (String)request.headers.get("content-type"); |
87 if( contentType != null ) { | 88 if( contentType != null ) { |
88 contentType = contentType.toLowerCase(); | 89 contentType = contentType.toLowerCase(); |
89 if( contentType.equals("application/x-www-form-urlencoded") ) { | 90 if( contentType.equals("application/x-www-form-urlencoded") ) { |
90 parser.parseUrlencoded(null); | 91 parser.parseUrlencoded(null); |
91 } else if( contentType.equals("application/x-www-form-urlencoded; charset=utf-8") ) { | 92 } else if( contentType.equals("application/x-www-form-urlencoded; charset=utf-8") ) { |
106 request.scheme = scheme; | 107 request.scheme = scheme; |
107 } | 108 } |
108 response = server.handler.handle(request); | 109 response = server.handler.handle(request); |
109 } catch(ParseException e) { | 110 } catch(ParseException e) { |
110 logger.warn("parse error\n"+request.rawHead.trim()+"\n",e); | 111 logger.warn("parse error\n"+request.rawHead.trim()+"\n",e); |
111 response = Response.errorResponse(Status.BAD_REQUEST,e.toString()); | 112 String msg = e.toString(); |
113 if( contentType != null ) | |
114 msg = "invalid content for content-type " + contentType + "\n" + msg; | |
115 response = Response.errorResponse(Status.BAD_REQUEST,msg); | |
112 } | 116 } |
113 response.headers.put("connection","close"); | 117 response.headers.put("connection","close"); |
114 response.headers.put("content-length",Long.toString(response.body.length)); | 118 response.headers.put("content-length",Long.toString(response.body.length)); |
115 byte[] header = response.toHeaderString().getBytes(); | 119 byte[] header = response.toHeaderString().getBytes(); |
116 | 120 |