Skip to content

Commit

Permalink
Updates #520
Browse files Browse the repository at this point in the history
Updating TIdHTTPResponseInfo.SetResponseNo() to assign a default ResponseText string to every HTTP status code that is currently registered with IANA.
  • Loading branch information
rlebeau committed Jan 17, 2024
1 parent b994412 commit 36fcd79
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
44 changes: 43 additions & 1 deletion Lib/Protocols/IdCustomHTTPServer.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1918,6 +1918,9 @@ procedure TIdHTTPRequestInfo.DecodeAndSetParams(const AValue: String);
s := Copy(AValue, i, j-i);
// See RFC 1866 section 8.2.1. TP
s := ReplaceAll(s, '+', ' '); {do not localize}
// TODO: provide an event or property that lets the user specify
// which charset to use for converting the decoded Unicode characters
// to ANSI in pre-Unicode compilers...
Params.Add(TIdURI.URLDecode(s, LEncoding));
i := j + 1;
end;
Expand Down Expand Up @@ -2051,7 +2054,13 @@ procedure TIdHTTPResponseInfo.SetResponseNo(const AValue: Integer);
begin
FResponseNo := AValue;
case FResponseNo of
// 1XX: Informational
100: ResponseText := RSHTTPContinue;
101: ResponseText := RSHTTPSwitchingProtocols;
102: ResponseText := RSHTTPProcessing;
103: ResponseText := RSHTTPEarlyHints;
//104-199 are Unassigned

// 2XX: Success
200: ResponseText := RSHTTPOK;
201: ResponseText := RSHTTPCreated;
Expand All @@ -2060,15 +2069,28 @@ procedure TIdHTTPResponseInfo.SetResponseNo(const AValue: Integer);
204: ResponseText := RSHTTPNoContent;
205: ResponseText := RSHTTPResetContent;
206: ResponseText := RSHTTPPartialContent;
207: ResponseText := RSHTTPMultiStatus;
208: ResponseText := RSHTTPAlreadyReported;
//209-225 are Unassigned
226: ResponseText := RSHTTPIMUsed;
// 227-299 are Unassigned

// 3XX: Redirections
300: ResponseText := RSHTTPMultipleChoices;
301: ResponseText := RSHTTPMovedPermanently;
302: ResponseText := RSHTTPMovedTemporarily;
303: ResponseText := RSHTTPSeeOther;
304: ResponseText := RSHTTPNotModified;
305: ResponseText := RSHTTPUseProxy;
// 306 is Unused
307: ResponseText := RSHTTPTemporaryRedirect;
308: ResponseText := RSHTTPPermanentRedirect;
// 309-399 are Unassigned

// 4XX Client Errors
400: ResponseText := RSHTTPBadRequest;
401: ResponseText := RSHTTPUnauthorized;
402: ResponseText := RSHTTPPaymentRequired;
403: ResponseText := RSHTTPForbidden;
404: begin
ResponseText := RSHTTPNotFound;
Expand All @@ -2086,24 +2108,44 @@ procedure TIdHTTPResponseInfo.SetResponseNo(const AValue: Integer);
413: ResponseText := RSHTTPRequestEntityTooLong;
414: ResponseText := RSHTTPRequestURITooLong;
415: ResponseText := RSHTTPUnsupportedMediaType;
416: ResponseText := RSHTTPRangeNotSatisfiable;
417: ResponseText := RSHTTPExpectationFailed;
// 418 is Unused
// 419-420 are Unassigned
421: ResponseText := RSHTTPMisdirectedRequest;
422: ResponseText := RSHTTPUnprocessableContent;
423: ResponseText := RSHTTPLocked;
424: ResponseText := RSHTTPFailedDependency;
425: ResponseText := RSHTTPTooEarly;
426: ResponseText := RSHTTPUpgradeRequired;
// 427 is Unassigned
428: ResponseText := RSHTTPPreconditionRequired;
429: ResponseText := RSHTTPTooManyRequests;
// 430 is Unassigned
431: ResponseText := RSHTTPRequestHeaderFieldsTooLarge;
// 432-499 are Unassigned

// 5XX Server errors
500: ResponseText := RSHTTPInternalServerError;
501: ResponseText := RSHTTPNotImplemented;
502: ResponseText := RSHTTPBadGateway;
503: ResponseText := RSHTTPServiceUnavailable;
504: ResponseText := RSHTTPGatewayTimeout;
505: ResponseText := RSHTTPHTTPVersionNotSupported;
506: ResponseText := RSHTTPVariantAlsoNegotiates;
507: ResponseText := RSHTTPInsufficientStorage;
508: ResponseText := RSHTTPLoopDetected;
// 509 is Unassigned
510: ResponseText := RSHTTPNotExtended;
511: ResponseText := RSHTTPNetworkAuthenticationRequired;
// 512-599 are Unassigned

else
ResponseText := RSHTTPUnknownResponseCode;
end;

{if ResponseNo >= 400 then
// Force COnnection closing when there is error during the request processing
// Force Connection closing when there is error during the request processing
CloseConnection := true;
end;}
end;
Expand Down
20 changes: 20 additions & 0 deletions Lib/Protocols/IdResourceStringsProtocols.pas
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,29 @@ interface
RSHTTPChunkStarted = 'Chunk Started';
RSHTTPContinue = 'Continue';
RSHTTPSwitchingProtocols = 'Switching protocols';
RSHTTPProcessing = 'Processing';
RSHTTPEarlyHints = 'Early Hints';
RSHTTPOK = 'OK';
RSHTTPCreated = 'Created';
RSHTTPAccepted = 'Accepted';
RSHTTPNonAuthoritativeInformation = 'Non-authoritative Information';
RSHTTPNoContent = 'No Content';
RSHTTPResetContent = 'Reset Content';
RSHTTPPartialContent = 'Partial Content';
RSHTTPMultiStatus = 'Multi-Status';
RSHTTPAlreadyReported = 'Already Reported';
RSHTTPIMUsed = 'IM Used';
RSHTTPMultipleChoices = 'Multiple Choices';
RSHTTPMovedPermanently = 'Moved Permanently';
RSHTTPMovedTemporarily = 'Moved Temporarily';
RSHTTPSeeOther = 'See Other';
RSHTTPNotModified = 'Not Modified';
RSHTTPUseProxy = 'Use Proxy';
RSHTTPTemporaryRedirect = 'Temporary Redirect';
RSHTTPPermanentRedirect = 'Permanent Redirect';
RSHTTPBadRequest = 'Bad Request';
RSHTTPUnauthorized = 'Unauthorized';
RSHTTPPaymentRequired = 'Payment Required';
RSHTTPForbidden = 'Forbidden';
RSHTTPNotFound = 'Not Found';
RSHTTPMethodNotAllowed = 'Method not allowed';
Expand All @@ -247,13 +256,24 @@ interface
RSHTTPRequestEntityTooLong = 'Request Entity Too Long';
RSHTTPRequestURITooLong = 'Request-URI Too Long. 256 Chars max';
RSHTTPUnsupportedMediaType = 'Unsupported Media Type';
RSHTTPRangeNotSatisfiable = 'Range Not Satisfiable';
RSHTTPExpectationFailed = 'Expectation Failed';
RSHTTPMisdirectedRequest = 'Misdirected Request';
RSHTTPUnprocessableContent = 'Unprocessable Content';
RSHTTPLocked = 'Locked';
RSHTTPFailedDependency = 'Failed Dependency';
RSHTTPTooEarly = 'Too Early';
RSHTTPUpgradeRequired = 'Upgrade Required';
RSHTTPInternalServerError = 'Internal Server Error';
RSHTTPNotImplemented = 'Not Implemented';
RSHTTPBadGateway = 'Bad Gateway';
RSHTTPServiceUnavailable = 'Service Unavailable';
RSHTTPGatewayTimeout = 'Gateway timeout';
RSHTTPHTTPVersionNotSupported = 'HTTP version not supported';
RSHTTPVariantAlsoNegotiates = 'Variant Also Negotiates';
RSHTTPInsufficientStorage = 'Insufficient Storage';
RSHTTPLoopDetected = 'Loop Detected';
RSHTTPNotExtended = 'Not Extended';
RSHTTPUnknownResponseCode = 'Unknown Response Code';

// HTTP Other
Expand Down

0 comments on commit 36fcd79

Please sign in to comment.