Skip to content

Commit d004513

Browse files
committed
Update README.md
1 parent 7cac121 commit d004513

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,20 @@ request.WriteHeader(preparedHeaders);
5757

5858
### Avoiding strings
5959

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>`:
6161

6262
```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"
6570
6671
await using ValueHttpRequest request = ...;
6772
request.ConfigureRequest(contentLength: 0, hasTrailingHeaders: false);
68-
request.WriteRequest(HttpMethod.Get, new Uri("http://microsoft.com"));
73+
request.WriteRequest(method, scheme, authority, pathAndQuery);
6974
request.WriteHeader(headerName, headerValue);
7075
```
7176

0 commit comments

Comments
 (0)