Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/proto/nuuo/client_request.rb
Views: 11704
# -*- coding: binary -*-12module Rex3module Proto4module Nuuo56class ClientRequest78DefaultConfig = {9#10# Nuuo stuff11#12'method' => 'USERLOGIN',13'server_version' => nil,14'data' => nil,15'headers' => nil,16'proto' => 'NUCM',17'version' => '1.0',18'file_name' => nil,19'file_type' => nil,20'user_session' => nil,21}2223attr_reader :opts2425def initialize(opts={})26@opts = DefaultConfig.merge(opts)27@opts['headers'] ||= {}28end2930def to_s31# Set default header: <method> <proto/version>32req = ''33req << set_method34req << ' '35req << set_proto_version3637# Set headers38req << set_header('server_version', 'Version')39req << set_header('user_session', 'User-Session-No')4041# Add any additional headers42req << set_extra_headers4344# Set data45req << set_body46end4748def set_method49"#{opts['method']}"50end5152def set_proto_version53"#{opts['proto']}/#{opts['version']}\r\n"54end5556#57# Return <name> header58#59def set_header(key, name)60unless opts['headers'] && opts['headers'].keys.map(&:downcase).include?(name.downcase)61return opts[key] ? set_formatted_header(name, opts[key]) : ''62end63''64end6566# Return additional headers67#68def set_extra_headers69buf = ''70opts['headers'].each_pair do |var,val|71buf << set_formatted_header(var,val)72end7374buf75end7677def set_body78return "\r\n#{opts['data']}"79end8081def set_formatted_header(var, val)82"#{var}: #{val}\r\n"83end8485end86end87end88end899091