Skip to content

Commit 2003255

Browse files
authored
Always set CORS headers (#434)
* Not all GRPC sessions advertise CORS in their headers In practice, this is still setting the headers just as often, as GRPC sessions that do advertise CORS in the request headers do so consistently, while those that do not are still limited by CORS by the browser policy. * remove two tests that are no longer relevant
1 parent 0102b97 commit 2003255

File tree

3 files changed

+1
-44
lines changed

3 files changed

+1
-44
lines changed

.tool-versions

Lines changed: 0 additions & 2 deletions
This file was deleted.

lib/grpc/server/interceptors/cors.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ defmodule GRPC.Server.Interceptors.CORS do
7777

7878
@impl true
7979
def call(req, stream, next, {allow_origin, allow_headers}) do
80-
if stream.access_mode != :grpc and
81-
Map.get(stream.http_request_headers, "sec-fetch-mode") == "cors" do
80+
if stream.access_mode != :grpc do
8281
headers =
8382
%{}
8483
|> add_allowed_origins(req, stream, allow_origin)

test/grpc/server/interceptors/cors_test.exs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -271,44 +271,4 @@ defmodule GRPC.Server.Interceptors.CORSTest do
271271
"Incorrect header when using function"
272272
)
273273
end
274-
275-
test "CORS only on cors sec-fetch-mode" do
276-
request = %FakeRequest{}
277-
278-
stream = %{
279-
create_stream()
280-
| access_mode: :grpcweb,
281-
http_request_headers: Map.put(@default_http_headers, "sec-fetch-mode", "same-origin")
282-
}
283-
284-
{:ok, :ok} =
285-
CORSInterceptor.call(
286-
request,
287-
%{stream | access_mode: :grpcweb},
288-
fn _request, _stream -> {:ok, :ok} end,
289-
CORSInterceptor.init(allow_origin: "*")
290-
)
291-
292-
refute_received({:setting_headers, _}, "Set CORS header")
293-
end
294-
295-
test "No CORS if missing sec-fetch-mode header" do
296-
request = %FakeRequest{}
297-
298-
stream = %{
299-
create_stream()
300-
| access_mode: :grpcweb,
301-
http_request_headers: Map.delete(@default_http_headers, "sec-fetch-mode")
302-
}
303-
304-
{:ok, :ok} =
305-
CORSInterceptor.call(
306-
request,
307-
%{stream | access_mode: :grpcweb},
308-
fn _request, _stream -> {:ok, :ok} end,
309-
CORSInterceptor.init(allow_origin: "*")
310-
)
311-
312-
refute_received({:setting_headers, _}, "Set CORS header")
313-
end
314274
end

0 commit comments

Comments
 (0)