Coverage Report

Created: 2026-02-14 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libsoup/libsoup/soup-status.c
Line
Count
Source
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2
/*
3
 * soup-status.c: Status code descriptions
4
 *
5
 * Copyright (C) 2001-2003, Ximian, Inc.
6
 */
7
8
#ifdef HAVE_CONFIG_H
9
#include <config.h>
10
#endif
11
12
#include "soup-status.h"
13
#include "soup.h"
14
15
/**
16
 * SOUP_STATUS_IS_INFORMATIONAL:
17
 * @status: an HTTP status code
18
 *
19
 * Tests if @status is an Informational (1xx) response.
20
 *
21
 * Returns: %TRUE or %FALSE
22
 **/
23
/**
24
 * SOUP_STATUS_IS_SUCCESSFUL:
25
 * @status: an HTTP status code
26
 *
27
 * Tests if @status is a Successful (2xx) response.
28
 *
29
 * Returns: %TRUE or %FALSE
30
 **/
31
/**
32
 * SOUP_STATUS_IS_REDIRECTION:
33
 * @status: an HTTP status code
34
 *
35
 * Tests if @status is a Redirection (3xx) response.
36
 *
37
 * Returns: %TRUE or %FALSE
38
 **/
39
/**
40
 * SOUP_STATUS_IS_CLIENT_ERROR:
41
 * @status: an HTTP status code
42
 *
43
 * Tests if @status is a Client Error (4xx) response.
44
 *
45
 * Returns: %TRUE or %FALSE
46
 **/
47
/**
48
 * SOUP_STATUS_IS_SERVER_ERROR:
49
 * @status: an HTTP status code
50
 *
51
 * Tests if @status is a Server Error (5xx) response.
52
 *
53
 * Returns: %TRUE or %FALSE
54
 **/
55
56
/**
57
 * SoupStatus:
58
 * @SOUP_STATUS_NONE: No status available. (Eg, the message has not
59
 * been sent yet)
60
 * @SOUP_STATUS_CONTINUE: 100 Continue (HTTP)
61
 * @SOUP_STATUS_SWITCHING_PROTOCOLS: 101 Switching Protocols (HTTP)
62
 * @SOUP_STATUS_PROCESSING: 102 Processing (WebDAV)
63
 * @SOUP_STATUS_OK: 200 Success (HTTP). Also used by many lower-level
64
 * soup routines to indicate success.
65
 * @SOUP_STATUS_CREATED: 201 Created (HTTP)
66
 * @SOUP_STATUS_ACCEPTED: 202 Accepted (HTTP)
67
 * @SOUP_STATUS_NON_AUTHORITATIVE: 203 Non-Authoritative Information
68
 * (HTTP)
69
 * @SOUP_STATUS_NO_CONTENT: 204 No Content (HTTP)
70
 * @SOUP_STATUS_RESET_CONTENT: 205 Reset Content (HTTP)
71
 * @SOUP_STATUS_PARTIAL_CONTENT: 206 Partial Content (HTTP)
72
 * @SOUP_STATUS_MULTI_STATUS: 207 Multi-Status (WebDAV)
73
 * @SOUP_STATUS_MULTIPLE_CHOICES: 300 Multiple Choices (HTTP)
74
 * @SOUP_STATUS_MOVED_PERMANENTLY: 301 Moved Permanently (HTTP)
75
 * @SOUP_STATUS_FOUND: 302 Found (HTTP)
76
 * @SOUP_STATUS_MOVED_TEMPORARILY: 302 Moved Temporarily (old name,
77
 * RFC 2068)
78
 * @SOUP_STATUS_SEE_OTHER: 303 See Other (HTTP)
79
 * @SOUP_STATUS_NOT_MODIFIED: 304 Not Modified (HTTP)
80
 * @SOUP_STATUS_USE_PROXY: 305 Use Proxy (HTTP)
81
 * @SOUP_STATUS_NOT_APPEARING_IN_THIS_PROTOCOL: 306 [Unused] (HTTP)
82
 * @SOUP_STATUS_TEMPORARY_REDIRECT: 307 Temporary Redirect (HTTP)
83
 * @SOUP_STATUS_PERMANENT_REDIRECT: 308 Permanent Redirect (HTTP)
84
 * @SOUP_STATUS_BAD_REQUEST: 400 Bad Request (HTTP)
85
 * @SOUP_STATUS_UNAUTHORIZED: 401 Unauthorized (HTTP)
86
 * @SOUP_STATUS_PAYMENT_REQUIRED: 402 Payment Required (HTTP)
87
 * @SOUP_STATUS_FORBIDDEN: 403 Forbidden (HTTP)
88
 * @SOUP_STATUS_NOT_FOUND: 404 Not Found (HTTP)
89
 * @SOUP_STATUS_METHOD_NOT_ALLOWED: 405 Method Not Allowed (HTTP)
90
 * @SOUP_STATUS_NOT_ACCEPTABLE: 406 Not Acceptable (HTTP)
91
 * @SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED: 407 Proxy Authentication
92
 * Required (HTTP)
93
 * @SOUP_STATUS_PROXY_UNAUTHORIZED: shorter alias for
94
 * %SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED
95
 * @SOUP_STATUS_REQUEST_TIMEOUT: 408 Request Timeout (HTTP)
96
 * @SOUP_STATUS_CONFLICT: 409 Conflict (HTTP)
97
 * @SOUP_STATUS_GONE: 410 Gone (HTTP)
98
 * @SOUP_STATUS_LENGTH_REQUIRED: 411 Length Required (HTTP)
99
 * @SOUP_STATUS_PRECONDITION_FAILED: 412 Precondition Failed (HTTP)
100
 * @SOUP_STATUS_REQUEST_ENTITY_TOO_LARGE: 413 Request Entity Too Large
101
 * (HTTP)
102
 * @SOUP_STATUS_REQUEST_URI_TOO_LONG: 414 Request-URI Too Long (HTTP)
103
 * @SOUP_STATUS_UNSUPPORTED_MEDIA_TYPE: 415 Unsupported Media Type
104
 * (HTTP)
105
 * @SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE: 416 Requested Range
106
 * Not Satisfiable (HTTP)
107
 * @SOUP_STATUS_INVALID_RANGE: shorter alias for
108
 * %SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE
109
 * @SOUP_STATUS_EXPECTATION_FAILED: 417 Expectation Failed (HTTP)
110
 * @SOUP_STATUS_MISDIRECTED_REQUEST: 421 Misdirected Request
111
 * @SOUP_STATUS_UNPROCESSABLE_ENTITY: 422 Unprocessable Entity
112
 * (WebDAV)
113
 * @SOUP_STATUS_LOCKED: 423 Locked (WebDAV)
114
 * @SOUP_STATUS_FAILED_DEPENDENCY: 424 Failed Dependency (WebDAV)
115
 * @SOUP_STATUS_INTERNAL_SERVER_ERROR: 500 Internal Server Error
116
 * (HTTP)
117
 * @SOUP_STATUS_NOT_IMPLEMENTED: 501 Not Implemented (HTTP)
118
 * @SOUP_STATUS_BAD_GATEWAY: 502 Bad Gateway (HTTP)
119
 * @SOUP_STATUS_SERVICE_UNAVAILABLE: 503 Service Unavailable (HTTP)
120
 * @SOUP_STATUS_GATEWAY_TIMEOUT: 504 Gateway Timeout (HTTP)
121
 * @SOUP_STATUS_HTTP_VERSION_NOT_SUPPORTED: 505 HTTP Version Not
122
 * Supported (HTTP)
123
 * @SOUP_STATUS_INSUFFICIENT_STORAGE: 507 Insufficient Storage
124
 * (WebDAV)
125
 * @SOUP_STATUS_NOT_EXTENDED: 510 Not Extended (RFC 2774)
126
 * 
127
 * These represent the known HTTP status code values, plus various
128
 * network and internal errors.
129
 *
130
 * Note that no libsoup functions take or return this type directly;
131
 * any function that works with status codes will accept unrecognized
132
 * status codes as well.
133
 **/
134
135
/* The reason_phrases are not localized because:
136
 *
137
 * 1. Only ASCII can be used portably in the HTTP Status-Line, so we
138
 *    would not be able to return localized reason phrases from
139
 *    SoupServer anyway.
140
 *
141
 * 2. Having a way for clients to get a localized version of a status
142
 *    code would just encourage them to present those strings to the
143
 *    user, which is bad because many of them are fairly
144
 *    incomprehensible anyway.
145
 */
146
147
static const struct {
148
  guint code;
149
  const char *phrase;
150
} reason_phrases [] = {
151
  /* Informational */
152
  { SOUP_STATUS_CONTINUE,                   "Continue" },
153
  { SOUP_STATUS_SWITCHING_PROTOCOLS,        "Switching Protocols" },
154
  { SOUP_STATUS_PROCESSING,                 "Processing" },
155
        { 103,                                    "Early Hints" },
156
157
  /* Success */
158
  { SOUP_STATUS_OK,                         "OK" },
159
  { SOUP_STATUS_CREATED,                    "Created" },
160
  { SOUP_STATUS_ACCEPTED,                   "Accepted" },
161
  { SOUP_STATUS_NON_AUTHORITATIVE,          "Non-Authoritative Information" },
162
  { SOUP_STATUS_NO_CONTENT,                 "No Content" },
163
  { SOUP_STATUS_RESET_CONTENT,              "Reset Content" },
164
  { SOUP_STATUS_PARTIAL_CONTENT,            "Partial Content" },
165
  { SOUP_STATUS_MULTI_STATUS,               "Multi-Status" },
166
167
  /* Redirection */
168
  { SOUP_STATUS_MULTIPLE_CHOICES,           "Multiple Choices" },
169
  { SOUP_STATUS_MOVED_PERMANENTLY,          "Moved Permanently" },
170
  { SOUP_STATUS_FOUND,                      "Found" },
171
  { SOUP_STATUS_SEE_OTHER,                  "See Other" },
172
  { SOUP_STATUS_NOT_MODIFIED,               "Not Modified" },
173
  { SOUP_STATUS_USE_PROXY,                  "Use Proxy" },
174
  { SOUP_STATUS_TEMPORARY_REDIRECT,         "Temporary Redirect" },
175
        { SOUP_STATUS_PERMANENT_REDIRECT,         "Permanent Redirect" },
176
177
  /* Client error */
178
  { SOUP_STATUS_BAD_REQUEST,                "Bad Request" },
179
  { SOUP_STATUS_UNAUTHORIZED,               "Unauthorized" },
180
  { SOUP_STATUS_PAYMENT_REQUIRED,           "Payment Required" },
181
  { SOUP_STATUS_FORBIDDEN,                  "Forbidden" },
182
  { SOUP_STATUS_NOT_FOUND,                  "Not Found" },
183
  { SOUP_STATUS_METHOD_NOT_ALLOWED,         "Method Not Allowed" },
184
  { SOUP_STATUS_NOT_ACCEPTABLE,             "Not Acceptable" },
185
  { SOUP_STATUS_PROXY_UNAUTHORIZED,         "Proxy Authentication Required" },
186
  { SOUP_STATUS_REQUEST_TIMEOUT,            "Request Timeout" },
187
  { SOUP_STATUS_CONFLICT,                   "Conflict" },
188
  { SOUP_STATUS_GONE,                       "Gone" },
189
  { SOUP_STATUS_LENGTH_REQUIRED,            "Length Required" },
190
  { SOUP_STATUS_PRECONDITION_FAILED,        "Precondition Failed" },
191
  { SOUP_STATUS_REQUEST_ENTITY_TOO_LARGE,   "Request Entity Too Large" },
192
  { SOUP_STATUS_REQUEST_URI_TOO_LONG,       "Request-URI Too Long" },
193
  { SOUP_STATUS_UNSUPPORTED_MEDIA_TYPE,     "Unsupported Media Type" },
194
  { SOUP_STATUS_INVALID_RANGE,              "Requested Range Not Satisfiable" },
195
  { SOUP_STATUS_EXPECTATION_FAILED,         "Expectation Failed" },
196
  { SOUP_STATUS_UNPROCESSABLE_ENTITY,       "Unprocessable Entity" },
197
  { SOUP_STATUS_LOCKED,                     "Locked" },
198
  { SOUP_STATUS_FAILED_DEPENDENCY,          "Failed Dependency" },
199
200
  /* Server error */
201
  { SOUP_STATUS_INTERNAL_SERVER_ERROR,      "Internal Server Error" },
202
  { SOUP_STATUS_NOT_IMPLEMENTED,            "Not Implemented" },
203
  { SOUP_STATUS_BAD_GATEWAY,                "Bad Gateway" },
204
  { SOUP_STATUS_SERVICE_UNAVAILABLE,        "Service Unavailable" },
205
  { SOUP_STATUS_GATEWAY_TIMEOUT,            "Gateway Timeout" },
206
  { SOUP_STATUS_HTTP_VERSION_NOT_SUPPORTED, "HTTP Version Not Supported" },
207
  { SOUP_STATUS_INSUFFICIENT_STORAGE,       "Insufficient Storage" },
208
  { SOUP_STATUS_NOT_EXTENDED,               "Not Extended" },
209
210
  { 0 }
211
};
212
213
/**
214
 * soup_status_get_phrase:
215
 * @status_code: an HTTP status code
216
 *
217
 * Looks up the stock HTTP description of @status_code.
218
 *
219
 * *There is no reason for you to ever use this
220
 * function.* If you wanted the textual description for the
221
 * [property@Message:status-code] of a given [class@Message], you should just
222
 * look at the message's [property@Message:reason-phrase]. However, you
223
 * should only do that for use in debugging messages; HTTP reason
224
 * phrases are not localized, and are not generally very descriptive
225
 * anyway, and so they should never be presented to the user directly.
226
 * Instead, you should create you own error messages based on the
227
 * status code, and on what you were trying to do.
228
 *
229
 * Returns: the (terse, English) description of @status_code
230
 **/
231
const char *
232
soup_status_get_phrase (guint status_code)
233
0
{
234
0
  int i;
235
236
0
  for (i = 0; reason_phrases [i].code; i++) {
237
0
    if (reason_phrases [i].code == status_code)
238
0
      return reason_phrases [i].phrase;
239
0
  }
240
241
0
  return "Unknown Error";
242
0
}
243
244
/**
245
 * SoupHTTPVersion:
246
 * @SOUP_HTTP_1_0: HTTP 1.0 (RFC 1945)
247
 * @SOUP_HTTP_1_1: HTTP 1.1 (RFC 2616)
248
 * @SOUP_HTTP_2_0: HTTP 2.0 (RFC 7540)
249
 *
250
 * Indicates the HTTP protocol version being used.
251
 */