Class: Gridinit::Jmeter::HttpSampler
- Inherits:
-
Object
- Object
- Gridinit::Jmeter::HttpSampler
- Includes:
- Helper
- Defined in:
- lib/gridinit-jmeter/samplers/http_sampler.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
Returns the value of attribute doc.
Instance Method Summary collapse
- #fill_in(params) ⇒ Object
-
#initialize(name, url, params = {}) ⇒ HttpSampler
constructor
A new instance of HttpSampler.
- #parse_uri(url) ⇒ Object
- #parse_url(url, params) ⇒ Object
- #raw_body(params) ⇒ Object
Methods included from Helper
Constructor Details
#initialize(name, url, params = {}) ⇒ HttpSampler
Returns a new instance of HttpSampler.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gridinit-jmeter/samplers/http_sampler.rb', line 7 def initialize(name, url, params={}) @doc = Nokogiri::XML(" <HTTPSamplerProxy guiclass=\"HttpTestSampleGui\" testclass=\"HTTPSamplerProxy\" testname=\"\#{name}\" enabled=\"true\">\n <elementProp name=\"HTTPsampler.Arguments\" elementType=\"Arguments\" guiclass=\"HTTPArgumentsPanel\" testclass=\"Arguments\" testname=\"User Defined Variables\" enabled=\"true\">\n <collectionProp name=\"Arguments.arguments\"/>\n </elementProp>\n <stringProp name=\"HTTPSampler.domain\"></stringProp>\n <stringProp name=\"HTTPSampler.port\"></stringProp>\n <stringProp name=\"HTTPSampler.connect_timeout\"></stringProp>\n <stringProp name=\"HTTPSampler.response_timeout\"></stringProp>\n <stringProp name=\"HTTPSampler.protocol\"></stringProp>\n <stringProp name=\"HTTPSampler.contentEncoding\"></stringProp>\n <stringProp name=\"HTTPSampler.path\">/</stringProp>\n <stringProp name=\"HTTPSampler.method\">GET</stringProp>\n <boolProp name=\"HTTPSampler.follow_redirects\">true</boolProp>\n <boolProp name=\"HTTPSampler.auto_redirects\">false</boolProp>\n <boolProp name=\"HTTPSampler.use_keepalive\">true</boolProp>\n <boolProp name=\"HTTPSampler.DO_MULTIPART_POST\">false</boolProp>\n <boolProp name=\"HTTPSampler.monitor\">false</boolProp>\n <boolProp name=\"HTTPSampler.image_parser\">false</boolProp>\n <stringProp name=\"HTTPSampler.embedded_url_re\"></stringProp>\n <boolProp name=\"HTTPSampler.concurrentDwn\">false</boolProp>\n <stringProp name=\"HTTPSampler.concurrentPool\">4</stringProp>\n </HTTPSamplerProxy>\n EOF\n parse_url(url, params) unless url.empty?\n fill_in(params) if params[:fill_in]\n raw_body(params) if params[:raw_body]\n if params[:raw_path]\n params[:path] = url\n else\n params[:params] && params[:params].split('&').each do |param| \n name,value = param.split('=')\n fill_in({ :fill_in => { \"\#{name}\" => value }, :always_encode => params[:always_encode] })\n end\n end\n\n update params\nend\n".strip_heredoc) |
Instance Attribute Details
#doc ⇒ Object
Returns the value of attribute doc.
5 6 7 |
# File 'lib/gridinit-jmeter/samplers/http_sampler.rb', line 5 def doc @doc end |
Instance Method Details
#fill_in(params) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/gridinit-jmeter/samplers/http_sampler.rb', line 64 def fill_in(params) params[:fill_in].each do |name, value| @doc.at_xpath('//collectionProp') << Nokogiri::XML(" <elementProp name=\"\#{name}\" elementType=\"HTTPArgument\">\n <boolProp name=\"HTTPArgument.always_encode\">\#{params[:always_encode] ? 'true' : false}</boolProp>\n <stringProp name=\"Argument.value\">\#{value}</stringProp>\n <stringProp name=\"Argument.metadata\">=</stringProp>\n <boolProp name=\"HTTPArgument.use_equals\">true</boolProp>\n <stringProp name=\"Argument.name\">\#{name}</stringProp>\n </elementProp>\n EOF\n end\n params.delete :fill_in\nend\n".strip_heredoc).children |
#parse_uri(url) ⇒ Object
47 48 49 |
# File 'lib/gridinit-jmeter/samplers/http_sampler.rb', line 47 def parse_uri(url) URI.parse(URI::encode(url)).scheme.nil? ? URI.parse(URI::encode("http://#{url}")) : URI.parse(URI::encode(url)) end |
#parse_url(url, params) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/gridinit-jmeter/samplers/http_sampler.rb', line 51 def parse_url(url, params) if url[0] == '$' params[:path] = url # special case for named expressions else uri = parse_uri(url) params[:port] ||= uri.port unless URI.parse(URI::encode(url)).scheme.nil? params[:protocol] ||= uri.scheme unless URI.parse(URI::encode(url)).scheme.nil? params[:domain] ||= uri.host params[:path] ||= uri.path && URI::decode(uri.path) params[:params] ||= uri.query && URI::decode(uri.query) end end |
#raw_body(params) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/gridinit-jmeter/samplers/http_sampler.rb', line 80 def raw_body(params) @doc.at_xpath('//HTTPSamplerProxy') << Nokogiri::XML(" <boolProp name=\"HTTPSampler.postBodyRaw\">true</boolProp>\n EOF\n @doc.at_xpath('//collectionProp') << \n Nokogiri::XML(<<-EOF.strip_heredoc).children \n <elementProp name=\"\" elementType=\"HTTPArgument\">\n <boolProp name=\"HTTPArgument.always_encode\">false</boolProp>\n <stringProp name=\"Argument.value\">\#{params[:raw_body]}</stringProp>\n <stringProp name=\"Argument.metadata\">=</stringProp>\n </elementProp>\n EOF\n params.delete :raw_body\nend\n".strip_heredoc).children |