Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for sparql-query content type #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions lib/sparql_server/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -148,26 +148,29 @@ defmodule SparqlServer.Router do
end

defp get_query_from_post(conn, body) do
if Plug.Conn.get_req_header(conn, "content-type") == ["application/sparql-update"] do
{:update, body}
else
body_params = URI.decode_query(body)

cond do
# apparently this can be both :query as well as :update in practice
body_params["query"] ->
{:any, body_params["query"]}

body_params["update"] ->
{:update, body_params["update"]}

true ->
params =
conn.query_string
|> URI.decode_query()

{:any, params["query"]}
end
cond do
Plug.Conn.get_req_header(conn, "content-type") == ["application/sparql-update"] ->
{:update, body}
Plug.Conn.get_req_header(conn, "content-type") == ["application/sparql-query"] ->
{:any, body}
true ->
body_params = URI.decode_query(body)

cond do
# apparently this can be both :query as well as :update in practice
body_params["query"] ->
{:any, body_params["query"]}

body_params["update"] ->
{:update, body_params["update"]}

true ->
params =
conn.query_string
|> URI.decode_query()

{:any, params["query"]}
end
end
end

Expand Down