D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Net
/
HTTPHeader
/
Filename :
cdesc-HTTPHeader.ri
back
Copy
U:RDoc::NormalModule[iI"HTTPHeader:ETI"Net::HTTPHeader;T0o:RDoc::Markup::Document:@parts[o;;[So:RDoc::Markup::Paragraph;[I"=The \HTTPHeader module provides access to \HTTP headers.;To:RDoc::Markup::BlankLine o; ;[I"The module is included in:;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0;[o; ;[I">Net::HTTPGenericRequest (and therefore Net::HTTPRequest).;To;;0;[o; ;[I"Net::HTTPResponse.;T@o; ;[I"OThe headers are a hash-like collection of key/value pairs called _fields_.;T@S:RDoc::Markup::Heading: leveli: textI" Request and Response Fields;T@o; ;[I" Headers may be included in:;T@o;;; ;[o;;0;[o; ;[ I" A Net::HTTPRequest object: ;TI"9the object's headers will be sent with the request. ;TI"/Any fields may be defined in the request; ;TI"5see {Setters}[rdoc-ref:Net::HTTPHeader@Setters].;To;;0;[o; ;[ I"!A Net::HTTPResponse object: ;TI"Cthe objects headers are usually those returned from the host. ;TI".Fields may be retrieved from the object; ;TI"5see {Getters}[rdoc-ref:Net::HTTPHeader@Getters] ;TI"9and {Iterators}[rdoc-ref:Net::HTTPHeader@Iterators].;T@o; ;[I"JExactly which fields should be sent or expected depends on the host; ;TI" see:;T@o;;; ;[o;;0;[o; ;[I"_{Request fields}[https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields].;To;;0;[o; ;[I"a{Response fields}[https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Response_fields].;T@S;;i;I"About the Examples;T@o; ;[I"CExamples here assume that <tt>net/http</tt> has been required ;TI"!(which also requires +uri+):;T@o:RDoc::Markup::Verbatim;[I"require 'net/http' ;T:@format0o; ;[I"8Many code examples here use these example websites:;T@o;;; ;[o;;0;[o; ;[I"*https://jsonplaceholder.typicode.com.;To;;0;[o; ;[I"http://example.com.;T@o; ;[I"/Some examples also assume these variables:;T@o;;[ I"8uri = URI('https://jsonplaceholder.typicode.com/') ;TI"+uri.freeze # Examples may not modify. ;TI"Ahostname = uri.hostname # => "jsonplaceholder.typicode.com" ;TI"&path = uri.path # => "/" ;TI"&port = uri.port # => 443 ;T;0o; ;[I"0So that example requests may be written as:;T@o;;[I"Net::HTTP.get(uri) ;TI",Net::HTTP.get(hostname, '/index.html') ;TI")Net::HTTP.start(hostname) do |http| ;TI" http.get('/todos/1') ;TI" http.get('/todos/2') ;TI" end ;T;0o; ;[I"^An example that needs a modified URI first duplicates +uri+, then modifies the duplicate:;T@o;;[I"_uri = uri.dup ;TI"_uri.path = '/todos/1' ;T;0S;;i;I"Fields;T@o; ;[I"(A header field is a key/value pair.;T@S;;i;I"Field Keys;T@o; ;[I"A field key may be:;T@o;;; ;[o;;0;[o; ;[I">A string: Key <tt>'Accept'</tt> is treated as if it were ;TI":<tt>'Accept'.downcase</tt>; i.e., <tt>'accept'</tt>.;To;;0;[o; ;[I"=A symbol: Key <tt>:Accept</tt> is treated as if it were ;TI"><tt>:Accept.to_s.downcase</tt>; i.e., <tt>'accept'</tt>.;T@o; ;[I"Examples:;T@o;;[ I"#req = Net::HTTP::Get.new(uri) ;TI"req[:accept] # => "*/*" ;TI"req['Accept'] # => "*/*" ;TI"req['ACCEPT'] # => "*/*" ;TI" ;TI"!req['accept'] = 'text/html' ;TI" req[:accept] = 'text/html' ;TI"!req['ACCEPT'] = 'text/html' ;T;0S;;i;I"Field Values;T@o; ;[I"IA field value may be returned as an array of strings or as a string:;T@o;;; ;[o;;0;[o; ;[I"1These methods return field values as arrays:;T@o;;; ;[o;;0;[o; ;[I"=#get_fields: Returns the array value for the given key, ;TI"#or +nil+ if it does not exist.;To;;0;[o; ;[I"4#to_hash: Returns a hash of all header fields: ;TI"Jeach key is a field name; its value is the array value for the field.;T@o;;0;[o; ;[I"2These methods return field values as string; ;TI"3the string value for a field is equivalent to ;TI"2<tt>self[key.downcase.to_s].join(', '))</tt>:;T@o;;; ;[o;;0;[o; ;[I"6#[]: Returns the string value for the given key, ;TI"#or +nil+ if it does not exist.;To;;0;[o; ;[I"3#fetch: Like #[], but accepts a default value ;TI".to be returned if the key does not exist.;T@o; ;[I" The field value may be set:;T@o;;; ;[o;;0;[o; ;[I"-#[]=: Sets the value for the given key; ;TI"Dthe given value may be a string, a symbol, an array, or a hash.;To;;0;[o; ;[I"A#add_field: Adds a given value to a value for the given key ;TI"*(not overwriting the existing value).;To;;0;[o; ;[I"2#delete: Deletes the field for the given key.;T@o; ;[I"Example field values:;T@o;;; ;[ o;;0;[o; ;[I" \String:;T@o;;[I"2req['Accept'] = 'text/html' # => "text/html" ;TI"2req['Accept'] # => "text/html" ;TI"4req.get_fields('Accept') # => ["text/html"] ;T;0o;;0;[o; ;[I" \Symbol:;T@o;;[I")req['Accept'] = :text # => :text ;TI"*req['Accept'] # => "text" ;TI",req.get_fields('Accept') # => ["text"] ;T;0o;;0;[o; ;[I"Simple array:;T@o;;[I"!req[:foo] = %w[bar baz bat] ;TI"/req[:foo] # => "bar, baz, bat" ;TI"5req.get_fields(:foo) # => ["bar", "baz", "bat"] ;T;0o;;0;[o; ;[I"Simple hash:;T@o;;[I"*req[:foo] = {bar: 0, baz: 1, bat: 2} ;TI"8req[:foo] # => "bar, 0, baz, 1, bat, 2" ;TI"Dreq.get_fields(:foo) # => ["bar", "0", "baz", "1", "bat", "2"] ;T;0o;;0;[o; ;[I"Nested:;T@o;;[I"1req[:foo] = [%w[bar baz], {bat: 0, bam: 1}] ;TI":req[:foo] # => "bar, baz, bat, 0, bam, 1" ;TI"Freq.get_fields(:foo) # => ["bar", "baz", "bat", "0", "bam", "1"] ;TI" ;TI";req[:foo] = {bar: %w[baz bat], bam: {bah: 0, bad: 1}} ;TI"Dreq[:foo] # => "bar, baz, bat, bam, bah, 0, bad, 1" ;TI"Treq.get_fields(:foo) # => ["bar", "baz", "bat", "bam", "bah", "0", "bad", "1"] ;T;0S;;i;I"Convenience Methods;T@o; ;[I"LVarious convenience methods retrieve values, set values, query values, ;TI"-set form values, or iterate over fields.;T@S;;i;I"Setters;T@o; ;[I"P\Method #[]= can set any field, but does little to validate the new value; ;TI">some of the other setter methods provide some validation:;T@o;;; ;[o;;0;[o; ;[I"<#[]=: Sets the string or array value for the given key.;To;;0;[o; ;[I"F#add_field: Creates or adds to the array value for the given key.;To;;0;[o; ;[I"T#basic_auth: Sets the string authorization header for <tt>'Authorization'</tt>.;To;;0;[o; ;[I"R#content_length=: Sets the integer length for field <tt>'Content-Length</tt>.;To;;0;[o; ;[I"M#content_type=: Sets the string value for field <tt>'Content-Type'</tt>.;To;;0;[o; ;[I"`#proxy_basic_auth: Sets the string authorization header for <tt>'Proxy-Authorization'</tt>.;To;;0;[o; ;[I";#set_range: Sets the value for field <tt>'Range'</tt>.;T@S;;i;I"Form Setters;T@o;;; ;[o;;0;[o; ;[I"+#set_form: Sets an HTML form data set.;To;;0;[o; ;[I"G#set_form_data: Sets header fields and a body from HTML form data.;T@S;;i;I"Getters;T@o; ;[ I"B\Method #[] can retrieve the value of any field that exists, ;TI"but always as a string; ;TI"Asome of the other getter methods return something different ;TI""from the simple string value:;T@o;;; ;[o;;0;[o; ;[I";#[]: Returns the string field value for the given key.;To;;0;[o; ;[I"S#content_length: Returns the integer value of field <tt>'Content-Length'</tt>.;To;;0;[o; ;[I"O#content_range: Returns the Range value of field <tt>'Content-Range'</tt>.;To;;0;[o; ;[I"N#content_type: Returns the string value of field <tt>'Content-Type'</tt>.;To;;0;[o; ;[I">#fetch: Returns the string field value for the given key.;To;;0;[o; ;[I"D#get_fields: Returns the array field value for the given +key+.;To;;0;[o; ;[I"Y#main_type: Returns first part of the string value of field <tt>'Content-Type'</tt>.;To;;0;[o; ;[I"Y#sub_type: Returns second part of the string value of field <tt>'Content-Type'</tt>.;To;;0;[o; ;[I"S#range: Returns an array of Range objects of field <tt>'Range'</tt>, or +nil+.;To;;0;[o; ;[I"d#range_length: Returns the integer length of the range given in field <tt>'Content-Range'</tt>.;To;;0;[o; ;[I"M#type_params: Returns the string parameters for <tt>'Content-Type'</tt>.;T@S;;i;I"Queries;T@o;;; ;[ o;;0;[o; ;[I"`#chunked?: Returns whether field <tt>'Transfer-Encoding'</tt> is set to <tt>'chunked'</tt>.;To;;0;[o; ;[I"`#connection_close?: Returns whether field <tt>'Connection'</tt> is set to <tt>'close'</tt>.;To;;0;[o; ;[I"j#connection_keep_alive?: Returns whether field <tt>'Connection'</tt> is set to <tt>'keep-alive'</tt>.;To;;0;[o; ;[I"/#key?: Returns whether a given key exists.;T@S;;i;I"Iterators;T@o;;; ;[ o;;0;[o; ;[I"S#each_capitalized: Passes each field capitalized-name/value pair to the block.;To;;0;[o; ;[I"M#each_capitalized_name: Passes each capitalized field name to the block.;To;;0;[o; ;[I"B#each_header: Passes each field name/value pair to the block.;To;;0;[o; ;[I"5#each_name: Passes each field name to the block.;To;;0;[o; ;[I">#each_value: Passes each string field value to the block.;T: @fileI"lib/net/http/header.rb;T:0@omit_headings_from_table_of_contents_below0;0;0[ [U:RDoc::Constant[i I"MAX_KEY_LENGTH;TI"$Net::HTTPHeader::MAX_KEY_LENGTH;T:public0o;;[ ;@�;0@�@cRDoc::NormalModule0U;[i I"MAX_FIELD_LENGTH;TI"&Net::HTTPHeader::MAX_FIELD_LENGTH;T;0o;;[ ;@�;0@�@@�0[ [[I" class;T[[;[ [:protected[ [:private[ [I" instance;T[[;[*[I"[];TI"lib/net/http/header.rb;T[I"[]=;T@�[I"add_field;T@�[I"basic_auth;T@�[I"canonical_each;T@�[I" chunked?;T@�[I"connection_close?;T@�[I"connection_keep_alive?;T@�[I"content_length;T@�[I"content_length=;T@�[I"content_range;T@�[I"content_type;T@�[I"content_type=;T@�[I"delete;T@�[I" each;T@�[I"each_capitalized;T@�[I"each_capitalized_name;T@�[I"each_header;T@�[I" each_key;T@�[I"each_name;T@�[I"each_value;T@�[I" fetch;T@�[I"form_data=;T@�[I"get_fields;T@�[I" key?;T@�[I"main_type;T@�[I"proxy_basic_auth;T@�[I" range;T@�[I"range=;T@�[I"range_length;T@�[I"set_content_type;T@�[I" set_form;T@�[I"set_form_data;T@�[I"set_range;T@�[I" sub_type;T@�[I"to_hash;T@�[I"type_params;T@�[;[ [;[ [I"append_field_value;T@�[I"basic_encode;T@�[I"capitalize;T@�[I"set_field;T@�[ [U:RDoc::Context::Section[i 0o;;[ ;0;0[@�I"Net;T@�