-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1244 from namusyaka/add-header-support
Add header support for middleware
- Loading branch information
Showing
8 changed files
with
135 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Grape | ||
module DSL | ||
module Headers | ||
# Set an individual header or retrieve | ||
# all headers that have been set. | ||
def header(key = nil, val = nil) | ||
if key | ||
val ? header[key.to_s] = val : header.delete(key.to_s) | ||
else | ||
@header ||= {} | ||
end | ||
end | ||
alias_method :headers, :header | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'spec_helper' | ||
|
||
module Grape | ||
module DSL | ||
module HeadersSpec | ||
class Dummy | ||
include Grape::DSL::Headers | ||
end | ||
end | ||
describe Headers do | ||
subject { HeadersSpec::Dummy.new } | ||
|
||
describe '#header' do | ||
describe 'set' do | ||
before do | ||
subject.header 'Name', 'Value' | ||
end | ||
|
||
it 'returns value' do | ||
expect(subject.header['Name']).to eq 'Value' | ||
expect(subject.header('Name')).to eq 'Value' | ||
end | ||
end | ||
|
||
it 'returns nil' do | ||
expect(subject.header['Name']).to be nil | ||
expect(subject.header('Name')).to be nil | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters