-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhttp.rb
More file actions
124 lines (114 loc) · 4.05 KB
/
http.rb
File metadata and controls
124 lines (114 loc) · 4.05 KB
1
2
3
4
5
6
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# frozen_string_literal: true
module Wreq
# HTTP method enumeration backed by Rust.
#
# Variants are exposed as constants under this class.
# Each constant is an instance of {Wreq::Method}.
#
# @example Using predefined constants
# method = Wreq::Method::GET
# method.class #=> Wreq::Method
#
# @example In request context
# Wreq.request(url: "https://api.example.com", method: Wreq::Method::POST)
class Method
# Constants are set by the native extension at initialization.
# These stubs are for documentation only.
unless const_defined?(:GET)
GET = nil # @return [Wreq::Method] HTTP GET method
HEAD = nil # @return [Wreq::Method] HTTP HEAD method
POST = nil # @return [Wreq::Method] HTTP POST method
PUT = nil # @return [Wreq::Method] HTTP PUT method
DELETE = nil # @return [Wreq::Method] HTTP DELETE method
OPTIONS = nil # @return [Wreq::Method] HTTP OPTIONS method
TRACE = nil # @return [Wreq::Method] HTTP TRACE method
PATCH = nil # @return [Wreq::Method] HTTP PATCH method
end
end
# HTTP version enumeration backed by Rust.
#
# @example Using predefined constants
# version = Wreq::Version::HTTP_11
# version.class #=> Wreq::Version
class Version
# Constants are set by the native extension at initialization.
# These stubs are for documentation only.
unless const_defined?(:HTTP_11)
HTTP_09 = nil # @return [Wreq::Version] HTTP/0.9
HTTP_10 = nil # @return [Wreq::Version] HTTP/1.0
HTTP_11 = nil # @return [Wreq::Version] HTTP/1.1
HTTP_2 = nil # @return [Wreq::Version] HTTP/2
HTTP_3 = nil # @return [Wreq::Version] HTTP/3
end
# Returns a string representation of the HTTP version.
# @return [String] HTTP version as string
unless method_defined?(:to_s)
def to_s; end
end
end
# HTTP status code wrapper.
#
# This class wraps standard HTTP status codes and provides
# convenient methods to check the response category.
#
# The actual implementation is provided by Rust for performance.
#
# @example Check if response is successful
# status = response.status
# if status.success?
# puts "Request succeeded with code: #{status.as_int}"
# end
#
# @example Check different status categories
# status.informational? # 1xx
# status.success? # 2xx
# status.redirection? # 3xx
# status.client_error? # 4xx
# status.server_error? # 5xx
unless const_defined?(:StatusCode)
class StatusCode
# Returns the status code as an integer.
#
# @return [Integer] the numeric HTTP status code (100-599)
def as_int; end
# Checks if status code is informational (1xx).
#
# Informational responses indicate that the request was received
# and the process is continuing.
#
# @return [Boolean] true if status is 100-199
def informational?; end
# Checks if status code indicates success (2xx).
#
# Success responses indicate that the request was successfully
# received, understood, and accepted.
#
# @return [Boolean] true if status is 200-299
def success?; end
# Checks if status code indicates redirection (3xx).
#
# Redirection responses indicate that further action needs to be
# taken to complete the request.
#
# @return [Boolean] true if status is 300-399
def redirection?; end
# Checks if status code indicates client error (4xx).
#
# Client error responses indicate that the request contains bad
# syntax or cannot be fulfilled.
#
# @return [Boolean] true if status is 400-499
def client_error?; end
# Checks if status code indicates server error (5xx).
#
# Server error responses indicate that the server failed to
# fulfill a valid request.
#
# @return [Boolean] true if status is 500-599
def server_error?; end
# Returns a string representation of the status code.
# @return [String] Status code as string
def to_s; end
end
end
end