-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathHttpRequest.cs
More file actions
76 lines (58 loc) · 2.01 KB
/
Copy pathHttpRequest.cs
File metadata and controls
76 lines (58 loc) · 2.01 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Components.Net.Http
{
public class HttpRequest : HttpMessagePart
{
public string Path { get; set; }
public string Method { get; set; }
public string Version { get; set; }
public FieldValuePair[] QueryString { get; set; }
public FieldValuePair[] PostValues { get; set; }
public HttpUpload[] Uploads { get; set; }
public bool IsMultipart { get; set; }
public string Boundary { get; set; }
public string StartBoundary { get; set; }
public string EndBoundary { get; set; }
public HttpRequest()
{
Path = "/";
Method = HttpMethod.Get;
Version = HttpVersion.V11;
}
public void SetMultipart(string boundary = "boundary5230")
{
IsMultipart = true;
Boundary = boundary;
StartBoundary = "--" + Boundary + "\r\n";
EndBoundary = "--" + Boundary + "--\r\n";
ResetField(HttpField.ContentType, MimeType.Multipart + "; boundary=" + boundary);
}
public void SetContentLength()
{
ResetField(HttpField.ContentLength, 0);
}
public string BuildRelativeUrl()
{
var url = (Path[0] == '/' ? "" : "/") + Path;
if (QueryString != null && QueryString.Any())
{
url += "?" + FormUrlEncoder.Encode(QueryString);
}
return url;
}
public string BuildAbsoluteUrl(string host)
{
return "http://" + host + BuildRelativeUrl();
}
public string CreateHeader(string host)
{
return Method + " " + BuildRelativeUrl() + " HTTP/" + Version + "\r\n" +
GetAttributeString() + "\r\n\r\n";
}
}
}