-
Notifications
You must be signed in to change notification settings - Fork 0
/
RequestParser.cs
32 lines (28 loc) · 906 Bytes
/
RequestParser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using Azure.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Sedc_Server_Try_One
{
internal class RequestParser
{
internal static Request Parse(string input)
{
var lines = input.Split("\r\n");
var requestLine = lines[0];
var rlRegex = new Regex(@"^([A-Z]+)\s\/(.*)\sHTTP\/1.1$");
var rlMatch = rlRegex.Match(requestLine);
var headerLines = lines.Skip(1).TakeWhile(line => line != "");
var hlRegex = new Regex(@"^([a-zA-Z0-9-]+):\s(.+)$");
var result = new Request
{
Method = rlMatch.Groups[1].Value,
Address = rlMatch.Groups[2].Value
};
return result;
}
}
}