Skip to content

Commit

Permalink
chore: Set user agent to metadata requests (blockscout#10834)
Browse files Browse the repository at this point in the history
* chore: Set user agent to metadata requests

* Add backend version to User-agent
  • Loading branch information
vbaranov authored Oct 16, 2024
1 parent 7d763c0 commit f71a4cc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
9 changes: 5 additions & 4 deletions apps/explorer/lib/explorer/token/metadata_retriever.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defmodule Explorer.Token.MetadataRetriever do
@no_uri_error "no uri"
@vm_execution_error "VM execution error"
@invalid_base64_data "invalid data:application/json;base64"
@default_headers [{"User-Agent", "blockscout-6.8.1"}]

# https://eips.ethereum.org/EIPS/eip-1155#metadata
@erc1155_token_id_placeholder "{id}"
Expand Down Expand Up @@ -475,12 +476,12 @@ defmodule Explorer.Token.MetadataRetriever do
gateway_url_param_value = ipfs_params[:gateway_url_param_value]

if gateway_url_param_key && gateway_url_param_value do
[{gateway_url_param_key, gateway_url_param_value}]
[{gateway_url_param_key, gateway_url_param_value} | @default_headers]
else
[]
@default_headers
end
else
[]
@default_headers
end
end

Expand Down Expand Up @@ -670,7 +671,7 @@ defmodule Explorer.Token.MetadataRetriever do
end

defp fetch_metadata_from_uri_request(uri, hex_token_id, ipfs?) do
headers = if ipfs?, do: ipfs_headers(), else: []
headers = if ipfs?, do: ipfs_headers(), else: @default_headers

case Application.get_env(:explorer, :http_adapter).get(uri, headers,
recv_timeout: 30_000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ defmodule Explorer.Token.MetadataRetrieverTest do

Explorer.Mox.HTTPoison
|> expect(:get, fn "https://ipfs.io/ipfs/QmT1Yz43R1PLn2RVovAnEM5dHQEvpTcnwgX8zftvY1FcjP",
[{"x-apikey", "mykey"}],
[{"x-apikey", "mykey"}, {"User-Agent", _}],
_options ->
{:ok, %HTTPoison.Response{status_code: 200, body: Jason.encode!(result)}}
end)
Expand Down
3 changes: 3 additions & 0 deletions bin/version_bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ CONFIG_FILE="$(pwd)/rel/config.exs"
DOCKER_COMPOSE_FILE="$(pwd)/docker-compose/docker-compose.yml"
MAKE_FILE="$(pwd)/docker/Makefile"
WORKFLOW_FILES=($(find "$(pwd)/.github/workflows" -type f \( -name "pre-release-*" -o -name "release-*" -o -name "publish-docker-image-*" \)))
METADATA_RETRIEVER_FILE="$(pwd)/apps/explorer/lib/explorer/token/metadata_retriever.ex"

# Function to bump version
bump_version() {
Expand Down Expand Up @@ -69,6 +70,8 @@ bump_version() {
sed -i '' "s/RELEASE_VERSION: $current_version/RELEASE_VERSION: $new_version/" "$WORKFLOW_FILE"
done

sed -i '' "s/\"blockscout-$current_version\"/\"blockscout-$new_version\"/" "$METADATA_RETRIEVER_FILE"

echo "Version bumped from $current_version to $new_version"
}

Expand Down

0 comments on commit f71a4cc

Please sign in to comment.