| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class _HttpUtils { | 5 class _HttpUtils { |
| 6 static String decodeUrlEncodedString(String urlEncoded) { | 6 static String decodeUrlEncodedString(String urlEncoded) { |
| 7 // First check the string for any encoding. | 7 // First check the string for any encoding. |
| 8 int index = 0; | 8 int index = 0; |
| 9 bool encoded = false; | 9 bool encoded = false; |
| 10 while (!encoded && index < urlEncoded.length) { | 10 while (!encoded && index < urlEncoded.length) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 // wkday = "Mon" | "Tue" | "Wed" | 87 // wkday = "Mon" | "Tue" | "Wed" |
| 88 // | "Thu" | "Fri" | "Sat" | "Sun" | 88 // | "Thu" | "Fri" | "Sat" | "Sun" |
| 89 // weekday = "Monday" | "Tuesday" | "Wednesday" | 89 // weekday = "Monday" | "Tuesday" | "Wednesday" |
| 90 // | "Thursday" | "Friday" | "Saturday" | "Sunday" | 90 // | "Thursday" | "Friday" | "Saturday" | "Sunday" |
| 91 // month = "Jan" | "Feb" | "Mar" | "Apr" | 91 // month = "Jan" | "Feb" | "Mar" | "Apr" |
| 92 // | "May" | "Jun" | "Jul" | "Aug" | 92 // | "May" | "Jun" | "Jul" | "Aug" |
| 93 // | "Sep" | "Oct" | "Nov" | "Dec" | 93 // | "Sep" | "Oct" | "Nov" | "Dec" |
| 94 | 94 |
| 95 // Format as RFC 1123 date. | 95 // Format as RFC 1123 date. |
| 96 static String formatDate(Date date) { | 96 static String formatDate(Date date) { |
| 97 List wkday = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; | 97 const List wkday = const ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; |
| 98 List month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", | 98 const List month = const ["Jan", "Feb", "Mar", "Apr", "May", "Jun", |
| 99 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; | 99 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; |
| 100 | 100 |
| 101 Date d = date.toUtc(); | 101 Date d = date.toUtc(); |
| 102 StringBuffer sb = new StringBuffer(); | 102 StringBuffer sb = new StringBuffer(); |
| 103 sb.add(wkday[d.weekday - 1]); | 103 sb.add(wkday[d.weekday - 1]); |
| 104 sb.add(", "); | 104 sb.add(", "); |
| 105 sb.add(d.day.toString()); | 105 sb.add(d.day.toString()); |
| 106 sb.add(" "); | 106 sb.add(" "); |
| 107 sb.add(month[d.month - 1]); | 107 sb.add(month[d.month - 1]); |
| 108 sb.add(" "); | 108 sb.add(" "); |
| 109 sb.add(d.year.toString()); | 109 sb.add(d.year.toString()); |
| 110 d.hour < 9 ? sb.add(" 0") : sb.add(" "); | 110 d.hour < 9 ? sb.add(" 0") : sb.add(" "); |
| 111 sb.add(d.hour.toString()); | 111 sb.add(d.hour.toString()); |
| 112 d.minute < 9 ? sb.add(":0") : sb.add(":"); | 112 d.minute < 9 ? sb.add(":0") : sb.add(":"); |
| 113 sb.add(d.minute.toString()); | 113 sb.add(d.minute.toString()); |
| 114 d.second < 9 ? sb.add(":0") : sb.add(":"); | 114 d.second < 9 ? sb.add(":0") : sb.add(":"); |
| 115 sb.add(d.second.toString()); | 115 sb.add(d.second.toString()); |
| 116 sb.add(" GMT"); | 116 sb.add(" GMT"); |
| 117 return sb.toString(); | 117 return sb.toString(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 static Date parseDate(String date) { | 120 static Date parseDate(String date) { |
| 121 final int SP = 32; | 121 final int SP = 32; |
| 122 List wkdays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; | 122 const List wkdays = const ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; |
| 123 List weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", | 123 const List weekdays = const ["Monday", "Tuesday", "Wednesday", "Thursday", |
| 124 "Friday", "Saturday", "Sunday"]; | 124 "Friday", "Saturday", "Sunday"]; |
| 125 List months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", | 125 const List months = const ["Jan", "Feb", "Mar", "Apr", "May", "Jun", |
| 126 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; | 126 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; |
| 127 List wkdaysLowerCase = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]; | 127 const List wkdaysLowerCase = |
| 128 List weekdaysLowerCase = ["monday", "tuesday", "wednesday", "thursday", | 128 const ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]; |
| 129 "friday", "saturday", "sunday"]; | 129 const List weekdaysLowerCase = const ["monday", "tuesday", "wednesday", |
| 130 List monthsLowerCase = ["jan", "feb", "mar", "apr", "may", "jun", | 130 "thursday", "friday", "saturday", |
| 131 "jul", "aug", "sep", "oct", "nov", "dec"]; | 131 "sunday"]; |
| 132 const List monthsLowerCase = const ["jan", "feb", "mar", "apr", "may", |
| 133 "jun", "jul", "aug", "sep", "oct", |
| 134 "nov", "dec"]; |
| 132 | 135 |
| 133 final int formatRfc1123 = 0; | 136 final int formatRfc1123 = 0; |
| 134 final int formatRfc850 = 1; | 137 final int formatRfc850 = 1; |
| 135 final int formatAsctime = 2; | 138 final int formatAsctime = 2; |
| 136 | 139 |
| 137 int index = 0; | 140 int index = 0; |
| 138 String tmp; | 141 String tmp; |
| 139 int format; | 142 int format; |
| 140 | 143 |
| 141 void expect(String s) { | 144 void expect(String s) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 minutes = expectNum(":"); | 240 minutes = expectNum(":"); |
| 238 seconds = expectNum(" "); | 241 seconds = expectNum(" "); |
| 239 expect("GMT"); | 242 expect("GMT"); |
| 240 } | 243 } |
| 241 expectEnd(); | 244 expectEnd(); |
| 242 return new Date( | 245 return new Date( |
| 243 year, month + 1, day, hours, minutes, seconds, 0, isUtc: true); | 246 year, month + 1, day, hours, minutes, seconds, 0, isUtc: true); |
| 244 } | 247 } |
| 245 | 248 |
| 246 static Date parseCookieDate(String date) { | 249 static Date parseCookieDate(String date) { |
| 247 List monthsLowerCase = ["jan", "feb", "mar", "apr", "may", "jun", | 250 const List monthsLowerCase = const ["jan", "feb", "mar", "apr", "may", |
| 248 "jul", "aug", "sep", "oct", "nov", "dec"]; | 251 "jun", "jul", "aug", "sep", "oct", |
| 252 "nov", "dec"]; |
| 249 | 253 |
| 250 int position = 0; | 254 int position = 0; |
| 251 | 255 |
| 252 void error() { | 256 void error() { |
| 253 throw new HttpException("Invalid cookie date $date"); | 257 throw new HttpException("Invalid cookie date $date"); |
| 254 } | 258 } |
| 255 | 259 |
| 256 bool isEnd() { | 260 bool isEnd() { |
| 257 return position == date.length; | 261 return position == date.length; |
| 258 } | 262 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 dayOfMonthStr = token; | 323 dayOfMonthStr = token; |
| 320 } else if (monthStr === null && getMonth(token) >= 0) { | 324 } else if (monthStr === null && getMonth(token) >= 0) { |
| 321 monthStr = token; | 325 monthStr = token; |
| 322 } else if (yearStr === null && token.length >= 2 && | 326 } else if (yearStr === null && token.length >= 2 && |
| 323 isDigit(token[0]) && isDigit(token[1])) { | 327 isDigit(token[0]) && isDigit(token[1])) { |
| 324 yearStr = token; | 328 yearStr = token; |
| 325 } | 329 } |
| 326 } | 330 } |
| 327 | 331 |
| 328 if (timeStr === null || dayOfMonthStr === null || | 332 if (timeStr === null || dayOfMonthStr === null || |
| 329 monthStr === null || yearStr === null) error(); | 333 monthStr === null || yearStr === null) { |
| 334 error(); |
| 335 } |
| 330 | 336 |
| 331 int year = toInt(yearStr); | 337 int year = toInt(yearStr); |
| 332 if (year >= 70 && year <= 99) year += 1900; | 338 if (year >= 70 && year <= 99) year += 1900; |
| 333 else if (year >= 0 && year <= 69) year += 2000; | 339 else if (year >= 0 && year <= 69) year += 2000; |
| 334 if (year < 1601) error(); | 340 if (year < 1601) error(); |
| 335 | 341 |
| 336 int dayOfMonth = toInt(dayOfMonthStr); | 342 int dayOfMonth = toInt(dayOfMonthStr); |
| 337 if (dayOfMonth < 1 || dayOfMonth > 31) error(); | 343 if (dayOfMonth < 1 || dayOfMonth > 31) error(); |
| 338 | 344 |
| 339 int month = getMonth(monthStr) + 1; | 345 int month = getMonth(monthStr) + 1; |
| 340 | 346 |
| 341 var timeList = timeStr.split(":"); | 347 var timeList = timeStr.split(":"); |
| 342 if (timeList.length !== 3) error(); | 348 if (timeList.length !== 3) error(); |
| 343 int hour = toInt(timeList[0]); | 349 int hour = toInt(timeList[0]); |
| 344 int minute = toInt(timeList[1]); | 350 int minute = toInt(timeList[1]); |
| 345 int second = toInt(timeList[2]); | 351 int second = toInt(timeList[2]); |
| 346 if (hour > 23) error(); | 352 if (hour > 23) error(); |
| 347 if (minute > 59) error(); | 353 if (minute > 59) error(); |
| 348 if (second > 59) error(); | 354 if (second > 59) error(); |
| 349 | 355 |
| 350 return new Date(year, month, dayOfMonth, hour, minute, second, 0, true); | 356 return new Date(year, month, dayOfMonth, hour, minute, second, 0, true); |
| 351 } | 357 } |
| 352 } | 358 } |
| OLD | NEW |