class QUIC::Client

Defined in:

lsquic/client.cr

Constant Summary

EA_PACKETS_OUT = ->(peer_ctx : ::Pointer(Void), specs : ::Pointer(LibLsquic::OutSpec), count : LibC::UInt) do packets_out = 0 count.times do |i| spec = specs[i] socket = Box(UDPSocket).unbox(spec.peer_ctx) spec.iovlen.times do |j| iov = spec.iov[j] begin socket.send(iov.iov_base.to_slice(iov.iov_len), to: socket.remote_address) packets_out = packets_out + 1 rescue ex end end end packets_out end
ENGINE_FLAGS = LibLsquic::LSENG_HTTP
ON_CLOSE = ->(s : LibLsquic::StreamT, stream_if_ctx : ::Pointer(Void)) do stream_ctx = Box(StreamCtx).unbox(stream_if_ctx) stream_ctx.io.close Box.box(stream_ctx) end
ON_NEW_STREAM = ->(stream_if_ctx : ::Pointer(Void), s : LibLsquic::StreamT) do stream_ctx = (LibLsquic.stream_conn(s)).try do |c| LibLsquic.conn_get_ctx(c) end.try do |c| Box(StreamCtx).unbox(c) end if (LibLsquic.stream_is_pushed(s)) != 0 return Box.box(stream_ctx) end LibLsquic.stream_wantwrite(s, 1) Box.box(stream_ctx) end
ON_READ = ->(s : LibLsquic::StreamT, stream_if_ctx : ::Pointer(Void)) do stream_ctx = Box(StreamCtx).unbox(stream_if_ctx) bytes_read = LibLsquic.stream_readf(s, STREAM_READF, Box.box(stream_ctx)) if bytes_read > 0 else if bytes_read == 0 LibLsquic.stream_shutdown(s, 0) LibLsquic.stream_wantread(s, 0) else if (LibLsquic.stream_is_rejected(s)) == 1 LibLsquic.stream_close(s) else "Could not read response" end end end Box.box(stream_ctx) end
ON_WRITE = ->(s : LibLsquic::StreamT, stream_if_ctx : ::Pointer(Void)) do stream_ctx = Box(StreamCtx).unbox(stream_if_ctx) headers = [] of LibLsquic::HttpHeader (stream_ctx.request.headers.to_a.sort_by do |k, v| ({":authority", ":path", ":scheme", ":method"}.index(k)) || -1 end).reverse.each do |tuple| name, values = tuple name = name.downcase values.each do |value| name_vec = LibLsquic::Iovec.new name_vec.iov_base = name.to_slice name_vec.iov_len = name.bytesize value_vec = LibLsquic::Iovec.new value_vec.iov_base = value.to_slice value_vec.iov_len = value.bytesize header = LibLsquic::HttpHeader.new header.name = name_vec header.value = value_vec headers << header end end http_headers = LibLsquic::HttpHeaders.new http_headers.count = headers.size http_headers.headers = headers.to_unsafe if (LibLsquic.stream_send_headers(s, pointerof(http_headers), stream_ctx.request.body ? 0 : 1)) != 0 raise("Could not send headers") end if stream_ctx.request.body body = stream_ctx.request.body.not_nil!.gets_to_end LibLsquic.stream_write(s, body, body.bytesize) LibLsquic.stream_flush(s) end LibLsquic.stream_shutdown(s, 1) LibLsquic.stream_wantwrite(s, 0) LibLsquic.stream_wantread(s, 1) Box.box(stream_ctx) end
STREAM_READF = ->(stream_if_ctx : ::Pointer(Void), buf : ::Pointer(UInt8), buf_len : LibC::SizeT, fin : LibC::Int) do stream_ctx = Box(StreamCtx).unbox(stream_if_ctx) bytes_read = stream_ctx.io.unbuffered_write(Slice.new(buf, buf_len)) bytes_read.to_u64 end

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(host : String, port = nil, tls : Bool | OpenSSL::SSL::Context::Client = false) #

[View source]
def self.new(uri : URI, tls = nil) #

[View source]
def self.new(uri : URI, tls = nil, &) #

[View source]
def self.new(host : String, port = nil, tls = false, &) #

[View source]

Class Method Detail

def self.delete(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response #

[View source]
def self.delete(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &) #

[View source]
def self.delete(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response #

[View source]
def self.delete(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &) #

[View source]
def self.exec(method, url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response #

[View source]
def self.exec(method, url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &) #

[View source]
def self.get(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response #

[View source]
def self.get(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &) #

[View source]
def self.get(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response #

[View source]
def self.get(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &) #

[View source]
def self.head(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response #

[View source]
def self.head(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &) #

[View source]
def self.head(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response #

[View source]
def self.head(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &) #

[View source]
def self.options(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response #

[View source]
def self.options(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &) #

[View source]
def self.options(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response #

[View source]
def self.options(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &) #

[View source]
def self.patch(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response #

[View source]
def self.patch(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &) #

[View source]
def self.patch(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response #

[View source]
def self.patch(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &) #

[View source]
def self.post(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response #

[View source]
def self.post(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &) #

[View source]
def self.post(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response #

[View source]
def self.post(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &) #

[View source]
def self.put(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response #

[View source]
def self.put(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &) #

[View source]
def self.put(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response #

[View source]
def self.put(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &) #

[View source]

Instance Method Detail

def basic_auth(username, password) #

Configures this client to perform basic authentication in every request.


[View source]
def before_request(&callback : HTTP::Request -> ) #

[View source]
def close #

[View source]
def connect_timeout=(connect_timeout : Number) #

[View source]
def connect_timeout=(connect_timeout : Time::Span) #

[View source]
def delete(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response #

[View source]
def delete(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, &) #

[View source]
def delete(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response #

[View source]
def delete(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO, &) #

[View source]
def delete(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response #

[View source]
def delete(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &) #

[View source]
def destroy_engine #

[View source]
def dns_timeout=(dns_timeout : Number) #

[View source]
def dns_timeout=(dns_timeout : Time::Span) #

[View source]
def exec(method : String, path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response #

[View source]
def exec(request : HTTP::Request) : HTTP::Client::Response #

[View source]
def exec(method : String, path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, &) #

[View source]
def exec(request : HTTP::Request, &) #

[View source]
def get(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response #

[View source]
def get(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, &) #

[View source]
def get(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response #

[View source]
def get(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO, &) #

[View source]
def get(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response #

[View source]
def get(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &) #

[View source]
def head(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response #

[View source]
def head(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, &) #

[View source]
def head(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response #

[View source]
def head(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO, &) #

[View source]
def head(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response #

[View source]
def head(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &) #

[View source]
def host : String #

[View source]
def options(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response #

[View source]
def options(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, &) #

[View source]
def options(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response #

[View source]
def options(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO, &) #

[View source]
def options(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response #

[View source]
def options(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &) #

[View source]
def patch(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response #

[View source]
def patch(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, &) #

[View source]
def patch(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response #

[View source]
def patch(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO, &) #

[View source]
def patch(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response #

[View source]
def patch(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &) #

[View source]
def port : Int32 #

[View source]
def post(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response #

[View source]
def post(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, &) #

[View source]
def post(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response #

[View source]
def post(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO, &) #

[View source]
def post(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response #

[View source]
def post(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &) #

[View source]
def put(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response #

[View source]
def put(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, &) #

[View source]
def put(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response #

[View source]
def put(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO, &) #

[View source]
def put(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response #

[View source]
def put(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &) #

[View source]
def read_timeout=(read_timeout : Number) #

[View source]
def read_timeout=(read_timeout : Time::Span) #

[View source]
def run_engine #

[View source]
def tls : OpenSSL::SSL::Context::Client #

[View source]
def tls? : OpenSSL::SSL::Context::Client | Nil #

[View source]