Commit 37fd806
Access mode detection (transcode vs grpcweb vs grpc) (#412)
* Detect preflight requests
These typically come from grpcweb clients doing OPTIONS checks for CORS
* Detect client types: grpc, grpcweb, web
This replaces the `http_transcode` member of the `Server.Stream` struct
as transcoding is correlated with being a web client (*not* a grpcweb
client, however!)
Knowing the type of client also allows for detection of when to send
different types of headers, for e.g. CORS
* Add a CORS header injection Interceptor
It an option `:allow` option to define which origins are allowed.
This may be a static string or a function which will be passed the
current `req` and `stream` structs to choose what to allow.
* Reintroduce the boolean http_transcode member of the Stream struct
NOTE: will merge this with commit
c39c834 post-review/discussion.
I am leaving it as a separate commit for now for ease of continued
discussion on the current PR.
* web can be detected in extract_subtype
* change access_type to access_mode, :web to :http_transcoding
this more accurately and directly maps to the grpc terminology, and is
probably clearer.
* default opts to an empty list, whitespace fix
* add tests for the CORS header interceptor
* Assign to a temporary variable and assign that to Stream.http_transcode
* provide access to request headers in the Stream object
* only set cors when the sec-fetch-mode header indicates it
* another test: if there is NO sec-fetch-mode header
* Make access-control-allow-headers configurable, and optional
Only send access-control-allow-headers when the client requests it with
access-control-request-headers and allow the same configurability as
access-control-allow-origin provides
* align variable names with http header names
* Add a CORS example to the README
* format
* Verbage.
Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>
* remove default for allow_origin in CORS interceptor
* raise on failed allow_origin type, and test for that
* allow_origin, not allow_header
* test: add missing compile-time test
* chore: format readme
* chore: fix Note bold
* docs: cleanup readme linking
* docs: proper module linking in exdoc
* fix: do not use Keyword.validate due to Elixir 1.12 support
---------
Co-authored-by: Adriano Santos <solid.sistemas@gmail.com>
Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>1 parent 9a9d73a commit 37fd806
File tree
7 files changed
+552
-50
lines changed- lib/grpc
- server
- adapters/cowboy
- interceptors
- test
- grpc/server/interceptors
- support
7 files changed
+552
-50
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
99 | | - | |
| 100 | + | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
| |||
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
| 156 | + | |
155 | 157 | | |
156 | 158 | | |
157 | 159 | | |
| |||
167 | 169 | | |
168 | 170 | | |
169 | 171 | | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
170 | 189 | | |
171 | 190 | | |
172 | 191 | | |
| |||
231 | 250 | | |
232 | 251 | | |
233 | 252 | | |
234 | | - | |
| 253 | + | |
235 | 254 | | |
236 | 255 | | |
237 | 256 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
| 155 | + | |
| 156 | + | |
156 | 157 | | |
157 | 158 | | |
158 | 159 | | |
| |||
178 | 179 | | |
179 | 180 | | |
180 | 181 | | |
181 | | - | |
182 | | - | |
| 182 | + | |
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
255 | | - | |
| 255 | + | |
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
274 | 278 | | |
275 | 279 | | |
276 | 280 | | |
| |||
339 | 343 | | |
340 | 344 | | |
341 | 345 | | |
342 | | - | |
| 346 | + | |
| 347 | + | |
343 | 348 | | |
344 | 349 | | |
345 | 350 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
59 | | - | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| 64 | + | |
| 65 | + | |
63 | 66 | | |
64 | 67 | | |
65 | 68 | | |
| |||
69 | 72 | | |
70 | 73 | | |
71 | 74 | | |
| 75 | + | |
| 76 | + | |
72 | 77 | | |
73 | | - | |
| 78 | + | |
| 79 | + | |
74 | 80 | | |
75 | 81 | | |
76 | 82 | | |
77 | 83 | | |
78 | 84 | | |
79 | 85 | | |
80 | 86 | | |
81 | | - | |
| 87 | + | |
82 | 88 | | |
83 | 89 | | |
84 | 90 | | |
| |||
89 | 95 | | |
90 | 96 | | |
91 | 97 | | |
92 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
93 | 108 | | |
94 | 109 | | |
95 | 110 | | |
| |||
121 | 136 | | |
122 | 137 | | |
123 | 138 | | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
130 | 142 | | |
131 | 143 | | |
132 | 144 | | |
| |||
600 | 612 | | |
601 | 613 | | |
602 | 614 | | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
609 | 621 | | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | | - | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
616 | 628 | | |
617 | 629 | | |
618 | 630 | | |
619 | | - | |
| 631 | + | |
620 | 632 | | |
621 | 633 | | |
622 | | - | |
| 634 | + | |
| 635 | + | |
623 | 636 | | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
630 | 644 | | |
631 | 645 | | |
632 | 646 | | |
633 | 647 | | |
634 | | - | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
635 | 652 | | |
636 | 653 | | |
637 | 654 | | |
| |||
0 commit comments