File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -57,15 +57,20 @@ request.WriteHeader(preparedHeaders);
57
57
58
58
### Avoiding strings
59
59
60
- Avoid string allocations and get tighter control over encoding by passing in ` byte[] ` arrays :
60
+ Avoid ` string ` and ` Uri ` allocations and get tight control over encoding by passing in ` ReadOnlySpan< byte> ` :
61
61
62
62
``` c#
63
- byte [] headerName = .. .;
64
- byte [] headerValue = .. .;
63
+ ReadOnlySpan < byte > method = HttpRequest .GetMethod ; // "GET"
64
+ ReadOnlySpan < byte > scheme = .. .; // "https"
65
+ ReadOnlySpan < byte > authority = .. .; // "microsoft.com:80"
66
+ ReadOnlySpan < byte > pathAndQuery = .. .; // "/"
67
+
68
+ ReadOnlySpan < byte > headerName = .. .; // "Accept"
69
+ ReadOnlySpan < byte > headerValue = .. .; // "text/html"
65
70
66
71
await using ValueHttpRequest request = ...;
67
72
request .ConfigureRequest (contentLength : 0 , hasTrailingHeaders : false );
68
- request .WriteRequest (HttpMethod . Get , new Uri ( " http://microsoft.com " ) );
73
+ request .WriteRequest (method , scheme , authority , pathAndQuery );
69
74
request .WriteHeader (headerName , headerValue );
70
75
```
71
76
You can’t perform that action at this time.
0 commit comments