Module: Ronin::Support::Network::HTTP::Request Private
- Defined in:
- lib/ronin/support/network/http/request.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Handles building HTTP request objects.
Constant Summary collapse
- METHODS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Request methods and
Net::HTTP
request classes. { copy: Net::HTTP::Copy, delete: Net::HTTP::Delete, get: Net::HTTP::Get, head: Net::HTTP::Head, lock: Net::HTTP::Lock, mkcol: Net::HTTP::Mkcol, move: Net::HTTP::Move, options: Net::HTTP::Options, patch: Net::HTTP::Patch, post: Net::HTTP::Post, propfind: Net::HTTP::Propfind, proppatch: Net::HTTP::Proppatch, put: Net::HTTP::Put, trace: Net::HTTP::Trace, unlock: Net::HTTP::Unlock }
Class Method Summary collapse
-
.build(method, path, query: nil, query_params: nil, user: nil, password: nil, headers: nil, user_agent: nil, cookie: nil, body: nil, form_data: nil) ⇒ Net::HTTP::Copy, ...
private
Creates a new
Net::HTTP
request. -
.request_uri(path, query: nil, query_params: nil) ⇒ String
private
Builds the [Request-URI], aka path + query string, for a HTTP request.
Class Method Details
.build(method, path, query: nil, query_params: nil, user: nil, password: nil, headers: nil, user_agent: nil, cookie: nil, body: nil, form_data: nil) ⇒ Net::HTTP::Copy, ...
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new Net::HTTP
request.
The HTTP request method to use.
The `User-Agent` header value for the request.
The built HTTP request object.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/ronin/support/network/http/request.rb', line 151 def self.build(method,path, # query string keyword arguments query: nil, query_params: nil, # Basic-Auth keyword arguments user: nil, password: nil, # Header keyword arguments headers: nil, user_agent: nil, cookie: nil, # request body keyword arguments body: nil, form_data: nil) request_class = METHODS.fetch(method) do raise(ArgumentError,"unknown HTTP request method: #{method.inspect}") end request = request_class.new( request_uri(path, query: query, query_params: query_params), headers ) if user user = user.to_s password = password.to_s if password request.basic_auth(user,password) end if user_agent request['User-Agent'] = case user_agent when Symbol then UserAgents[user_agent] else user_agent end end if && !.empty? request['Cookie'] = case when Hash then HTTP::Cookie.new().to_s else .to_s end end if form_data case form_data when String request.content_type = 'application/x-www-form-urlencoded' request.body = form_data else request.form_data = form_data end elsif body case body when IO, StringIO then request.body_stream = body else request.body = body end end return request end |
.request_uri(path, query: nil, query_params: nil) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Builds the Request-URI, aka path + query string, for a HTTP request.
Additional query params for the request.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ronin/support/network/http/request.rb', line 55 def self.request_uri(path, query: nil, query_params: nil) if query_params query = URI::QueryParams.dump(query_params) end if query # append the query-string onto the path path += if path.include?('?') then "&#{query}" else "?#{query}" end end return path end |