mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-09 19:28:30 -05:00
Return dawarich headers on all API responses
This commit is contained in:
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
# [0.30.9] - 2025-08-11
|
||||
|
||||
## Added
|
||||
|
||||
- X-Dawarich-Response and X-Dawarich-Version headers are now returned for all API responses.
|
||||
|
||||
# [0.30.8] - 2025-08-01
|
||||
|
||||
## Fixed
|
||||
|
||||
@@ -4,14 +4,6 @@ class Api::V1::HealthController < ApiController
|
||||
skip_before_action :authenticate_api_key
|
||||
|
||||
def index
|
||||
if current_api_user
|
||||
response.set_header('X-Dawarich-Response', 'Hey, I\'m alive and authenticated!')
|
||||
else
|
||||
response.set_header('X-Dawarich-Response', 'Hey, I\'m alive!')
|
||||
end
|
||||
|
||||
response.set_header('X-Dawarich-Version', APP_VERSION)
|
||||
|
||||
render json: { status: 'ok' }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,10 +2,18 @@
|
||||
|
||||
class ApiController < ApplicationController
|
||||
skip_before_action :verify_authenticity_token
|
||||
before_action :set_version_header
|
||||
before_action :authenticate_api_key
|
||||
|
||||
private
|
||||
|
||||
def set_version_header
|
||||
message = "Hey, I\'m alive#{current_api_user ? ' and authenticated' : ''}!"
|
||||
|
||||
response.set_header('X-Dawarich-Response', message)
|
||||
response.set_header('X-Dawarich-Version', APP_VERSION)
|
||||
end
|
||||
|
||||
def authenticate_api_key
|
||||
return head :unauthorized unless current_api_user
|
||||
|
||||
|
||||
@@ -12,6 +12,13 @@ RSpec.describe 'Api::V1::Countries::Borders', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
|
||||
it 'returns X-Dawarich-Response header' do
|
||||
get '/api/v1/countries/borders'
|
||||
|
||||
expect(response.headers['X-Dawarich-Response']).to eq('Hey, I\'m alive!')
|
||||
expect(response.headers['X-Dawarich-Version']).to eq(APP_VERSION)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user is authenticated' do
|
||||
@@ -22,6 +29,13 @@ RSpec.describe 'Api::V1::Countries::Borders', type: :request do
|
||||
expect(response.body).to include('AF')
|
||||
expect(response.body).to include('ZW')
|
||||
end
|
||||
|
||||
it 'returns X-Dawarich-Response header' do
|
||||
get '/api/v1/countries/borders', headers: { 'Authorization' => "Bearer #{user.api_key}" }
|
||||
|
||||
expect(response.headers['X-Dawarich-Response']).to eq('Hey, I\'m alive and authenticated!')
|
||||
expect(response.headers['X-Dawarich-Version']).to eq(APP_VERSION)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user