1
0
Fork 0

🧑‍💻 Added joke HTTP status codes

This commit is contained in:
Maxim Lebedev 2024-03-17 04:39:18 +05:00
parent 51b6e24e96
commit 872d5babb5
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
3 changed files with 357 additions and 0 deletions

91
net/http/267.go Normal file
View File

@ -0,0 +1,91 @@
package http
// This status code is primary meant to be used in REST API interactions as an
// issued warning related to the request itself. Since in regular GET requests
// there are no direct ways of telling the client about a potential mistake in
// the request without altering the response body, the only way to notify the
// client is using a custom HTTP header.
//
// However, many client-side libraries and applications are silently ignoring
// all non-important headers, which would ultimately hide such warning from the
// actual client code logic, unless the programmer directly checks the known
// header.
//
// But in cases when the server responds with "267 Questionable But Okay", the
// request status code becomes obvious. There are a lot of implementations that
// expect the response code to be strictly equal to "200 OK" and thus would
// consider the potentially erroneous request as failed indeed, bringing
// developers' attention to the underlying problem.
//
// From the practical point of view, the server may return 267 status code for
// GET requests each time it determines that the particular request is not
// coming from an official or fully conforming REST client. Small differences in
// implementation of client logic might make this client application to stand
// out from the behavior patterns of official clients:
//
// - Absence of a GET parameter that is always sent by official clients in
// cases when the server can tolerate its absence and still fulfil the
// request based on other available information
// (e.g. "/getPhoto?album_id=421&photo_index=NaN" might fallback to photo_index=0)
// - Duplication of a GET parameter or receiving GET parameters in an
// unexpected order in cases where the order of those parameters has a
// semantic meaning for this particular API endpoint and the server logic
// has valid reasons to specifically check for this
// (e.g. "/getPhoto?photo_index=3&album_id=421&photo_index=3")
// - Presence of a GET parameter that has a special meaning for other API
// endpoints in cases when this parameter otherwise involves a different
// processing on the server that is not required for this particular
// endpoint (e.g. "/getPhoto?album_id=421&photo_index=3&user_token=abcdef")
// - Presence of a HTTP header that has a special meaning for other API
// endpoints and requires a special processing that cannot be applied for
// this particular request (e.g. "Authorization: Basic YmFzZTY0")
//
// This status code should be related only to this particular requests,
// indicating a discrepancy in logic that formed it. It should not be used to
// indicate a questionable series of requests made by client (e.g. wrong order
// of API calls).
// Also it is not advisable to use it with POST requests that return an
// application-defined data structure, since it is naturally to include any
// warnings or hints directly in the POST body.
//
// Generally, a received "267 Questionable But Okay" status code indicates that
// the server warns the client that the request is identified as non-genuine but
// otherwise conforming to web standards. It may be silently ignored or
// converted to "200 OK" on the client side in case the programmer
// deliberatively wants to simplify the code and generalize the interactions
// with server API.
//
// However, its highly advisable to log all 267 responses in fully conforming
// client because it indicates a potential bug in request logic. A conforming
// client should be prepared to receive 267 statuses for any REST call to the
// server that is known to issue them, but must not treat them as fatal errors.
//
// A third-party client that had strict checks for equality to status code 200
// would essentially fail the questionable request, bringing developers'
// attention to the fact that the logic could be buggy, and the code should be
// modified according to changes in official conforming applications, or updated
// to ignore them, accepting the fact that the server is not happy.
//
// If a request resulted in 267 response, then any subsequent request with the
// same parameters should also return 267 status code unless the server state
// was changed in a way that even a genuine request would have been resulted in
// a different status code too.
//
// See: https://github.com/maximal/http-267/issues/1#issuecomment-2000395105
//
// 267 code can be used as a soft deprecation warning for this particular API
// endpoint and its passed or omitted parameters. Example: API version ?v= is
// not passed and defaults to the latest version before addition of explicit
// versioning, that is expected to be shut down soon.
//
// If the updated server decides that a particular cause of 267 is no longer can
// be tolerated, it may start to return "422 Unprocessable Entity" instead, as a
// refusal to support this deprecated API call.
//
// For example: Notification for the client that performs some extra work which
// is not required for this particular API call (e.g. it sends a header with
// cryptographically signed URL parameters even for requests that do not need to
// be signed, contrary to other API calls that may require it).
//
// See: https://github.com/maximal/http-267/issues/1#issuecomment-2000599066
const StatusQuestionableButOkay = 267

97
net/http/7xx.go Normal file
View File

@ -0,0 +1,97 @@
package http
// 700 HTTP status code series as known unknowns.
// See: https://github.com/joho/7XX-rfc
const (
// Inexcusable
StatusMeh = 701
StatusEmacs = 702
StatusExplosion = 703
StatusGotoFail = 704
StatusIWroteTheCodeAndMissedTheNecessaryValidationByAnOversight = 705 // See [StatusHeartbleed]
StatusDeleteYourAccount = 706
StatusCantQuitVi = 707
// Novelty Implementations
StatusPHP = 710
StatusConvenienceStore = 711
StatusNoSQL = 712
StatusIAmNotATeapot = 718
StatusHaskell = 719
// Edge Cases
StatusUnpossible = 720
StatusKnownUnknowns = 721
StatusUnknownUnknowns = 722
StatusTricky = 723
StatusThisLineShouldBeUnreachable = 724
StatusItWorksOnMyMachine = 725
StatusItsAFeatureNotABug = 726
Status32BitsIsPlenty = 727
StatusItWorksInMyTimezone = 728
// Fucking
StatusFuckingNpm = 730
StatusFuckingRubygems = 731
StatusFuckingUnicode = 732
StatusFuckingDeadlocks = 733
StatusFuckingDeferreds = 734
StatusFuckingRaceConditions = 736
StatusFuckingIE = 735
StatusFuckThreadsing = 737
StatusFuckingExactlyOnceDelivery = 738
StatusFuckingWindows = 739
// Syntax Errors
StatusDidntBotherToCompileIt = 750
StatusSyntaxError = 753
StatusTooManySemiColons = 754
StatusNotEnoughSemiColons = 755
StatusInsufficientlyPolite = 756
StatusExcessivelyPolite = 757
StatusUnexpectedT_PAAMAYIM_NEKUDOTAYIM = 759
// Substance-Affected Developer
StatusHungover = 761
StatusStoned = 762
StatusUnderCaffeinated = 763
StatusOverCaffeinated = 764
StatusRailscamp = 765
StatusSober = 766
StatusDrunk = 767
StatusAccidentallyTookSleepingPillsInsteadOfMigrainePillsDuringCrunchWeek = 768
// Predictable Problems
StatusCachedForTooLong = 771
StatusNotCachedLongEnough = 772
StatusNotCachedAtAll = 773
StatusWhyWasThisCached = 774
StatusOutOfCash = 775
StatusErrorOnTheException = 776
StatusCoincidence = 777
StatusOffByOneError = 778
StatusOffByTooManyToCountError = 779
// Somebody Else's Problem
StatusProjectOwnerNotResponding = 780
StatusOperations = 781
StatusQA = 782
StatusItWasACustomerRequestHonestly = 783
StatusManagementObviously = 784
StatusTPSCoverSheetNotAttached = 785
StatusTryItNow = 786
StatusFurtherFundingRequired = 787
StatusDesignersFinalDesignsWerent = 788
StatusNotMyDepartment = 789
// Internet crashed
StatusTheInternetShutDownDueToCopyrightRestrictions = 791
StatusClimateChangeDrivenCatastrophicWeatherEvent = 792
StatusZombieApocalypse = 793
StatusSomeoneLetPGNearAREPL = 794
StatusHeartbleed = 795 // See [StatusIWroteTheCodeAndMissedTheNecessaryValidationByAnOversight]
StatusSomeDNSFuckeryIdno = 796
StatusThisIsTheLastPageOfTheInternetGoBack = 797
StatusICheckedTheDbBackupsCupboardAndTheCupboardWasBare = 798
StatusEndOfTheWorld = 799
)

169
net/http/http.go Normal file
View File

@ -0,0 +1,169 @@
// Package http contains utilities, jokes and helpers for manipulate HTTP data
// in clients and servers.
package http
import "net/http"
// StatusText wraps native [net/http.StatusText], but considers the status codes
// provided in this package before referring to the standard ones.
func StatusText(code int) string {
switch code {
default:
// Reserved for meritocracy related bullshit
if StatusFuckingWindows < code && code < StatusDidntBotherToCompileIt {
return "TBD. Got the brains trust on the case."
}
return http.StatusText(code)
case StatusQuestionableButOkay:
return "Questionable But Okay"
case StatusMeh:
return "Meh"
case StatusEmacs:
return "Emacs"
case StatusExplosion:
return "Explosion"
case StatusGotoFail:
return "Goto Fail"
case StatusIWroteTheCodeAndMissedTheNecessaryValidationByAnOversight:
return "I wrote the code and missed the necessary validation by an oversight"
case StatusDeleteYourAccount:
return "Delete Your Account"
case StatusCantQuitVi:
return "Can't quit vi"
case StatusPHP:
return "PHP"
case StatusConvenienceStore:
return "Convenience Store"
case StatusNoSQL:
return "NoSQL"
case StatusIAmNotATeapot:
return "I am not a teapot"
case StatusHaskell:
return "Haskell"
case StatusUnpossible:
return "Unpossible"
case StatusKnownUnknowns:
return "Known Unknowns"
case StatusUnknownUnknowns:
return "Unknown Unknowns"
case StatusTricky:
return "Tricky"
case StatusThisLineShouldBeUnreachable:
return "This line should be unreachable"
case StatusItWorksOnMyMachine:
return "It works on my machine"
case StatusItsAFeatureNotABug:
return "It's a feature, not a bug"
case Status32BitsIsPlenty:
return "32 bits is plenty"
case StatusItWorksInMyTimezone:
return "It works in my timezone"
case StatusFuckingNpm:
return "Fucking npm"
case StatusFuckingRubygems:
return "Fucking Rubygems"
case StatusFuckingUnicode:
return "Fucking Unic&#128169;de"
case StatusFuckingDeadlocks:
return "Fucking Deadlocks"
case StatusFuckingDeferreds:
return "Fucking Deferreds"
case StatusFuckingRaceConditions:
return "Fucking Race Conditions"
case StatusFuckingIE:
return "Fucking IE"
case StatusFuckThreadsing:
return "FuckThreadsing"
case StatusFuckingExactlyOnceDelivery:
return "Fucking Exactly-once Delivery"
case StatusFuckingWindows:
return "Fucking Windows"
case StatusDidntBotherToCompileIt:
return "Didn't bother to compile it"
case StatusSyntaxError:
return "Syntax Error"
case StatusTooManySemiColons:
return "Too many semi-colons"
case StatusNotEnoughSemiColons:
return "Not enough semi-colons"
case StatusInsufficientlyPolite:
return "Insufficiently polite"
case StatusExcessivelyPolite:
return "Excessively polite"
case StatusUnexpectedT_PAAMAYIM_NEKUDOTAYIM:
return "Unexpected \"T_PAAMAYIM_NEKUDOTAYIM\""
case StatusHungover:
return "Hungover"
case StatusStoned:
return "Stoned"
case StatusUnderCaffeinated:
return "Under-Caffeinated"
case StatusOverCaffeinated:
return "Over-Caffeinated"
case StatusRailscamp:
return "Railscamp"
case StatusSober:
return "Sober"
case StatusDrunk:
return "Drunk"
case StatusAccidentallyTookSleepingPillsInsteadOfMigrainePillsDuringCrunchWeek:
return "Accidentally Took Sleeping Pills Instead Of Migraine Pills During Crunch Week"
case StatusCachedForTooLong:
return "Cached for too long"
case StatusNotCachedLongEnough:
return "Not cached long enough"
case StatusNotCachedAtAll:
return "Not cached at all"
case StatusWhyWasThisCached:
return "Why was this cached?"
case StatusOutOfCash:
return "Out of cash"
case StatusErrorOnTheException:
return "Error on the Exception"
case StatusCoincidence:
return "Coincidence"
case StatusOffByOneError:
return "Off By One Error"
case StatusOffByTooManyToCountError:
return "Off By Too Many To Count Error"
case StatusProjectOwnerNotResponding:
return "Project owner not responding"
case StatusOperations:
return "Operations"
case StatusQA:
return "QA"
case StatusItWasACustomerRequestHonestly:
return "It was a customer request, honestly"
case StatusManagementObviously:
return "Management, obviously"
case StatusTPSCoverSheetNotAttached:
return "TPS Cover Sheet not attached"
case StatusTryItNow:
return "Try it now"
case StatusFurtherFundingRequired:
return "Further Funding Required"
case StatusDesignersFinalDesignsWerent:
return "Designer's final designs weren't"
case StatusNotMyDepartment:
return "Not my department"
case StatusTheInternetShutDownDueToCopyrightRestrictions:
return "The Internet shut down due to copyright restrictions"
case StatusClimateChangeDrivenCatastrophicWeatherEvent:
return "Climate change driven catastrophic weather event"
case StatusZombieApocalypse:
return "Zombie Apocalypse"
case StatusSomeoneLetPGNearAREPL:
return "Someone let PG near a REPL"
case StatusHeartbleed:
return "#heartbleed"
case StatusSomeDNSFuckeryIdno:
return "Some DNS fuckery idno"
case StatusThisIsTheLastPageOfTheInternetGoBack:
return "This is the last page of the Internet. Go back"
case StatusICheckedTheDbBackupsCupboardAndTheCupboardWasBare:
return "I checked the db backups cupboard and the cupboard was bare"
case StatusEndOfTheWorld:
return "End of the world"
}
}