- if (3 != sscanf(str, "HTTP/%u%c%u", &tmp.major, &separator, &tmp.minor)
- && 3 != sscanf(str, "%u%c%u", &tmp.major, &separator, &tmp.minor)) {
- php_http_error(HE_WARNING, PHP_HTTP_E_MALFORMED_HEADERS, "Could not parse HTTP protocol version '%s'", str);
- return NULL;
+ switch (*ptr) {
+ case 'h':
+ case 'H':
+ ++ptr; if (*ptr != 't' && *ptr != 'T') break;
+ ++ptr; if (*ptr != 't' && *ptr != 'T') break;
+ ++ptr; if (*ptr != 'p' && *ptr != 'P') break;
+ ++ptr; if (*ptr != '/') break;
+ ++ptr;
+ /* no break */
+ default:
+ /* rfc7230#2.6 The HTTP version number consists of two decimal digits separated by a "." (period or decimal point) */
+ major = *ptr++ - '0';
+ if (major >= 0 && major <= 9) {
+ separator = *ptr++;
+ if (separator) {
+ if (separator != '.' && separator != ',') {
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Non-standard version separator '%c' in HTTP protocol version '%s'", separator, ptr - 2);
+ }
+ minor = *ptr - '0';
+ if (minor >= 0 && minor <= 9) {
+ return php_http_version_init(v, major, minor TSRMLS_CC);
+ }
+ }
+ }