public static int GetRequestProtocolVersion(Request request) {
// Accept: application/starcounter.warehouse.software-v2+json\r\n
try {
string headers = request.GetAllHeaders();
if (!string.IsNullOrEmpty(headers)) {
string[] lines = headers.Split(new string[] { "\r\n" }, StringSplitOptions.None);
for (int i = 0; i < lines.Length; i++) {
string line = lines[i];
// Check if the line is field values
if (line.StartsWith(" ") || line.StartsWith("\t")) continue;
if (line.StartsWith("acceptversion:", StringComparison.CurrentCultureIgnoreCase)) {
// Found our accept header.
string match = "application/starcounter.warehouse.software-v";
int vStartIndex = line.IndexOf(match, 7, StringComparison.CurrentCultureIgnoreCase);
if (vStartIndex == -1) continue;
vStartIndex += match.Length;
int vStopIndex = line.IndexOf('+', vStartIndex);
if (vStopIndex == -1) continue;
string str = line.Substring(vStartIndex, vStopIndex - vStartIndex);
int num;
if (int.TryParse(str, out num) == false) continue;
// TODO: For the moment we will ignore values that spans over multiple lines
// In the future i think this code will be replaced by logic in the Request
return num;
}
}
}
}
catch (Exception) {
}
return 1;
}