Ruby ã® http ã©ã¤ãã©ãªã®éä¿¡ã表示ãã http-dump ãä½ã£ã
ã
Ruby ä¸ã§ http ãå©ããéä¿¡è¦ããæã«ãæ¯ååãäºããã£ã¦ãã®ã§æ½è±¡åã㦠http-dump ã¨ããã©ã¤ãã©ãªãä½ã£ãã
$ gem install http-dump
require 'net/http' require 'uri' require 'http-dump' HTTPDump.dump { Net::HTTP.get(URI('http://example.com')) }
㨠http ã§ããã¨ããã¦ãã³ã¼ãã block ã§å²ãã¨ã以ä¸ã®ããã«åºåãããã
> GET http://example.com/ with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Host'=>'example.com', 'User-Agent'=>'Ruby'} < 200 OK < Accept-Ranges: bytes < Cache-Control: max-age=604800 < Content-Type: text/html < Date: Fri, 03 Jan 2014 13:42:51 GMT < Etag: "359670651" < Expires: Fri, 10 Jan 2014 13:42:51 GMT < Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT < Server: ECS (sjc/4FB4) < X-Cache: HIT < X-Ec-Custom-Error: 1 < Content-Length: 1270 < <!doctype html> <html> <head> <title>Example Domain</title> ... more ...
enable! / disable! ã§å ¨ä½çã«æå¹ã»ç¡å¹ãåãæ¿ããããã
require 'open-uri' require 'http-dump' HTTPDump.enable! open('http://example.com').read HTTPDump.disable!
Rails ãããªã
group :development do gem 'http-dump', require: ENV['HTTP_DUMP_ENABLE'] ? 'http-dump/enable' : 'http-dump' end
ã Gemfile ã«è¿½å ã
HTTP_DUMP_ENABLE=1 bundle exec rails s
㧠Rails ã¢ããªå é¨ããå©ãã¦ãã http ã®ããã¨ãã表示ãã¨ãã«ä½¿ããã
ãµãã¼ããã¦ã http ã®ã©ã¤ãã©ãªã¯ net/http ãã¼ã¹ã®ç©ãããã®ä» WebMock ã§ä½¿ããç©ãã¹ã¦ãhttp-dump ã®å é¨å®è£ ã¯å ¨ããããããã¨ã¯ãã£ã¦ç¡ãã¦ãWebMock ã®æ©è½ã«ã®ã£ã¦ãã ãã§ãã
ã©ãããå©ç¨ä¸ããã