Commit 2beedadcc2f3aa78a6e42cdc0503314a927ff880
1 parent
8b3737e9
Exists in
master
and in
2 other branches
Create teste.rb, in this file we have the ideia for test our REMOTE_USER
Showing
1 changed file
with
29 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
1 | +# references: http://ruby-doc.org/stdlib-2.1.1/libdoc/net/http/rdoc/Net/HTTPHeader.html#method-i-add_field | ||
2 | +# import the netHTTP | ||
3 | +require 'net/http' | ||
4 | + | ||
5 | +# uri get the url http headers | ||
6 | +uri = URI('http://google.com') | ||
7 | + | ||
8 | +# new request and result the http_readers | ||
9 | +http_request = Net::HTTP::Get.new(uri) | ||
10 | + | ||
11 | +# o metodo each_header retorna um map com o nome do header e o conteudo | ||
12 | +http_request.each_header { |header,value| puts header + " " + value } | ||
13 | +#http_request.set_form_data({"REMOTE_USER" => "siqueira"}) | ||
14 | +#http_request.set_form_data({"q" => "ruby", "lang" => "en"}, ';') | ||
15 | + | ||
16 | +### add_field adicona um campo novo ou seja um novo HTTP_HEADER no nosso caso o REMOTE_USER | ||
17 | +http_request.add_field 'REMOTE_USER', 'siqueira' | ||
18 | + | ||
19 | +# Com o get_field podemos pegar o conteudo do header REMOTE_USER | ||
20 | +puts http_request.get_fields('REMOTE_USER') | ||
21 | + | ||
22 | +# => accept-encoding | ||
23 | +# => accept | ||
24 | +# => user-agent | ||
25 | +# => host | ||
26 | + | ||
27 | +http_response = Net::HTTP.start(uri.hostname, uri.port) do |http| | ||
28 | + http.request(http_request) | ||
29 | +end |