comparison src/luan/webserver/RequestParser.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 bd0420fb3dd0
comparison
equal deleted inserted replaced
1147:30d87b7d1d62 1148:49fb4e83484f
121 require( parser.match("\r\n") ); 121 require( parser.match("\r\n") );
122 Util.add(request.headers,name,value); 122 Util.add(request.headers,name,value);
123 } 123 }
124 124
125 private String parseName() throws ParseException { 125 private String parseName() throws ParseException {
126 StringBuilder buf = new StringBuilder(); 126 int start = parser.currentIndex();
127 boolean cap = true;
128 require( tokenChar() ); 127 require( tokenChar() );
129 do { 128 while( tokenChar() );
130 char c = parser.lastChar(); 129 return parser.textFrom(start).toLowerCase();
131 if( c == '-' ) { 130 }
132 cap = true; 131
133 } else if( cap ) { 132 private String parseValue() throws ParseException {
134 c = Character.toUpperCase(c);
135 cap = false;
136 } else {
137 c = Character.toLowerCase(c);
138 }
139 buf.append(c);
140 } while( tokenChar() );
141 return buf.toString();
142 }
143
144 private String parseValue() {
145 int start = parser.currentIndex(); 133 int start = parser.currentIndex();
146 while( !testEndOfValue() ) 134 while( !testEndOfValue() )
147 parser.anyChar(); 135 require( parser.anyChar() );
148 return parser.textFrom(start); 136 return parser.textFrom(start);
149 } 137 }
150 138
151 private boolean testEndOfValue() { 139 private boolean testEndOfValue() {
152 parser.begin(); 140 parser.begin();
173 } 161 }
174 } 162 }
175 163
176 164
177 private void parseCookies() throws ParseException { 165 private void parseCookies() throws ParseException {
178 String text = (String)request.headers.get("Cookie"); 166 String text = (String)request.headers.get("cookie");
179 if( text == null ) 167 if( text == null )
180 return; 168 return;
181 this.parser = new Parser(text); 169 this.parser = new Parser(text);
182 while(true) { 170 while(true) {
183 int start = parser.currentIndex(); 171 int start = parser.currentIndex();
197 185
198 186
199 private static final String contentTypeStart = "multipart/form-data; boundary="; 187 private static final String contentTypeStart = "multipart/form-data; boundary=";
200 188
201 void parseMultipart() throws ParseException { 189 void parseMultipart() throws ParseException {
202 String contentType = (String)request.headers.get("Content-Type"); 190 String contentType = (String)request.headers.get("content-type");
203 if( !contentType.startsWith(contentTypeStart) ) 191 if( !contentType.startsWith(contentTypeStart) )
204 throw new RuntimeException(contentType); 192 throw new RuntimeException(contentType);
205 String boundary = "--"+contentType.substring(contentTypeStart.length()); 193 String boundary = "--"+contentType.substring(contentTypeStart.length());
206 this.parser = new Parser(Util.toString(request.body)); 194 this.parser = new Parser(Util.toString(request.body));
207 require( parser.match(boundary) ); 195 require( parser.match(boundary) );