diff --git a/.github/workflows/hex-publish.yml b/.github/workflows/hex-publish.yml deleted file mode 100644 index f904b66..0000000 --- a/.github/workflows/hex-publish.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Hex Publish - -on: - push: - tags: - - '*' - -jobs: - publish: - runs-on: ubuntu-latest - steps: - - name: Check out - uses: actions/checkout@v2 - - - name: Publish to Hex.pm - uses: erlangpack/github-action@v3 - env: - HEX_API_KEY: ${{ secrets.HEX_API_KEY }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bbfd9a5..67cc33b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: - otp_version: [23,24,25] + otp_version: [24,25,26] os: [ubuntu-latest] container: diff --git a/src/cowmachine.app.src b/src/cowmachine.app.src index bd3bbe2..96061f3 100644 --- a/src/cowmachine.app.src +++ b/src/cowmachine.app.src @@ -6,12 +6,13 @@ {applications, [ kernel, stdlib, + inets, zotonic_stdlib, + ranch, + cowlib, cowboy ]}, - {env, [ - {use_sendfile, erlang} - ]}, + {env, []}, {licenses, ["Apache-2.0"]}, {links, [{"GitHub", "https://github.com/zotonic/cowmachine"}]} ]}. diff --git a/src/cowmachine_decision_core.erl b/src/cowmachine_decision_core.erl index 1b6f7d1..357c5af 100644 --- a/src/cowmachine_decision_core.erl +++ b/src/cowmachine_decision_core.erl @@ -82,10 +82,12 @@ is_cacheable(generate_etag) -> true; is_cacheable(_) -> false. -spec controller_call_process(ContentType, State, Context) -> Result when - ContentType :: cow_http_hd:media_type(), - State :: cmstate(), + ContentType :: cow_http_hd:media_type(), + State :: cmstate(), Context :: cowmachine_req:context(), - Result :: {boolean() | ContentType, State, Context}. + Result :: {Res, State, Context}, + Res :: boolean() | cowmachine_req:halt() | {error, any(), any()} | {error, any()} | + cowmachine_req:resp_body(). controller_call_process(ContentType, State, Context) -> {T, Context1} = cowmachine_controller:do_process(ContentType, State, Context), {T, State, Context1}. @@ -137,11 +139,18 @@ respond(Code, State, Context) -> ExpCtx0) end, {StateExp, ExpCtx}; - % Let the error controller handle 4xx and 5xx errors - E when E =:= 401; E =:= 403; E =:= 404; E=:= 410; - (E >= 500 andalso E =< 599) -> - controller_call(finish_request, State, Context), - throw({stop_request, Code}); + E when E =:= 401; E =:= 403; E =:= 404; E=:= 410; (E >= 500 andalso E =< 599) -> + % Http errors - maybe handled by error controller + HasRespContentType = cowmachine_req:get_resp_header(<<"content-type">>, Context) =/= undefined, + HasBody = cowmachine_req:resp_body(Context) =/= undefined, + if + HasBody andalso HasRespContentType -> + {State, Context}; + true -> + % Let the error controller handle 4xx and 5xx errors without body + controller_call(finish_request, State, Context), + throw({stop_request, Code}) + end; _ -> {State, Context} end, @@ -778,9 +787,9 @@ process_helper(ContentTypeAccepted, State, Context) -> {halt, _} -> Result; {error, _, _} -> Result; {error, _} -> Result; - true when is_boolean(Res) -> Result; - false when is_boolean(Res) -> Result; - RespBody -> + true -> Result; + false -> Result; + RespBody when is_binary(RespBody); is_list(RespBody) -> C3 = cowmachine_req:set_resp_body(RespBody, C2), {body, S2, C3} end. diff --git a/src/cowmachine_response.erl b/src/cowmachine_response.erl index 6b3b158..c50ffd7 100644 --- a/src/cowmachine_response.erl +++ b/src/cowmachine_response.erl @@ -356,7 +356,7 @@ send_device_body(Context, Length, IO) -> -spec send_file_body(Context, Length, File, FinNoFin) -> Result when Context :: cowmachine_req:context(), Length :: non_neg_integer(), - File :: Filename | file:iodata(), + File :: Filename | iodata(), Filename :: file:name_all(), FinNoFin :: fin | nofin, Result :: cowmachine_req:context(). diff --git a/src/cowmachine_util.erl b/src/cowmachine_util.erl index 1c4f514..b20438a 100644 --- a/src/cowmachine_util.erl +++ b/src/cowmachine_util.erl @@ -239,7 +239,7 @@ accept_header_to_media_types(HeadVal) -> -spec normalize_provided(Provided) -> Result when Provided :: [cowmachine_req:media_type()], - Result :: cow_http_hd:media_type(). + Result :: [cow_http_hd:media_type()]. normalize_provided(Provided) -> [ normalize_content_type(X) || X <- Provided ].