An Elixir toolkit for the AT Protocol. hexdocs.pm/atex
elixir bluesky atproto decentralization
25
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(xrpc): ensure content-type header is set when sending raw_input

+32 -4
+28 -3
lib/atex/xrpc.ex
··· 168 168 end 169 169 170 170 def post(client, %{__struct__: module} = procedure, opts) do 171 + has_raw_input? = 172 + if raw_input = procedure.raw_input do 173 + opts = Keyword.put(opts, :body, raw_input) 174 + 175 + if Code.ensure_loaded?(module) and function_exported?(module, :content_type, 0) do 176 + headers = Keyword.get(opts, :headers, []) 177 + has_content_type? = Enum.any?(headers, fn {k, _} -> String.downcase(k) == "content-type" end) 178 + 179 + unless has_content_type? do 180 + raise """ 181 + content-type header is required when sending raw_input for #{module.id()}. 182 + Expected: #{module.content_type()} 183 + """ 184 + end 185 + end 186 + 187 + true 188 + else 189 + false 190 + end 191 + 171 192 opts = 172 - opts 173 - |> put_params(procedure) 174 - |> put_body(procedure) 193 + if has_raw_input? do 194 + put_params(opts, procedure) 195 + else 196 + opts 197 + |> put_params(procedure) 198 + |> put_body(procedure) 199 + end 175 200 176 201 output_struct = Module.concat(module, Output) 177 202 output_exists = Code.ensure_loaded?(output_struct)
+4 -1
test/atex/lexicon_test.exs
··· 196 196 end 197 197 198 198 test "error structs have from_json/1" do 199 + Code.ensure_loaded!(Lexicon.Test.DoThing.Errors.SomethingBroke) 200 + Code.ensure_loaded!(Lexicon.Test.DoThing.Errors.DoesNotCompute) 199 201 assert function_exported?(Lexicon.Test.DoThing.Errors.SomethingBroke, :from_json, 1) 200 202 assert function_exported?(Lexicon.Test.DoThing.Errors.DoesNotCompute, :from_json, 1) 201 203 end ··· 232 234 end 233 235 234 236 test "root module exports coerce_error/1" do 237 + Code.ensure_loaded!(Lexicon.Test.DoThing) 235 238 assert function_exported?(Lexicon.Test.DoThing, :coerce_error, 1) 236 239 end 237 240 ··· 269 272 end 270 273 271 274 test "error structs have from_json/1" do 272 - Code.ensure_loaded!(Lexicon.Test.DoOtherThing) 275 + Code.ensure_loaded!(Lexicon.Test.DoOtherThing.Errors.ValidationFailed) 273 276 assert function_exported?(Lexicon.Test.DoOtherThing.Errors.ValidationFailed, :from_json, 1) 274 277 end 275 278