class QUIC::Client
- QUIC::Client
- Reference
- Object
Defined in:
lsquic/client.crConstant 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
- .new(host : String, port = nil, tls : Bool | OpenSSL::SSL::Context::Client = false)
- .new(uri : URI, tls = nil)
- .new(uri : URI, tls = nil, &)
- .new(host : String, port = nil, tls = false, &)
Class Method Summary
- .delete(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response
- .delete(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &)
- .delete(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response
- .delete(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &)
- .exec(method, url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response
- .exec(method, url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &)
- .get(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response
- .get(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &)
- .get(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response
- .get(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &)
- .head(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response
- .head(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &)
- .head(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response
- .head(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &)
- .options(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response
- .options(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &)
- .options(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response
- .options(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &)
- .patch(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response
- .patch(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &)
- .patch(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response
- .patch(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &)
- .post(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response
- .post(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &)
- .post(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response
- .post(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &)
- .put(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response
- .put(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &)
- .put(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response
- .put(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &)
Instance Method Summary
-
#basic_auth(username, password)
Configures this client to perform basic authentication in every request.
- #before_request(&callback : HTTP::Request -> )
- #close
- #connect_timeout=(connect_timeout : Number)
- #connect_timeout=(connect_timeout : Time::Span)
- #delete(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response
- #delete(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, &)
- #delete(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response
- #delete(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO, &)
- #delete(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response
- #delete(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &)
- #destroy_engine
- #dns_timeout=(dns_timeout : Number)
- #dns_timeout=(dns_timeout : Time::Span)
- #exec(method : String, path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response
- #exec(request : HTTP::Request) : HTTP::Client::Response
- #exec(method : String, path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, &)
- #exec(request : HTTP::Request, &)
- #get(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response
- #get(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, &)
- #get(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response
- #get(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO, &)
- #get(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response
- #get(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &)
- #head(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response
- #head(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, &)
- #head(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response
- #head(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO, &)
- #head(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response
- #head(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &)
- #host : String
- #options(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response
- #options(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, &)
- #options(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response
- #options(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO, &)
- #options(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response
- #options(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &)
- #patch(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response
- #patch(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, &)
- #patch(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response
- #patch(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO, &)
- #patch(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response
- #patch(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &)
- #port : Int32
- #post(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response
- #post(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, &)
- #post(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response
- #post(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO, &)
- #post(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response
- #post(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &)
- #put(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response
- #put(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, &)
- #put(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response
- #put(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO, &)
- #put(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response
- #put(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &)
- #read_timeout=(read_timeout : Number)
- #read_timeout=(read_timeout : Time::Span)
- #run_engine
- #tls : OpenSSL::SSL::Context::Client
- #tls? : OpenSSL::SSL::Context::Client | Nil
Constructor Detail
Class Method Detail
def self.delete(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response
#
def self.delete(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &)
#
def self.delete(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response
#
def self.delete(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &)
#
def self.exec(method, url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response
#
def self.exec(method, url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &)
#
def self.get(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response
#
def self.get(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &)
#
def self.get(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response
#
def self.get(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &)
#
def self.head(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response
#
def self.head(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &)
#
def self.head(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response
#
def self.head(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &)
#
def self.options(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response
#
def self.options(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &)
#
def self.options(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response
#
def self.options(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &)
#
def self.patch(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response
#
def self.patch(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &)
#
def self.patch(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response
#
def self.patch(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &)
#
def self.post(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response
#
def self.post(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &)
#
def self.post(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response
#
def self.post(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &)
#
def self.put(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil) : HTTP::Client::Response
#
def self.put(url : String | URI, headers : HTTP::Headers | Nil = nil, body : BodyType = nil, tls = nil, &)
#
def self.put(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash) : HTTP::Client::Response
#
def self.put(url, headers : HTTP::Headers | Nil = nil, tls = nil, *, form : String | IO | Hash, &)
#
Instance Method Detail
def basic_auth(username, password)
#
Configures this client to perform basic authentication in every request.
def delete(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response
#
def delete(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response
#
def delete(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response
#
def delete(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &)
#
def exec(method : String, path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response
#
def get(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response
#
def get(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response
#
def get(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response
#
def get(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &)
#
def head(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response
#
def head(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response
#
def head(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response
#
def head(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &)
#
def options(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response
#
def options(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response
#
def options(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response
#
def options(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &)
#
def patch(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response
#
def patch(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response
#
def patch(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response
#
def patch(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &)
#
def post(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response
#
def post(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response
#
def post(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response
#
def post(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &)
#
def put(path, headers : HTTP::Headers | Nil = nil, body : BodyType = nil) : HTTP::Client::Response
#
def put(path, headers : HTTP::Headers | Nil = nil, *, form : String | IO) : HTTP::Client::Response
#
def put(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple) : HTTP::Client::Response
#
def put(path, headers : HTTP::Headers | Nil = nil, *, form : Hash(String, String) | NamedTuple, &)
#