Class: HTTY::CLI::Commands::HeadersRequest

Inherits:
HTTY::CLI::Command show all
Includes:
Display
Defined in:
lib/htty/cli/commands/headers_request.rb

Overview

Encapsulates the headers-request command.

Constant Summary

Constant Summary

Constants included from Display

Display::FORMATS

Instance Attribute Summary

Attributes inherited from HTTY::CLI::Command

#arguments, #session

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Display

#break, #format, #formatted_prompt_for, #indent, #logotype, #normal, #notice, #pluralize, #rescuing_from, #say, #say_goodbye, #say_header, #say_hello, #show_headers, #show_request, #show_response, #strong, #word_wrap, #word_wrap_indented

Methods inherited from HTTY::CLI::Command

#add_request_if_new, alias_for, aliases, build_for, command_line, command_line_arguments, complete_for?, #initialize, notify_if_cookies_cleared, raw_name, sanitize_arguments

Constructor Details

This class inherits a constructor from HTTY::CLI::Command

Class Method Details

+ (Object) category

Returns the name of a category under which help for the headers-request command should appear.



24
25
26
# File 'lib/htty/cli/commands/headers_request.rb', line 24

def self.category
  'Building Requests'
end

+ (Object) help

Returns the help text for the headers-request command.



29
30
31
# File 'lib/htty/cli/commands/headers_request.rb', line 29

def self.help
  'Displays the headers of the request'
end

+ (Object) help_extended

Returns the extended help text for the headers-request command.



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/htty/cli/commands/headers_request.rb', line 34

def self.help_extended
  'Displays the headers used for the request. Does not communicate with '    +
  "the host.\n"                                                              +
  "\n"                                                                       +
  'Headers must have unique names. When you set a header that already '      +
  "exists, its value will be changed.\n"                                     +
  "\n"                                                                       +
  "A '#{HTTY::Request::COOKIES_HEADER_NAME}' request header is marked with " +
  'a bold asterisk (it looks like a cookie). Similarly, an '                 +
  "'#{HTTY::Request::AUTHORIZATION_HEADER_NAME}' request header is marked "  +
  "with a bold mercantile symbol ('@')."
end

+ (Object) see_also_commands

Returns related command classes for the headers-request command.



48
49
50
51
52
53
54
55
# File 'lib/htty/cli/commands/headers_request.rb', line 48

def self.see_also_commands
  [HTTY::CLI::Commands::HeadersSet,
   HTTY::CLI::Commands::HeadersUnset,
   HTTY::CLI::Commands::HeadersUnsetAll,
   HTTY::CLI::Commands::BodyRequest,
   HTTY::CLI::Commands::Cookies,
   HTTY::CLI::Commands::HeadersResponse]
end

Instance Method Details

- (Object) perform

Performs the headers-request command.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/htty/cli/commands/headers_request.rb', line 58

def perform
  request = session.requests.last
  headers = if request.request_method.nil?
              if request.body.to_s.length.zero?
                request.headers false
              else
                request.headers true
              end
            else
              request.headers
            end
  show_headers headers,
               :show_asterisk_next_to => HTTY::Request::COOKIES_HEADER_NAME,
               :show_mercantile_next_to => HTTY::Request::AUTHORIZATION_HEADER_NAME
  self
end