diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80d082a..54f1910 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,4 +8,4 @@ on: jobs: check: - uses: Emerging-Patterns/actions/.github/workflows/nix-flake-check.yml@feaa011dafd85fecb67aa058fbcf6424cf605e86 + uses: Emerging-Patterns/actions/.github/workflows/nix-flake-check.yml@4ea982dc3e7839b05bc0bd65a3e4a2868d44e1a1 diff --git a/LAWS.bend b/LAWS.bend index 614fd30..fd31f16 100644 --- a/LAWS.bend +++ b/LAWS.bend @@ -38,47 +38,27 @@ import ./laws/AbsoluteLocationsResolve.bend as AbsoluteLocationsResolve import ./laws/BadRequestAnswers400.bend as BadRequestAnswers400 import ./laws/BadRequestShowIsMarked.bend as BadRequestShowIsMarked import ./laws/BareRepliesWriteHeadOnly.bend as BareRepliesWriteHeadOnly -import ./laws/Base64EmptyIsEmpty.bend as Base64EmptyIsEmpty -import ./laws/Base64EncodesF.bend as Base64EncodesF -import ./laws/Base64EncodesFo.bend as Base64EncodesFo -import ./laws/Base64EncodesFoo.bend as Base64EncodesFoo -import ./laws/Base64EncodesUserPass.bend as Base64EncodesUserPass import ./laws/Base64PadsFinalQuantum.bend as Base64PadsFinalQuantum import ./laws/BasicIsBase64OfUserPassword.bend as BasicIsBase64OfUserPassword import ./laws/BearerIsAuthorization.bend as BearerIsAuthorization -import ./laws/BearerTokenAcceptsPlain.bend as BearerTokenAcceptsPlain -import ./laws/BearerTokenRejectsNewline.bend as BearerTokenRejectsNewline -import ./laws/BearerTokenRejectsSpace.bend as BearerTokenRejectsSpace -import ./laws/BearerTokenRejectsTab.bend as BearerTokenRejectsTab -import ./laws/CacheDirectiveNamesIgnoreCase.bend as CacheDirectiveNamesIgnoreCase -import ./laws/CacheIgnoresUnknownDirective.bend as CacheIgnoresUnknownDirective -import ./laws/CacheMaxAgeIgnoresJunk.bend as CacheMaxAgeIgnoresJunk import ./laws/CacheReadsKnownDirectives.bend as CacheReadsKnownDirectives import ./laws/CacheRecordsExpires.bend as CacheRecordsExpires import ./laws/CacheRecordsMaxAge.bend as CacheRecordsMaxAge -import ./laws/CacheRecordsNoCache.bend as CacheRecordsNoCache -import ./laws/CacheRecordsPrivate.bend as CacheRecordsPrivate import ./laws/ChunkDataUnchanged.bend as ChunkDataUnchanged import ./laws/ChunkSizeHexIgnoresCase.bend as ChunkSizeHexIgnoresCase import ./laws/ChunkSizeIgnoresExtension.bend as ChunkSizeIgnoresExtension -import ./laws/ChunkSizeReadsHexSkipsExtension.bend as ChunkSizeReadsHexSkipsExtension import ./laws/ChunkedBodyJoinsChunks.bend as ChunkedBodyJoinsChunks -import ./laws/ChunkedNameIgnoresCase.bend as ChunkedNameIgnoresCase import ./laws/ChunksStopWithoutFuel.bend as ChunksStopWithoutFuel import ./laws/ContentLengthFramesBody.bend as ContentLengthFramesBody import ./laws/ContentLengthReadsDecimal.bend as ContentLengthReadsDecimal import ./laws/ContentLengthRejectsJunk.bend as ContentLengthRejectsJunk -import ./laws/ContentLengthTakesPrefix.bend as ContentLengthTakesPrefix import ./laws/ContinuationLineRejected.bend as ContinuationLineRejected import ./laws/CookieAliveUnderMaxAge.bend as CookieAliveUnderMaxAge import ./laws/CookieAttributesJoinWithSemicolons.bend as CookieAttributesJoinWithSemicolons import ./laws/CookieDefaultPathFallsBackToRoot.bend as CookieDefaultPathFallsBackToRoot import ./laws/CookieDefaultPathIsDirectory.bend as CookieDefaultPathIsDirectory -import ./laws/CookieDefaultPathNeedsTwoSlashes.bend as CookieDefaultPathNeedsTwoSlashes -import ./laws/CookieDefaultPathOmitsTrailingSlash.bend as CookieDefaultPathOmitsTrailingSlash import ./laws/CookieDomainLowercased.bend as CookieDomainLowercased import ./laws/CookieDomainMatchesDotSuffix.bend as CookieDomainMatchesDotSuffix -import ./laws/CookieDomainNeedsDotBeforeSuffix.bend as CookieDomainNeedsDotBeforeSuffix import ./laws/CookieHeaderEchoesStore.bend as CookieHeaderEchoesStore import ./laws/CookieHostOnlyNotSentElsewhere.bend as CookieHostOnlyNotSentElsewhere import ./laws/CookieHostOnlySentToHost.bend as CookieHostOnlySentToHost @@ -89,34 +69,24 @@ import ./laws/CookieIpHostMatchesExactly.bend as CookieIpHostMatchesExactly import ./laws/CookieIpHostNoSuffixMatch.bend as CookieIpHostNoSuffixMatch import ./laws/CookieLongerPathFails.bend as CookieLongerPathFails import ./laws/CookieMaxAgeIgnoresJunk.bend as CookieMaxAgeIgnoresJunk -import ./laws/CookieMaxAgeOneStaleAtOne.bend as CookieMaxAgeOneStaleAtOne import ./laws/CookieMaxAgeSetsAge.bend as CookieMaxAgeSetsAge -import ./laws/CookieMaxAgeZeroNotAlive.bend as CookieMaxAgeZeroNotAlive import ./laws/CookieNameIsNotIpv4.bend as CookieNameIsNotIpv4 -import ./laws/CookieNoDomainNotSentElsewhere.bend as CookieNoDomainNotSentElsewhere import ./laws/CookiePathMatchesSlashPrefix.bend as CookiePathMatchesSlashPrefix import ./laws/CookiePathNeedsSegmentBoundary.bend as CookiePathNeedsSegmentBoundary import ./laws/CookieRecognizesIpv4Literal.bend as CookieRecognizesIpv4Literal import ./laws/CookieRejectsEmptyName.bend as CookieRejectsEmptyName import ./laws/CookieRequestJoinsPairs.bend as CookieRequestJoinsPairs -import ./laws/CookieRootPathMatchesLonger.bend as CookieRootPathMatchesLonger import ./laws/CookieSameSiteFoldsCase.bend as CookieSameSiteFoldsCase -import ./laws/CookieSameSiteNoneCanonical.bend as CookieSameSiteNoneCanonical import ./laws/CookieSecureNeedsTls.bend as CookieSecureNeedsTls -import ./laws/CookieSecureSentOnTls.bend as CookieSecureSentOnTls -import ./laws/CookieSessionStaysAlive.bend as CookieSessionStaysAlive import ./laws/CookieSlashEndedPathIsPrefix.bend as CookieSlashEndedPathIsPrefix -import ./laws/CookieUnknownSameSiteDropped.bend as CookieUnknownSameSiteDropped import ./laws/CorsAllowListReflectsOrigin.bend as CorsAllowListReflectsOrigin import ./laws/CorsAllowedPreflightIs200.bend as CorsAllowedPreflightIs200 import ./laws/CorsBadPreflightIs400.bend as CorsBadPreflightIs400 -import ./laws/CorsCredentialsKeepExplicitOrigin.bend as CorsCredentialsKeepExplicitOrigin import ./laws/CorsCredentialsReflectOrigin.bend as CorsCredentialsReflectOrigin import ./laws/CorsGetIsNotPreflight.bend as CorsGetIsNotPreflight import ./laws/CorsNoVaryForStar.bend as CorsNoVaryForStar import ./laws/CorsNoVaryWhenRefused.bend as CorsNoVaryWhenRefused import ./laws/CorsOptionsWithMethodIsPreflight.bend as CorsOptionsWithMethodIsPreflight -import ./laws/CorsPreflightAnswersStar.bend as CorsPreflightAnswersStar import ./laws/CorsPreflightHeaderDenied.bend as CorsPreflightHeaderDenied import ./laws/CorsPreflightHeadersIgnoreCase.bend as CorsPreflightHeadersIgnoreCase import ./laws/CorsPreflightMethodDenied.bend as CorsPreflightMethodDenied @@ -126,30 +96,21 @@ import ./laws/CorsReadsRequestHeaders.bend as CorsReadsRequestHeaders import ./laws/CorsReadsRequestMethod.bend as CorsReadsRequestMethod import ./laws/CorsRefusedLeavesReply.bend as CorsRefusedLeavesReply import ./laws/CorsRefusesMissingOrigin.bend as CorsRefusesMissingOrigin -import ./laws/CorsSimpleAnswersStar.bend as CorsSimpleAnswersStar import ./laws/CorsSimpleKeepsBody.bend as CorsSimpleKeepsBody import ./laws/CorsStarStaysStar.bend as CorsStarStaysStar import ./laws/CorsVaryOnSpecificOrigin.bend as CorsVaryOnSpecificOrigin import ./laws/CutAtFirstEquals.bend as CutAtFirstEquals import ./laws/DeadlineIsTimeout.bend as DeadlineIsTimeout import ./laws/DechunkEmptyIsEmpty.bend as DechunkEmptyIsEmpty -import ./laws/DechunkIgnoresExtension.bend as DechunkIgnoresExtension -import ./laws/DechunkJoinsTwoChunks.bend as DechunkJoinsTwoChunks -import ./laws/DechunkLastChunkAloneIsEmpty.bend as DechunkLastChunkAloneIsEmpty -import ./laws/DechunkRfcExample.bend as DechunkRfcExample -import ./laws/DechunkStopsAtZero.bend as DechunkStopsAtZero -import ./laws/DeleteIsIdempotent.bend as DeleteIsIdempotent -import ./laws/DeleteNotSafe.bend as DeleteNotSafe import ./laws/DeleteRequestLine.bend as DeleteRequestLine import ./laws/DotSegmentsRemoved.bend as DotSegmentsRemoved -import ./laws/EqualContentLengthsAreOne.bend as EqualContentLengthsAreOne import ./laws/ErrnoNamesAreLinux.bend as ErrnoNamesAreLinux import ./laws/ExactContentLengthBodyKept.bend as ExactContentLengthBodyKept import ./laws/ExchangeCarriesMethod.bend as ExchangeCarriesMethod import ./laws/FailedEffectsLoseConnection.bend as FailedEffectsLoseConnection +import ./laws/MaxZeroIsNoLimit.bend as MaxZeroIsNoLimit import ./laws/FailuresReportedByPhase.bend as FailuresReportedByPhase import ./laws/FieldLookupFindsFirst.bend as FieldLookupFindsFirst -import ./laws/FieldLookupIgnoresCase.bend as FieldLookupIgnoresCase import ./laws/FieldNamesIgnoreCase.bend as FieldNamesIgnoreCase import ./laws/FieldValueTrimsWhitespace.bend as FieldValueTrimsWhitespace import ./laws/FirstIsFirstWord.bend as FirstIsFirstWord @@ -160,16 +121,10 @@ import ./laws/FormPartHeaders.bend as FormPartHeaders import ./laws/FormRefusesBadRequests.bend as FormRefusesBadRequests import ./laws/FreshUnderMaxAge.bend as FreshUnderMaxAge import ./laws/GetAsteriskTargetRejected.bend as GetAsteriskTargetRejected -import ./laws/GetIsIdempotent.bend as GetIsIdempotent -import ./laws/GetIsSafe.bend as GetIsSafe -import ./laws/GetOmitsContentLength.bend as GetOmitsContentLength import ./laws/GetRequestLine.bend as GetRequestLine import ./laws/HandlerGetsRequestText.bend as HandlerGetsRequestText import ./laws/HeadAndNoContentHaveNoBody.bend as HeadAndNoContentHaveNoBody -import ./laws/HeadIsIdempotent.bend as HeadIsIdempotent -import ./laws/HeadIsSafe.bend as HeadIsSafe import ./laws/HeadPlannedBeforeBody.bend as HeadPlannedBeforeBody -import ./laws/HeadReplyDropsBody.bend as HeadReplyDropsBody import ./laws/HeadRequestLine.bend as HeadRequestLine import ./laws/HtmlEscapeCharByChar.bend as HtmlEscapeCharByChar import ./laws/HtmlEscapeIsSafe.bend as HtmlEscapeIsSafe @@ -179,24 +134,15 @@ import ./laws/HttpsDefaultsTo443.bend as HttpsDefaultsTo443 import ./laws/InterimResponsesSkipped.bend as InterimResponsesSkipped import ./laws/InterimStatusIs1xx.bend as InterimStatusIs1xx import ./laws/JoinedPiecesAreText.bend as JoinedPiecesAreText -import ./laws/JsonRejectsNonJson.bend as JsonRejectsNonJson import ./laws/JsonStringIsTextBody.bend as JsonStringIsTextBody -import ./laws/JsonStringParsesBack.bend as JsonStringParsesBack import ./laws/LocationResolvedBySort.bend as LocationResolvedBySort import ./laws/LocationSplitsAtQuery.bend as LocationSplitsAtQuery -import ./laws/LowercaseGetNotSafe.bend as LowercaseGetNotSafe -import ./laws/MaxAgeOneFreshThenStale.bend as MaxAgeOneFreshThenStale -import ./laws/MaxAgeOverridesExpires.bend as MaxAgeOverridesExpires -import ./laws/MaxAgeZeroIsStale.bend as MaxAgeZeroIsStale import ./laws/MethodTokensAreCaseSensitive.bend as MethodTokensAreCaseSensitive import ./laws/MissingFieldIsEmpty.bend as MissingFieldIsEmpty import ./laws/NamedReferencesLongestMatch.bend as NamedReferencesLongestMatch import ./laws/NoCacheNeverFresh.bend as NoCacheNeverFresh -import ./laws/NoCacheNotFresh.bend as NoCacheNotFresh import ./laws/NoMaxAgeNotFresh.bend as NoMaxAgeNotFresh import ./laws/NoStoreNeverFresh.bend as NoStoreNeverFresh -import ./laws/NoStoreNotFresh.bend as NoStoreNotFresh -import ./laws/NonHeadReplyKeepsBody.bend as NonHeadReplyKeepsBody import ./laws/NonHexChunkSizeTorn.bend as NonHexChunkSizeTorn import ./laws/NumericReferencesDecode.bend as NumericReferencesDecode import ./laws/ObsFoldRejected.bend as ObsFoldRejected @@ -205,22 +151,14 @@ import ./laws/OctetsDecodeAsUtf8.bend as OctetsDecodeAsUtf8 import ./laws/OneOctetPerChar.bend as OneOctetPerChar import ./laws/OnlyGetFollows.bend as OnlyGetFollows import ./laws/OptionsAsteriskNamesServer.bend as OptionsAsteriskNamesServer -import ./laws/OptionsIsIdempotent.bend as OptionsIsIdempotent -import ./laws/OptionsIsSafe.bend as OptionsIsSafe import ./laws/OptionsRequestLine.bend as OptionsRequestLine import ./laws/OriginFormKeepsQuery.bend as OriginFormKeepsQuery import ./laws/OtherSchemesDefaultTo80.bend as OtherSchemesDefaultTo80 import ./laws/OtherStatusesStopChain.bend as OtherStatusesStopChain import ./laws/ParseQuerySplitsPairs.bend as ParseQuerySplitsPairs -import ./laws/PatchNotIdempotent.bend as PatchNotIdempotent import ./laws/PathFormKeepsSlash.bend as PathFormKeepsSlash import ./laws/PhraseTableLookup.bend as PhraseTableLookup -import ./laws/PostNotIdempotent.bend as PostNotIdempotent -import ./laws/PostNotSafe.bend as PostNotSafe import ./laws/PostRequestLine.bend as PostRequestLine -import ./laws/PostWritesContentLength.bend as PostWritesContentLength -import ./laws/PutIsIdempotent.bend as PutIsIdempotent -import ./laws/PutNotSafe.bend as PutNotSafe import ./laws/PutRequestLine.bend as PutRequestLine import ./laws/QueryGetLastWins.bend as QueryGetLastWins import ./laws/QuoteEscapesUtf8Bytes.bend as QuoteEscapesUtf8Bytes @@ -229,18 +167,10 @@ import ./laws/QuoteOutputIsFramed.bend as QuoteOutputIsFramed import ./laws/QuotePlusWritesSpaces.bend as QuotePlusWritesSpaces import ./laws/ReadStateMatchesWholeText.bend as ReadStateMatchesWholeText import ./laws/ReadsJudgedByCount.bend as ReadsJudgedByCount -import ./laws/Reason200IsOk.bend as Reason200IsOk -import ./laws/Reason201IsCreated.bend as Reason201IsCreated -import ./laws/Reason204IsNoContent.bend as Reason204IsNoContent -import ./laws/Reason400IsBadRequest.bend as Reason400IsBadRequest -import ./laws/Reason404IsNotFound.bend as Reason404IsNotFound -import ./laws/Reason405IsMethodNotAllowed.bend as Reason405IsMethodNotAllowed -import ./laws/Reason500IsInternalServerError.bend as Reason500IsInternalServerError import ./laws/ReasonPhraseFromFinalHead.bend as ReasonPhraseFromFinalHead import ./laws/ReasonPhrasesFollowRfc.bend as ReasonPhrasesFollowRfc import ./laws/RedirectsFollowLocation.bend as RedirectsFollowLocation import ./laws/RelativeLocationsMerge.bend as RelativeLocationsMerge -import ./laws/RelativeTargetRejected.bend as RelativeTargetRejected import ./laws/ReplyHeadFramesBody.bend as ReplyHeadFramesBody import ./laws/RequestBodyOfContentLengthKept.bend as RequestBodyOfContentLengthKept import ./laws/RequestDisagreeingContentLengthsRejected.bend as RequestDisagreeingContentLengthsRejected @@ -252,15 +182,10 @@ import ./laws/RequestLineOpensWithMethod.bend as RequestLineOpensWithMethod import ./laws/RequestNeedsBlankLine.bend as RequestNeedsBlankLine import ./laws/RequestNeedsRequestLine.bend as RequestNeedsRequestLine import ./laws/RequestWithBothFramingsRejected.bend as RequestWithBothFramingsRejected -import ./laws/Respond200KeepsBody.bend as Respond200KeepsBody -import ./laws/Respond204DropsBody.bend as Respond204DropsBody -import ./laws/Respond304DropsBody.bend as Respond304DropsBody import ./laws/RespondOpensWithVersion.bend as RespondOpensWithVersion import ./laws/ResponseCompleteByFraming.bend as ResponseCompleteByFraming -import ./laws/ResponseDisagreeingContentLengthsTorn.bend as ResponseDisagreeingContentLengthsTorn import ./laws/ResponseNeedsBlankLine.bend as ResponseNeedsBlankLine import ./laws/ResponseNeedsStatus.bend as ResponseNeedsStatus -import ./laws/ResponseWithBothFramingsTorn.bend as ResponseWithBothFramingsTorn import ./laws/SchemeBeforeFirstColon.bend as SchemeBeforeFirstColon import ./laws/SecondIsNextWord.bend as SecondIsNextWord import ./laws/SetCookieFieldsSelected.bend as SetCookieFieldsSelected @@ -270,7 +195,6 @@ import ./laws/ShortRequestBodyIsBad.bend as ShortRequestBodyIsBad import ./laws/ShowReplyOpensWithStatus.bend as ShowReplyOpensWithStatus import ./laws/ShowTornIsMarked.bend as ShowTornIsMarked import ./laws/SplitAtCharacter.bend as SplitAtCharacter -import ./laws/StaleAtMaxAge.bend as StaleAtMaxAge import ./laws/StreamedRepliesAreChunked.bend as StreamedRepliesAreChunked import ./laws/TakeDropSplitAtOneOffset.bend as TakeDropSplitAtOneOffset import ./laws/TimeoutZeroIsOneMs.bend as TimeoutZeroIsOneMs @@ -278,28 +202,26 @@ import ./laws/TimeoutsReadAsTimedOut.bend as TimeoutsReadAsTimedOut import ./laws/UnescapeFindsReferences.bend as UnescapeFindsReferences import ./laws/UnescapeUndoesEscape.bend as UnescapeUndoesEscape import ./laws/UnframedBodyIsRest.bend as UnframedBodyIsRest -import ./laws/UnknownStatusHasEmptyReason.bend as UnknownStatusHasEmptyReason import ./laws/UnquotePlusReadsSpaces.bend as UnquotePlusReadsSpaces import ./laws/UnquoteReadsEscapes.bend as UnquoteReadsEscapes import ./laws/UrlBadPortUsesDefault.bend as UrlBadPortUsesDefault import ./laws/UrlEmptyPath.bend as UrlEmptyPath import ./laws/UrlFragmentHidesQuery.bend as UrlFragmentHidesQuery import ./laws/UrlHttpDefaultPort.bend as UrlHttpDefaultPort -import ./laws/UrlHttpsDefaultPort.bend as UrlHttpsDefaultPort import ./laws/UrlHttpsExplicitPort.bend as UrlHttpsExplicitPort import ./laws/UrlIpv4Host.bend as UrlIpv4Host -import ./laws/UrlIpv4Port.bend as UrlIpv4Port import ./laws/UrlNeedsSlashes.bend as UrlNeedsSlashes import ./laws/UrlPathIsAbsolute.bend as UrlPathIsAbsolute -import ./laws/UrlQueryDropsFragment.bend as UrlQueryDropsFragment import ./laws/UrlQueryKeepsQuestion.bend as UrlQueryKeepsQuestion import ./laws/UrlQueryOnEmptyPath.bend as UrlQueryOnEmptyPath -import ./laws/UrlSchemeLowercased.bend as UrlSchemeLowercased import ./laws/UrlShowBadIsMarked.bend as UrlShowBadIsMarked import ./laws/UrlShowOpensWithScheme.bend as UrlShowOpensWithScheme import ./laws/UrlTrailingSlash.bend as UrlTrailingSlash import ./laws/UrlUserinfoLastAt.bend as UrlUserinfoLastAt -import ./laws/UrlUserinfoStripped.bend as UrlUserinfoStripped import ./laws/UrlencodeJoinsPairs.bend as UrlencodeJoinsPairs import ./laws/Utf8DecodesWithReplacement.bend as Utf8DecodesWithReplacement import ./laws/WithServesGetOctetsAndContext.bend as WithServesGetOctetsAndContext +import ./laws/Base64EncodesByQuantum.bend as Base64EncodesByQuantum +import ./laws/BearerTokenHasNoWhitespace.bend as BearerTokenHasNoWhitespace +import ./laws/JsonParseIsEzjsonParse.bend as JsonParseIsEzjsonParse +import ./laws/MethodsSafeAndIdempotent.bend as MethodsSafeAndIdempotent diff --git a/PROOF.bend b/PROOF.bend index 89878e6..047052b 100644 --- a/PROOF.bend +++ b/PROOF.bend @@ -7,47 +7,27 @@ import ./proofs/AbsoluteLocationsResolve.bend as PAbsoluteLocationsResolve import ./proofs/BadRequestAnswers400.bend as PBadRequestAnswers400 import ./proofs/BadRequestShowIsMarked.bend as PBadRequestShowIsMarked import ./proofs/BareRepliesWriteHeadOnly.bend as PBareRepliesWriteHeadOnly -import ./proofs/Base64EmptyIsEmpty.bend as PBase64EmptyIsEmpty -import ./proofs/Base64EncodesF.bend as PBase64EncodesF -import ./proofs/Base64EncodesFo.bend as PBase64EncodesFo -import ./proofs/Base64EncodesFoo.bend as PBase64EncodesFoo -import ./proofs/Base64EncodesUserPass.bend as PBase64EncodesUserPass import ./proofs/Base64PadsFinalQuantum.bend as PBase64PadsFinalQuantum import ./proofs/BasicIsBase64OfUserPassword.bend as PBasicIsBase64OfUserPassword import ./proofs/BearerIsAuthorization.bend as PBearerIsAuthorization -import ./proofs/BearerTokenAcceptsPlain.bend as PBearerTokenAcceptsPlain -import ./proofs/BearerTokenRejectsNewline.bend as PBearerTokenRejectsNewline -import ./proofs/BearerTokenRejectsSpace.bend as PBearerTokenRejectsSpace -import ./proofs/BearerTokenRejectsTab.bend as PBearerTokenRejectsTab -import ./proofs/CacheDirectiveNamesIgnoreCase.bend as PCacheDirectiveNamesIgnoreCase -import ./proofs/CacheIgnoresUnknownDirective.bend as PCacheIgnoresUnknownDirective -import ./proofs/CacheMaxAgeIgnoresJunk.bend as PCacheMaxAgeIgnoresJunk import ./proofs/CacheReadsKnownDirectives.bend as PCacheReadsKnownDirectives import ./proofs/CacheRecordsExpires.bend as PCacheRecordsExpires import ./proofs/CacheRecordsMaxAge.bend as PCacheRecordsMaxAge -import ./proofs/CacheRecordsNoCache.bend as PCacheRecordsNoCache -import ./proofs/CacheRecordsPrivate.bend as PCacheRecordsPrivate import ./proofs/ChunkDataUnchanged.bend as PChunkDataUnchanged import ./proofs/ChunkSizeHexIgnoresCase.bend as PChunkSizeHexIgnoresCase import ./proofs/ChunkSizeIgnoresExtension.bend as PChunkSizeIgnoresExtension -import ./proofs/ChunkSizeReadsHexSkipsExtension.bend as PChunkSizeReadsHexSkipsExtension import ./proofs/ChunkedBodyJoinsChunks.bend as PChunkedBodyJoinsChunks -import ./proofs/ChunkedNameIgnoresCase.bend as PChunkedNameIgnoresCase import ./proofs/ChunksStopWithoutFuel.bend as PChunksStopWithoutFuel import ./proofs/ContentLengthFramesBody.bend as PContentLengthFramesBody import ./proofs/ContentLengthReadsDecimal.bend as PContentLengthReadsDecimal import ./proofs/ContentLengthRejectsJunk.bend as PContentLengthRejectsJunk -import ./proofs/ContentLengthTakesPrefix.bend as PContentLengthTakesPrefix import ./proofs/ContinuationLineRejected.bend as PContinuationLineRejected import ./proofs/CookieAliveUnderMaxAge.bend as PCookieAliveUnderMaxAge import ./proofs/CookieAttributesJoinWithSemicolons.bend as PCookieAttributesJoinWithSemicolons import ./proofs/CookieDefaultPathFallsBackToRoot.bend as PCookieDefaultPathFallsBackToRoot import ./proofs/CookieDefaultPathIsDirectory.bend as PCookieDefaultPathIsDirectory -import ./proofs/CookieDefaultPathNeedsTwoSlashes.bend as PCookieDefaultPathNeedsTwoSlashes -import ./proofs/CookieDefaultPathOmitsTrailingSlash.bend as PCookieDefaultPathOmitsTrailingSlash import ./proofs/CookieDomainLowercased.bend as PCookieDomainLowercased import ./proofs/CookieDomainMatchesDotSuffix.bend as PCookieDomainMatchesDotSuffix -import ./proofs/CookieDomainNeedsDotBeforeSuffix.bend as PCookieDomainNeedsDotBeforeSuffix import ./proofs/CookieHeaderEchoesStore.bend as PCookieHeaderEchoesStore import ./proofs/CookieHostOnlyNotSentElsewhere.bend as PCookieHostOnlyNotSentElsewhere import ./proofs/CookieHostOnlySentToHost.bend as PCookieHostOnlySentToHost @@ -58,34 +38,24 @@ import ./proofs/CookieIpHostMatchesExactly.bend as PCookieIpHostMatchesExactly import ./proofs/CookieIpHostNoSuffixMatch.bend as PCookieIpHostNoSuffixMatch import ./proofs/CookieLongerPathFails.bend as PCookieLongerPathFails import ./proofs/CookieMaxAgeIgnoresJunk.bend as PCookieMaxAgeIgnoresJunk -import ./proofs/CookieMaxAgeOneStaleAtOne.bend as PCookieMaxAgeOneStaleAtOne import ./proofs/CookieMaxAgeSetsAge.bend as PCookieMaxAgeSetsAge -import ./proofs/CookieMaxAgeZeroNotAlive.bend as PCookieMaxAgeZeroNotAlive import ./proofs/CookieNameIsNotIpv4.bend as PCookieNameIsNotIpv4 -import ./proofs/CookieNoDomainNotSentElsewhere.bend as PCookieNoDomainNotSentElsewhere import ./proofs/CookiePathMatchesSlashPrefix.bend as PCookiePathMatchesSlashPrefix import ./proofs/CookiePathNeedsSegmentBoundary.bend as PCookiePathNeedsSegmentBoundary import ./proofs/CookieRecognizesIpv4Literal.bend as PCookieRecognizesIpv4Literal import ./proofs/CookieRejectsEmptyName.bend as PCookieRejectsEmptyName import ./proofs/CookieRequestJoinsPairs.bend as PCookieRequestJoinsPairs -import ./proofs/CookieRootPathMatchesLonger.bend as PCookieRootPathMatchesLonger import ./proofs/CookieSameSiteFoldsCase.bend as PCookieSameSiteFoldsCase -import ./proofs/CookieSameSiteNoneCanonical.bend as PCookieSameSiteNoneCanonical import ./proofs/CookieSecureNeedsTls.bend as PCookieSecureNeedsTls -import ./proofs/CookieSecureSentOnTls.bend as PCookieSecureSentOnTls -import ./proofs/CookieSessionStaysAlive.bend as PCookieSessionStaysAlive import ./proofs/CookieSlashEndedPathIsPrefix.bend as PCookieSlashEndedPathIsPrefix -import ./proofs/CookieUnknownSameSiteDropped.bend as PCookieUnknownSameSiteDropped import ./proofs/CorsAllowListReflectsOrigin.bend as PCorsAllowListReflectsOrigin import ./proofs/CorsAllowedPreflightIs200.bend as PCorsAllowedPreflightIs200 import ./proofs/CorsBadPreflightIs400.bend as PCorsBadPreflightIs400 -import ./proofs/CorsCredentialsKeepExplicitOrigin.bend as PCorsCredentialsKeepExplicitOrigin import ./proofs/CorsCredentialsReflectOrigin.bend as PCorsCredentialsReflectOrigin import ./proofs/CorsGetIsNotPreflight.bend as PCorsGetIsNotPreflight import ./proofs/CorsNoVaryForStar.bend as PCorsNoVaryForStar import ./proofs/CorsNoVaryWhenRefused.bend as PCorsNoVaryWhenRefused import ./proofs/CorsOptionsWithMethodIsPreflight.bend as PCorsOptionsWithMethodIsPreflight -import ./proofs/CorsPreflightAnswersStar.bend as PCorsPreflightAnswersStar import ./proofs/CorsPreflightHeaderDenied.bend as PCorsPreflightHeaderDenied import ./proofs/CorsPreflightHeadersIgnoreCase.bend as PCorsPreflightHeadersIgnoreCase import ./proofs/CorsPreflightMethodDenied.bend as PCorsPreflightMethodDenied @@ -95,30 +65,21 @@ import ./proofs/CorsReadsRequestHeaders.bend as PCorsReadsRequestHeaders import ./proofs/CorsReadsRequestMethod.bend as PCorsReadsRequestMethod import ./proofs/CorsRefusedLeavesReply.bend as PCorsRefusedLeavesReply import ./proofs/CorsRefusesMissingOrigin.bend as PCorsRefusesMissingOrigin -import ./proofs/CorsSimpleAnswersStar.bend as PCorsSimpleAnswersStar import ./proofs/CorsSimpleKeepsBody.bend as PCorsSimpleKeepsBody import ./proofs/CorsStarStaysStar.bend as PCorsStarStaysStar import ./proofs/CorsVaryOnSpecificOrigin.bend as PCorsVaryOnSpecificOrigin import ./proofs/CutAtFirstEquals.bend as PCutAtFirstEquals import ./proofs/DeadlineIsTimeout.bend as PDeadlineIsTimeout import ./proofs/DechunkEmptyIsEmpty.bend as PDechunkEmptyIsEmpty -import ./proofs/DechunkIgnoresExtension.bend as PDechunkIgnoresExtension -import ./proofs/DechunkJoinsTwoChunks.bend as PDechunkJoinsTwoChunks -import ./proofs/DechunkLastChunkAloneIsEmpty.bend as PDechunkLastChunkAloneIsEmpty -import ./proofs/DechunkRfcExample.bend as PDechunkRfcExample -import ./proofs/DechunkStopsAtZero.bend as PDechunkStopsAtZero -import ./proofs/DeleteIsIdempotent.bend as PDeleteIsIdempotent -import ./proofs/DeleteNotSafe.bend as PDeleteNotSafe import ./proofs/DeleteRequestLine.bend as PDeleteRequestLine import ./proofs/DotSegmentsRemoved.bend as PDotSegmentsRemoved -import ./proofs/EqualContentLengthsAreOne.bend as PEqualContentLengthsAreOne import ./proofs/ErrnoNamesAreLinux.bend as PErrnoNamesAreLinux import ./proofs/ExactContentLengthBodyKept.bend as PExactContentLengthBodyKept import ./proofs/ExchangeCarriesMethod.bend as PExchangeCarriesMethod import ./proofs/FailedEffectsLoseConnection.bend as PFailedEffectsLoseConnection +import ./proofs/MaxZeroIsNoLimit.bend as PMaxZeroIsNoLimit import ./proofs/FailuresReportedByPhase.bend as PFailuresReportedByPhase import ./proofs/FieldLookupFindsFirst.bend as PFieldLookupFindsFirst -import ./proofs/FieldLookupIgnoresCase.bend as PFieldLookupIgnoresCase import ./proofs/FieldNamesIgnoreCase.bend as PFieldNamesIgnoreCase import ./proofs/FieldValueTrimsWhitespace.bend as PFieldValueTrimsWhitespace import ./proofs/FirstIsFirstWord.bend as PFirstIsFirstWord @@ -129,16 +90,10 @@ import ./proofs/FormPartHeaders.bend as PFormPartHeaders import ./proofs/FormRefusesBadRequests.bend as PFormRefusesBadRequests import ./proofs/FreshUnderMaxAge.bend as PFreshUnderMaxAge import ./proofs/GetAsteriskTargetRejected.bend as PGetAsteriskTargetRejected -import ./proofs/GetIsIdempotent.bend as PGetIsIdempotent -import ./proofs/GetIsSafe.bend as PGetIsSafe -import ./proofs/GetOmitsContentLength.bend as PGetOmitsContentLength import ./proofs/GetRequestLine.bend as PGetRequestLine import ./proofs/HandlerGetsRequestText.bend as PHandlerGetsRequestText import ./proofs/HeadAndNoContentHaveNoBody.bend as PHeadAndNoContentHaveNoBody -import ./proofs/HeadIsIdempotent.bend as PHeadIsIdempotent -import ./proofs/HeadIsSafe.bend as PHeadIsSafe import ./proofs/HeadPlannedBeforeBody.bend as PHeadPlannedBeforeBody -import ./proofs/HeadReplyDropsBody.bend as PHeadReplyDropsBody import ./proofs/HeadRequestLine.bend as PHeadRequestLine import ./proofs/HtmlEscapeCharByChar.bend as PHtmlEscapeCharByChar import ./proofs/HtmlEscapeIsSafe.bend as PHtmlEscapeIsSafe @@ -148,24 +103,15 @@ import ./proofs/HttpsDefaultsTo443.bend as PHttpsDefaultsTo443 import ./proofs/InterimResponsesSkipped.bend as PInterimResponsesSkipped import ./proofs/InterimStatusIs1xx.bend as PInterimStatusIs1xx import ./proofs/JoinedPiecesAreText.bend as PJoinedPiecesAreText -import ./proofs/JsonRejectsNonJson.bend as PJsonRejectsNonJson import ./proofs/JsonStringIsTextBody.bend as PJsonStringIsTextBody -import ./proofs/JsonStringParsesBack.bend as PJsonStringParsesBack import ./proofs/LocationResolvedBySort.bend as PLocationResolvedBySort import ./proofs/LocationSplitsAtQuery.bend as PLocationSplitsAtQuery -import ./proofs/LowercaseGetNotSafe.bend as PLowercaseGetNotSafe -import ./proofs/MaxAgeOneFreshThenStale.bend as PMaxAgeOneFreshThenStale -import ./proofs/MaxAgeOverridesExpires.bend as PMaxAgeOverridesExpires -import ./proofs/MaxAgeZeroIsStale.bend as PMaxAgeZeroIsStale import ./proofs/MethodTokensAreCaseSensitive.bend as PMethodTokensAreCaseSensitive import ./proofs/MissingFieldIsEmpty.bend as PMissingFieldIsEmpty import ./proofs/NamedReferencesLongestMatch.bend as PNamedReferencesLongestMatch import ./proofs/NoCacheNeverFresh.bend as PNoCacheNeverFresh -import ./proofs/NoCacheNotFresh.bend as PNoCacheNotFresh import ./proofs/NoMaxAgeNotFresh.bend as PNoMaxAgeNotFresh import ./proofs/NoStoreNeverFresh.bend as PNoStoreNeverFresh -import ./proofs/NoStoreNotFresh.bend as PNoStoreNotFresh -import ./proofs/NonHeadReplyKeepsBody.bend as PNonHeadReplyKeepsBody import ./proofs/NonHexChunkSizeTorn.bend as PNonHexChunkSizeTorn import ./proofs/NumericReferencesDecode.bend as PNumericReferencesDecode import ./proofs/ObsFoldRejected.bend as PObsFoldRejected @@ -174,22 +120,14 @@ import ./proofs/OctetsDecodeAsUtf8.bend as POctetsDecodeAsUtf8 import ./proofs/OneOctetPerChar.bend as POneOctetPerChar import ./proofs/OnlyGetFollows.bend as POnlyGetFollows import ./proofs/OptionsAsteriskNamesServer.bend as POptionsAsteriskNamesServer -import ./proofs/OptionsIsIdempotent.bend as POptionsIsIdempotent -import ./proofs/OptionsIsSafe.bend as POptionsIsSafe import ./proofs/OptionsRequestLine.bend as POptionsRequestLine import ./proofs/OriginFormKeepsQuery.bend as POriginFormKeepsQuery import ./proofs/OtherSchemesDefaultTo80.bend as POtherSchemesDefaultTo80 import ./proofs/OtherStatusesStopChain.bend as POtherStatusesStopChain import ./proofs/ParseQuerySplitsPairs.bend as PParseQuerySplitsPairs -import ./proofs/PatchNotIdempotent.bend as PPatchNotIdempotent import ./proofs/PathFormKeepsSlash.bend as PPathFormKeepsSlash import ./proofs/PhraseTableLookup.bend as PPhraseTableLookup -import ./proofs/PostNotIdempotent.bend as PPostNotIdempotent -import ./proofs/PostNotSafe.bend as PPostNotSafe import ./proofs/PostRequestLine.bend as PPostRequestLine -import ./proofs/PostWritesContentLength.bend as PPostWritesContentLength -import ./proofs/PutIsIdempotent.bend as PPutIsIdempotent -import ./proofs/PutNotSafe.bend as PPutNotSafe import ./proofs/PutRequestLine.bend as PPutRequestLine import ./proofs/QueryGetLastWins.bend as PQueryGetLastWins import ./proofs/QuoteEscapesUtf8Bytes.bend as PQuoteEscapesUtf8Bytes @@ -198,18 +136,10 @@ import ./proofs/QuoteOutputIsFramed.bend as PQuoteOutputIsFramed import ./proofs/QuotePlusWritesSpaces.bend as PQuotePlusWritesSpaces import ./proofs/ReadStateMatchesWholeText.bend as PReadStateMatchesWholeText import ./proofs/ReadsJudgedByCount.bend as PReadsJudgedByCount -import ./proofs/Reason200IsOk.bend as PReason200IsOk -import ./proofs/Reason201IsCreated.bend as PReason201IsCreated -import ./proofs/Reason204IsNoContent.bend as PReason204IsNoContent -import ./proofs/Reason400IsBadRequest.bend as PReason400IsBadRequest -import ./proofs/Reason404IsNotFound.bend as PReason404IsNotFound -import ./proofs/Reason405IsMethodNotAllowed.bend as PReason405IsMethodNotAllowed -import ./proofs/Reason500IsInternalServerError.bend as PReason500IsInternalServerError import ./proofs/ReasonPhraseFromFinalHead.bend as PReasonPhraseFromFinalHead import ./proofs/ReasonPhrasesFollowRfc.bend as PReasonPhrasesFollowRfc import ./proofs/RedirectsFollowLocation.bend as PRedirectsFollowLocation import ./proofs/RelativeLocationsMerge.bend as PRelativeLocationsMerge -import ./proofs/RelativeTargetRejected.bend as PRelativeTargetRejected import ./proofs/ReplyHeadFramesBody.bend as PReplyHeadFramesBody import ./proofs/RequestBodyOfContentLengthKept.bend as PRequestBodyOfContentLengthKept import ./proofs/RequestDisagreeingContentLengthsRejected.bend as PRequestDisagreeingContentLengthsRejected @@ -221,15 +151,10 @@ import ./proofs/RequestLineOpensWithMethod.bend as PRequestLineOpensWithMethod import ./proofs/RequestNeedsBlankLine.bend as PRequestNeedsBlankLine import ./proofs/RequestNeedsRequestLine.bend as PRequestNeedsRequestLine import ./proofs/RequestWithBothFramingsRejected.bend as PRequestWithBothFramingsRejected -import ./proofs/Respond200KeepsBody.bend as PRespond200KeepsBody -import ./proofs/Respond204DropsBody.bend as PRespond204DropsBody -import ./proofs/Respond304DropsBody.bend as PRespond304DropsBody import ./proofs/RespondOpensWithVersion.bend as PRespondOpensWithVersion import ./proofs/ResponseCompleteByFraming.bend as PResponseCompleteByFraming -import ./proofs/ResponseDisagreeingContentLengthsTorn.bend as PResponseDisagreeingContentLengthsTorn import ./proofs/ResponseNeedsBlankLine.bend as PResponseNeedsBlankLine import ./proofs/ResponseNeedsStatus.bend as PResponseNeedsStatus -import ./proofs/ResponseWithBothFramingsTorn.bend as PResponseWithBothFramingsTorn import ./proofs/SchemeBeforeFirstColon.bend as PSchemeBeforeFirstColon import ./proofs/SecondIsNextWord.bend as PSecondIsNextWord import ./proofs/SetCookieFieldsSelected.bend as PSetCookieFieldsSelected @@ -239,7 +164,6 @@ import ./proofs/ShortRequestBodyIsBad.bend as PShortRequestBodyIsBad import ./proofs/ShowReplyOpensWithStatus.bend as PShowReplyOpensWithStatus import ./proofs/ShowTornIsMarked.bend as PShowTornIsMarked import ./proofs/SplitAtCharacter.bend as PSplitAtCharacter -import ./proofs/StaleAtMaxAge.bend as PStaleAtMaxAge import ./proofs/StreamedRepliesAreChunked.bend as PStreamedRepliesAreChunked import ./proofs/TakeDropSplitAtOneOffset.bend as PTakeDropSplitAtOneOffset import ./proofs/TimeoutZeroIsOneMs.bend as PTimeoutZeroIsOneMs @@ -247,28 +171,26 @@ import ./proofs/TimeoutsReadAsTimedOut.bend as PTimeoutsReadAsTimedOut import ./proofs/UnescapeFindsReferences.bend as PUnescapeFindsReferences import ./proofs/UnescapeUndoesEscape.bend as PUnescapeUndoesEscape import ./proofs/UnframedBodyIsRest.bend as PUnframedBodyIsRest -import ./proofs/UnknownStatusHasEmptyReason.bend as PUnknownStatusHasEmptyReason import ./proofs/UnquotePlusReadsSpaces.bend as PUnquotePlusReadsSpaces import ./proofs/UnquoteReadsEscapes.bend as PUnquoteReadsEscapes import ./proofs/UrlBadPortUsesDefault.bend as PUrlBadPortUsesDefault import ./proofs/UrlEmptyPath.bend as PUrlEmptyPath import ./proofs/UrlFragmentHidesQuery.bend as PUrlFragmentHidesQuery import ./proofs/UrlHttpDefaultPort.bend as PUrlHttpDefaultPort -import ./proofs/UrlHttpsDefaultPort.bend as PUrlHttpsDefaultPort import ./proofs/UrlHttpsExplicitPort.bend as PUrlHttpsExplicitPort import ./proofs/UrlIpv4Host.bend as PUrlIpv4Host -import ./proofs/UrlIpv4Port.bend as PUrlIpv4Port import ./proofs/UrlNeedsSlashes.bend as PUrlNeedsSlashes import ./proofs/UrlPathIsAbsolute.bend as PUrlPathIsAbsolute -import ./proofs/UrlQueryDropsFragment.bend as PUrlQueryDropsFragment import ./proofs/UrlQueryKeepsQuestion.bend as PUrlQueryKeepsQuestion import ./proofs/UrlQueryOnEmptyPath.bend as PUrlQueryOnEmptyPath -import ./proofs/UrlSchemeLowercased.bend as PUrlSchemeLowercased import ./proofs/UrlShowBadIsMarked.bend as PUrlShowBadIsMarked import ./proofs/UrlShowOpensWithScheme.bend as PUrlShowOpensWithScheme import ./proofs/UrlTrailingSlash.bend as PUrlTrailingSlash import ./proofs/UrlUserinfoLastAt.bend as PUrlUserinfoLastAt -import ./proofs/UrlUserinfoStripped.bend as PUrlUserinfoStripped import ./proofs/UrlencodeJoinsPairs.bend as PUrlencodeJoinsPairs import ./proofs/Utf8DecodesWithReplacement.bend as PUtf8DecodesWithReplacement import ./proofs/WithServesGetOctetsAndContext.bend as PWithServesGetOctetsAndContext +import ./proofs/Base64EncodesByQuantum.bend as PBase64EncodesByQuantum +import ./proofs/BearerTokenHasNoWhitespace.bend as PBearerTokenHasNoWhitespace +import ./proofs/JsonParseIsEzjsonParse.bend as PJsonParseIsEzjsonParse +import ./proofs/MethodsSafeAndIdempotent.bend as PMethodsSafeAndIdempotent diff --git a/bolt.bend b/bolt.bend index 75d3bab..3e5972c 100644 --- a/bolt.bend +++ b/bolt.bend @@ -1,6 +1,5 @@ # bolt.bend: how bolt lints this repo. See bolt/config.bend for groups and -# levels. `param` and `wrap` are warn: this port keeps ez net's short framing -# parameters and compact multi-line headers. +# levels. import Base # what will fail or blow up @@ -15,25 +14,14 @@ def suspicious() -> String: def style() -> String: "error" -# single-letter parameters (ez net idiom) -def param() -> String: - "warn" - -# multi-line headers without one-param-per-line (ez net idiom) -def wrap() -> String: - "warn" - # a pure def named by no law def laws() -> String: "error" -# bolt 1.8.0 closed: warn until the findings are fixed (see the tracking issue) +# a law with no `for` or `exs` binder def closed() -> String: - "warn" + "error" -# a def no quantified law reaches. main.bend's re-exports, the bench program -# and src/client.bend's Response type (the wire effect keeps it out of every -# law file) carry `# noqa: L001` with the reason; dotted defs are helpers, -# which bolt never grades +# a def no quantified law reaches def coverage() -> String: "error" diff --git a/ez.lock.toml b/ez.lock.toml index 6c861e2..1a4bffb 100644 --- a/ez.lock.toml +++ b/ez.lock.toml @@ -46,8 +46,8 @@ LICENSE = "309f5aae946e4db157750e002fb179a74ed0fe27fce09a7be68a6977b14f205f" [tools] [tools.bolt] git = "https://github.com/Emerging-Patterns/bolt" -rev = "9700daf3a447089a8795d311912014382a74a2a9" -tag = "v1.27.0" +rev = "26391508a28b69077aaf59b75a80f774a455bca5" +tag = "v1.66.0" root = "." -narHash = "sha256-0S48j2dongVcvP5Oms5a+s5I12sIy91KAgwW0bP7pxM=" +narHash = "sha256-gldg9U4c/Rq1W/9sdhxSPCbujQ8LpHR8edQwbM3tNXM=" entry = "main.bend" diff --git a/ez.toml b/ez.toml index a784329..e4218b3 100644 --- a/ez.toml +++ b/ez.toml @@ -21,8 +21,8 @@ entry = "main.bend" [tools] [tools.bolt] git = "https://github.com/Emerging-Patterns/bolt" -rev = "9700daf3a447089a8795d311912014382a74a2a9" -tag = "v1.27.0" +rev = "26391508a28b69077aaf59b75a80f774a455bca5" +tag = "v1.66.0" root = "." -narHash = "sha256-0S48j2dongVcvP5Oms5a+s5I12sIy91KAgwW0bP7pxM=" +narHash = "sha256-gldg9U4c/Rq1W/9sdhxSPCbujQ8LpHR8edQwbM3tNXM=" entry = "main.bend" diff --git a/flake.lock b/flake.lock index 674ef31..4175ba2 100644 --- a/flake.lock +++ b/flake.lock @@ -31,11 +31,11 @@ ] }, "locked": { - "lastModified": 1794163393, - "narHash": "sha256-RwsUSTKjNvU7qGYKdaFItKGjtI/dy3cEjdDhZuN49tE=", + "lastModified": 1794759086, + "narHash": "sha256-DgFFeqCgFFWGXV+gFMOpvDKHLaVEiI73mxJQud7GUTU=", "owner": "Emerging-Patterns", "repo": "ez", - "rev": "35ace28d9578d8809a55d16941b0633e8fa774f5", + "rev": "c9f485554a0e11e40ee559d27875b052c22cdf65", "type": "github" }, "original": { diff --git a/laws/AbsoluteFormTargetRejected.bend b/laws/AbsoluteFormTargetRejected.bend index 6d546d5..0f8580e 100644 --- a/laws/AbsoluteFormTargetRejected.bend +++ b/laws/AbsoluteFormTargetRejected.bend @@ -1,7 +1,18 @@ +# For every method, target, header lines and body, a request-target that +# does not start with `/` and is not `*` (absolute-form such as +# `http://example.com/a`, or a bare `relative` path) is not origin-form, and +# the request is bad (RFC 9112 §3.2). import Base import ../src/http.bend as Http -# LAW (RFC 9112 §3.2.2): absolute-form is not accepted as origin-form +# LAW (RFC 9112 §3.2.1, §3.2.2): a target with no leading `/` that is not `*` +# is rejected law ask_rejects_absolute_form: - {Http.ask("GET http://example.com/a HTTP/1.1\r\nHost: h\r\n\r\n") + for +method: String + for +target: String + for +ls: List<&2, String> + for body: String + for es: {False{} == String.starts_with(target, "/") : Bool} + for ea: {False{} == String.eq(target, "*") : Bool} + {Http.ask.line(method, target, ls, body) == Http.Bad{"the request-target is not in origin-form"} : Http.Request} diff --git a/laws/Base64EmptyIsEmpty.bend b/laws/Base64EmptyIsEmpty.bend deleted file mode 100644 index d50b2ce..0000000 --- a/laws/Base64EmptyIsEmpty.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/b64.bend as B64 - -# LAW (RFC 4648 §4): the empty string encodes to empty -law b64_empty: - {B64.b64.encode("") == "" : String} diff --git a/laws/Base64EncodesByQuantum.bend b/laws/Base64EncodesByQuantum.bend new file mode 100644 index 0000000..e72300f --- /dev/null +++ b/laws/Base64EncodesByQuantum.bend @@ -0,0 +1,37 @@ +# For every string, Base64 (`b64.encode`, RFC 4648 §4) writes each group of +# three octets as the four alphabet characters of its 24 bits and goes on +# with the rest; a final group of two octets is three characters and one +# `=`, a final group of one octet is two characters and `==`; and the +# encoding is empty exactly when the input is. The RFC 4648 §10 test vectors +# (`f` is `Zg==`, `fo` is `Zm8=`, `foo` is `Zm9v`) and `user:pass` as +# `dXNlcjpwYXNz` are instances. +import Base +import ../src/b64.bend as B64 + +# LAW (RFC 4648 §4): three octets are one full quantum, then the rest +law b64_three: + for +a: Char + for +b: Char + for +c: Char + for s: String + {B64.b64.encode(SCon{a, SCon{b, SCon{c, s}}}) + == B64.b64.quad(Char.to_u32(a), Char.to_u32(b), Char.to_u32(c), 0n) + ++ B64.b64.encode(s) : String} + +# LAW (RFC 4648 §4): two final octets are three characters and one `=` +law b64_two: + for +a: Char + for +b: Char + {B64.b64.encode(SCon{a, SCon{b, SNil{}}}) + == B64.b64.quad(Char.to_u32(a), Char.to_u32(b), 0, 1n) : String} + +# LAW (RFC 4648 §4): one final octet is two characters and `==` +law b64_one: + for +a: Char + {B64.b64.encode(SCon{a, SNil{}}) == B64.b64.quad(Char.to_u32(a), 0, 0, 2n) + : String} + +# LAW (RFC 4648 §4): the encoding is empty exactly when the input is +law b64_empty: + for s: String + {String.is_empty(B64.b64.encode(s)) == String.is_empty(s) : Bool} diff --git a/laws/Base64EncodesF.bend b/laws/Base64EncodesF.bend deleted file mode 100644 index 8db8b18..0000000 --- a/laws/Base64EncodesF.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/b64.bend as B64 - -# LAW (RFC 4648 §10): `f` encodes to `Zg==` -law b64_f: - {B64.b64.encode("f") == "Zg==" : String} diff --git a/laws/Base64EncodesFo.bend b/laws/Base64EncodesFo.bend deleted file mode 100644 index bee0e8e..0000000 --- a/laws/Base64EncodesFo.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/b64.bend as B64 - -# LAW (RFC 4648 §10): `fo` encodes to `Zm8=` -law b64_fo: - {B64.b64.encode("fo") == "Zm8=" : String} diff --git a/laws/Base64EncodesFoo.bend b/laws/Base64EncodesFoo.bend deleted file mode 100644 index 2ee4e09..0000000 --- a/laws/Base64EncodesFoo.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/b64.bend as B64 - -# LAW (RFC 4648 §10): `foo` encodes to `Zm9v` -law b64_foo: - {B64.b64.encode("foo") == "Zm9v" : String} diff --git a/laws/Base64EncodesUserPass.bend b/laws/Base64EncodesUserPass.bend deleted file mode 100644 index 24256a8..0000000 --- a/laws/Base64EncodesUserPass.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/b64.bend as B64 - -# LAW (RFC 4648 §10 / RFC 7617 §2): user:pass is the Basic credential alphabet -law b64_user_pass: - {B64.b64.encode("user:pass") == "dXNlcjpwYXNz" : String} diff --git a/laws/BasicIsBase64OfUserPassword.bend b/laws/BasicIsBase64OfUserPassword.bend index e523327..694184d 100644 --- a/laws/BasicIsBase64OfUserPassword.bend +++ b/laws/BasicIsBase64OfUserPassword.bend @@ -1,8 +1,16 @@ +# For every user and password, Basic credentials (`auth.basic`) are the +# Authorization field `Basic ` and the Base64 of `user:password` +# (laws/Base64EncodesByQuantum.bend); `user`/`pass` as +# `Basic dXNlcjpwYXNz` is an instance. import Base import ../src/http.bend as Http import ../src/auth.bend as Auth +import ../src/b64.bend as B64 # LAW (RFC 7617 §2): Basic credentials are Base64 of user:password law basic_user_pass: - {Auth.auth.basic("user", "pass") - == Http.H{"Authorization", "Basic dXNlcjpwYXNz"} : Http.Header} + for user: String + for password: String + {Auth.auth.basic(user, password) + == Http.H{"Authorization", "Basic " ++ B64.b64.encode(user ++ ":" ++ password)} + : Http.Header} diff --git a/laws/BearerTokenAcceptsPlain.bend b/laws/BearerTokenAcceptsPlain.bend deleted file mode 100644 index eaa2eda..0000000 --- a/laws/BearerTokenAcceptsPlain.bend +++ /dev/null @@ -1,8 +0,0 @@ -import Base -import ../src/http.bend as Http - -# --- RFC 6750 / 7617 / 4648 credentials --- - -# LAW (RFC 6750 §2.1): a token with no whitespace is acceptable -law token_ok_plain: - {Http.token.ok("abc") == True{} : Bool} diff --git a/laws/BearerTokenHasNoWhitespace.bend b/laws/BearerTokenHasNoWhitespace.bend new file mode 100644 index 0000000..61ac1d3 --- /dev/null +++ b/laws/BearerTokenHasNoWhitespace.bend @@ -0,0 +1,24 @@ +# For every string, a bearer token (`token.ok`, RFC 6750 §2.1) is rejected +# when a whitespace character (space, tab, newline, CR, VT, FF) appears +# anywhere in it, and a leading non-whitespace character leaves the verdict +# to the rest; so a token is accepted exactly when it has no whitespace +# (`abc` is accepted; `a b`, `a\tb` and `a\nb` are rejected). +import Base +import ../src/http.bend as Http + +# --- RFC 6750 / 7617 / 4648 credentials --- + +# LAW (RFC 6750 §2.1): a whitespace character anywhere rejects the token +law token_ok_space: + for a: String + for +c: Char + for +b: String + for +e: {Char.is_space(c) == True{} : Bool} + {Http.token.ok(a ++ SCon{c, b}) == False{} : Bool} + +# LAW (RFC 6750 §2.1): a non-whitespace character leaves the rest to decide +law token_ok_plain: + for c: Char + for t: String + for e: {Char.is_space(c) == False{} : Bool} + {Http.token.ok(SCon{c, t}) == Http.token.ok(t) : Bool} diff --git a/laws/BearerTokenRejectsNewline.bend b/laws/BearerTokenRejectsNewline.bend deleted file mode 100644 index f865b14..0000000 --- a/laws/BearerTokenRejectsNewline.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 6750 §2.1): a newline is not a bearer token character -law token_ok_newline: - {Http.token.ok("a\nb") == False{} : Bool} diff --git a/laws/BearerTokenRejectsSpace.bend b/laws/BearerTokenRejectsSpace.bend deleted file mode 100644 index f6698ff..0000000 --- a/laws/BearerTokenRejectsSpace.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 6750 §2.1): a space is not a bearer token character -law token_ok_space: - {Http.token.ok("a b") == False{} : Bool} diff --git a/laws/BearerTokenRejectsTab.bend b/laws/BearerTokenRejectsTab.bend deleted file mode 100644 index e52ba40..0000000 --- a/laws/BearerTokenRejectsTab.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 6750 §2.1): a tab is not a bearer token character -law token_ok_tab: - {Http.token.ok("a\tb") == False{} : Bool} diff --git a/laws/CacheDirectiveNamesIgnoreCase.bend b/laws/CacheDirectiveNamesIgnoreCase.bend deleted file mode 100644 index a82e194..0000000 --- a/laws/CacheDirectiveNamesIgnoreCase.bend +++ /dev/null @@ -1,9 +0,0 @@ -import Base -import ../src/cache.bend as Cache - -# --- RFC 9111 cache directives --- - -# LAW (RFC 9111 §5.2): directive names are case-insensitive -law cache_directive_case: - {Cache.cache.parse("No-Store, MAX-AGE=0, Public") - == Cache.Cc{True{}, False{}, True{}, False{}, "0", ""} : Cache.Cc} diff --git a/laws/CacheIgnoresUnknownDirective.bend b/laws/CacheIgnoresUnknownDirective.bend deleted file mode 100644 index 7c0e05e..0000000 --- a/laws/CacheIgnoresUnknownDirective.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/cache.bend as Cache - -# LAW (RFC 9111 §5.2): an unrecognized directive is ignored -law cache_ignores_s_maxage: - {Cache.cache.parse("s-maxage=9, max-age=3") - == Cache.Cc{False{}, False{}, False{}, False{}, "3", ""} : Cache.Cc} diff --git a/laws/CacheMaxAgeIgnoresJunk.bend b/laws/CacheMaxAgeIgnoresJunk.bend deleted file mode 100644 index 46e1b28..0000000 --- a/laws/CacheMaxAgeIgnoresJunk.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/cache.bend as Cache - -# LAW (RFC 9111 §5.2.1.1): a non-digit max-age is not recorded -law cache_max_age_ignores_junk: - {Cache.cache.parse("max-age=nope") - == Cache.Cc{False{}, False{}, False{}, False{}, "", ""} : Cache.Cc} diff --git a/laws/CacheReadsKnownDirectives.bend b/laws/CacheReadsKnownDirectives.bend index c598b83..80936e9 100644 --- a/laws/CacheReadsKnownDirectives.bend +++ b/laws/CacheReadsKnownDirectives.bend @@ -1,7 +1,95 @@ +# For every directive state `c` read so far and every directive text +# `piece`, Cache-Control is read one directive at a time, left to right, +# each over what the ones before it recorded (`cache.fold`). A directive with +# no `=` whose name, trimmed and in any case, is no-store, no-cache, public +# or private sets that flag and keeps the rest. A `max-age=` directive whose +# name is max-age in any case records its trimmed argument when that is +# delta-seconds and is ignored otherwise. A `name=value` directive with any +# other name is ignored (RFC 9111 §5.2: names are case-insensitive and +# unrecognized directives are ignored). import Base +import ../src/http.bend as Http import ../src/cache.bend as Cache -# LAW (RFC 9111 §5.2): no-store, no-cache, public, private, and max-age -law cache_directives: - {Cache.cache.parse("no-store, no-cache, public, private, max-age=5") - == Cache.Cc{True{}, True{}, True{}, True{}, "5", ""} : Cache.Cc} +# LAW (RFC 9111 §5.2): directives are read left to right +law fold_each: + for h: String + for t: List<&2, String> + for c: Cache.Cc + {Cache.cache.fold(h <> t, c) == Cache.cache.fold(t, Cache.cache.one(c, String.trim(h))) + : Cache.Cc} + +# LAW (RFC 9111 §5.2): after the last directive, what was read is the result +law fold_end: + for c: Cache.Cc + {Cache.cache.fold([], c) == c : Cache.Cc} + +# LAW (RFC 9111 §5.2.2.5): no-store, in any case, sets no-store +law one_no_store: + for c: Cache.Cc + for +piece: String + for e1: {Http.NoCut{} == Http.divide(piece, "=") : Http.Cut} + for e2: {"no-store" == String.to_lower(String.trim(piece)) : String} + {Cache.cache.one(c, piece) == Cache.cache.store(c) : Cache.Cc} + +# LAW (RFC 9111 §5.2.2.4): no-cache, in any case, sets no-cache +law one_no_cache: + for c: Cache.Cc + for +piece: String + for e1: {Http.NoCut{} == Http.divide(piece, "=") : Http.Cut} + for e2: {"no-cache" == String.to_lower(String.trim(piece)) : String} + {Cache.cache.one(c, piece) == Cache.cache.revalidate(c) : Cache.Cc} + +# LAW (RFC 9111 §5.2.2.9): public, in any case, sets public +law one_public: + for c: Cache.Cc + for +piece: String + for e1: {Http.NoCut{} == Http.divide(piece, "=") : Http.Cut} + for e2: {"public" == String.to_lower(String.trim(piece)) : String} + {Cache.cache.one(c, piece) == Cache.cache.pub(c) : Cache.Cc} + +# LAW (RFC 9111 §5.2.2.7): private, in any case, sets private +law one_private: + for c: Cache.Cc + for +piece: String + for e1: {Http.NoCut{} == Http.divide(piece, "=") : Http.Cut} + for e2: {"private" == String.to_lower(String.trim(piece)) : String} + {Cache.cache.one(c, piece) == Cache.cache.priv(c) : Cache.Cc} + +# LAW (RFC 9111 §5.2.2.1): max-age, in any case, records delta-seconds +law one_max_age: + for c: Cache.Cc + for +piece: String + for +before: String + for +after: String + for n: Nat + for e1: {Http.Cut{before, after} == Http.divide(piece, "=") : Http.Cut} + for e2: {"max-age" == String.to_lower(String.trim(before)) : String} + for e3: {Some{n} == Http.digits.read(String.trim(after)) : Maybe<&2, Nat>} + {Cache.cache.one(c, piece) == Cache.cache.age(c, String.trim(after)) : Cache.Cc} + +# LAW (RFC 9111 §5.2.1.1): a max-age argument that is not delta-seconds is +# ignored +law one_max_age_junk: + for c: Cache.Cc + for +piece: String + for +before: String + for +after: String + for e1: {Http.Cut{before, after} == Http.divide(piece, "=") : Http.Cut} + for e2: {"max-age" == String.to_lower(String.trim(before)) : String} + for e3: {None{} == Http.digits.read(String.trim(after)) : Maybe<&2, Nat>} + {Cache.cache.one(c, piece) == c : Cache.Cc} + +# LAW (RFC 9111 §5.2): a name=value directive of no recorded name is ignored +law one_unknown: + for c: Cache.Cc + for +piece: String + for +before: String + for +after: String + for e1: {Http.Cut{before, after} == Http.divide(piece, "=") : Http.Cut} + for e2: {False{} == String.eq(String.to_lower(String.trim(before)), "no-store") : Bool} + for e3: {False{} == String.eq(String.to_lower(String.trim(before)), "no-cache") : Bool} + for e4: {False{} == String.eq(String.to_lower(String.trim(before)), "max-age") : Bool} + for e5: {False{} == String.eq(String.to_lower(String.trim(before)), "public") : Bool} + for e6: {False{} == String.eq(String.to_lower(String.trim(before)), "private") : Bool} + {Cache.cache.one(c, piece) == c : Cache.Cc} diff --git a/laws/CacheRecordsExpires.bend b/laws/CacheRecordsExpires.bend index e31a7ca..4ab0ce5 100644 --- a/laws/CacheRecordsExpires.bend +++ b/laws/CacheRecordsExpires.bend @@ -1,8 +1,21 @@ +# For every Cache-Control value and Expires text, the directives noted with +# an Expires header (`cache.note`) are exactly the directives read from the +# Cache-Control value, with that Expires text recorded beside them; noting +# Expires changes no directive. import Base import ../src/cache.bend as Cache # LAW (RFC 9111 §5.3): Expires is recorded beside Cache-Control law cache_note_expires: - {Cache.cache.note("max-age=0", "Wed, 21 Oct 2099 07:28:00 GMT") - == Cache.Cc{False{}, False{}, False{}, False{}, "0", - "Wed, 21 Oct 2099 07:28:00 GMT"} : Cache.Cc} + for value: String + for when: String + for no_store: Bool + for no_cache: Bool + for public: Bool + for private: Bool + for max_age: String + for expires: String + for e: {Cache.Cc{no_store, no_cache, public, private, max_age, expires} + == Cache.cache.parse(value) : Cache.Cc} + {Cache.cache.note(value, when) + == Cache.Cc{no_store, no_cache, public, private, max_age, when} : Cache.Cc} diff --git a/laws/CacheRecordsMaxAge.bend b/laws/CacheRecordsMaxAge.bend index 2d4c8ac..28ba3a1 100644 --- a/laws/CacheRecordsMaxAge.bend +++ b/laws/CacheRecordsMaxAge.bend @@ -1,6 +1,15 @@ +# For every directive state and every max-age argument that is +# delta-seconds, recording it (`cache.age`, what a max-age directive does, +# laws/CacheReadsKnownDirectives.bend) leaves max-age present +# (`cache.max_age`), so it is what freshness uses and it overrides Expires. import Base +import ../src/http.bend as Http import ../src/cache.bend as Cache -# LAW (RFC 9111 §4.2.1): a present max-age is what freshness uses +# LAW (RFC 9111 §4.2.1): a recorded max-age is present law cache_max_age_present: - {Cache.cache.max_age(Cache.cache.parse("max-age=1")) == True{} : Bool} + for c: Cache.Cc + for raw: String + for n: Nat + for e: {Some{n} == Http.digits.read(raw) : Maybe<&2, Nat>} + {Cache.cache.max_age(Cache.cache.age(c, raw)) == True{} : Bool} diff --git a/laws/CacheRecordsNoCache.bend b/laws/CacheRecordsNoCache.bend deleted file mode 100644 index 656c50c..0000000 --- a/laws/CacheRecordsNoCache.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/cache.bend as Cache - -# LAW (RFC 9111 §5.2.2.2): no-cache alone is recorded and not fresh -law cache_no_cache_alone: - {Cache.cache.parse("no-cache") - == Cache.Cc{False{}, True{}, False{}, False{}, "", ""} : Cache.Cc} diff --git a/laws/CacheRecordsPrivate.bend b/laws/CacheRecordsPrivate.bend deleted file mode 100644 index 555c413..0000000 --- a/laws/CacheRecordsPrivate.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/cache.bend as Cache - -# LAW (RFC 9111 §5.2.2.6): private alone is recorded -law cache_private_alone: - {Cache.cache.parse("private") - == Cache.Cc{False{}, False{}, False{}, True{}, "", ""} : Cache.Cc} diff --git a/laws/ChunkSizeHexIgnoresCase.bend b/laws/ChunkSizeHexIgnoresCase.bend index 63ffc29..042446c 100644 --- a/laws/ChunkSizeHexIgnoresCase.bend +++ b/laws/ChunkSizeHexIgnoresCase.bend @@ -1,6 +1,42 @@ +# For every hex reading so far `acc` and text `t` after the digit, the +# chunk-size reader (`hex.go`) reads each letter digit `a` to `f` exactly as +# its capital `A` to `F` (RFC 9112 §7.1: chunk-size is HEXDIG, and RFC 5234 +# §2.3 makes its letters case-insensitive). import Base import ../src/http.bend as Http # LAW (RFC 9112 §7.1): `a` and `A` are the same chunk-size digit -law hexlen_alpha: - {Http.hexlen("a") == Http.hexlen("A") : Nat} +law hex_a: + for +acc: Nat + for t: String + {Http.hex.go(SCon{'a', t}, acc) == Http.hex.go(SCon{'A', t}, acc) : Nat} + +# LAW (RFC 9112 §7.1): `b` and `B` are the same chunk-size digit +law hex_b: + for +acc: Nat + for t: String + {Http.hex.go(SCon{'b', t}, acc) == Http.hex.go(SCon{'B', t}, acc) : Nat} + +# LAW (RFC 9112 §7.1): `c` and `C` are the same chunk-size digit +law hex_c: + for +acc: Nat + for t: String + {Http.hex.go(SCon{'c', t}, acc) == Http.hex.go(SCon{'C', t}, acc) : Nat} + +# LAW (RFC 9112 §7.1): `d` and `D` are the same chunk-size digit +law hex_d: + for +acc: Nat + for t: String + {Http.hex.go(SCon{'d', t}, acc) == Http.hex.go(SCon{'D', t}, acc) : Nat} + +# LAW (RFC 9112 §7.1): `e` and `E` are the same chunk-size digit +law hex_e: + for +acc: Nat + for t: String + {Http.hex.go(SCon{'e', t}, acc) == Http.hex.go(SCon{'E', t}, acc) : Nat} + +# LAW (RFC 9112 §7.1): `f` and `F` are the same chunk-size digit +law hex_f: + for +acc: Nat + for t: String + {Http.hex.go(SCon{'f', t}, acc) == Http.hex.go(SCon{'F', t}, acc) : Nat} diff --git a/laws/ChunkSizeReadsHexSkipsExtension.bend b/laws/ChunkSizeReadsHexSkipsExtension.bend deleted file mode 100644 index 406ed23..0000000 --- a/laws/ChunkSizeReadsHexSkipsExtension.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9112 §7.1): chunk-size is hexadecimal, and an extension is skipped -law hexlen_extension_and_case: - {Http.hexlen("5;ext=1") == 5n : Nat} diff --git a/laws/ChunkedBodyJoinsChunks.bend b/laws/ChunkedBodyJoinsChunks.bend index 6dbfd21..41de736 100644 --- a/laws/ChunkedBodyJoinsChunks.bend +++ b/laws/ChunkedBodyJoinsChunks.bend @@ -1,8 +1,16 @@ +# For every status, header fields and chunked body whose chunk sizes are +# all hexadecimal and reach the last chunk (`chunks.scan` finds nothing +# wrong), the response's body is the chunks joined (`dechunk`, RFC 9112 +# §7.1); what the joined chunks are is laws/ChunkDataUnchanged.bend. import Base import ../src/http.bend as Http -# LAW (RFC 9112 §7.1): a chunked response body is the concatenated chunks -law parse_chunked_body: - {Http.parse("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n4\r\nwiki\r\n5\r\npedia\r\n0\r\n\r\n") - == Http.Reply{200, [Http.H{"Transfer-Encoding", "chunked"}], "wikipedia"} +# LAW (RFC 9112 §7.1): a well-framed chunked body is its chunks joined +law chunked_joins: + for st: U32 + for hs: List<&2, Http.Header> + for +body: String + for e: {None{} == Http.chunks.scan(String.length(body), Http.divide(body, "\r\n")) + : Maybe<&2, String>} + {Http.parse.chunks(st, hs, body) == Http.Reply{st, hs, Http.dechunk(body)} : Http.Reply} diff --git a/laws/ChunkedNameIgnoresCase.bend b/laws/ChunkedNameIgnoresCase.bend deleted file mode 100644 index c8f5dc6..0000000 --- a/laws/ChunkedNameIgnoresCase.bend +++ /dev/null @@ -1,8 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9112 §7.1): chunked is recognized in any case -law parse_chunked_ignores_case: - {Http.parse("HTTP/1.1 200 OK\r\nTransfer-Encoding: CHUNKED\r\n\r\n1\r\nZ\r\n0\r\n\r\n") - == Http.Reply{200, [Http.H{"Transfer-Encoding", "CHUNKED"}], "Z"} - : Http.Reply} diff --git a/laws/ChunksStopWithoutFuel.bend b/laws/ChunksStopWithoutFuel.bend index 5a97cae..fab530c 100644 --- a/laws/ChunksStopWithoutFuel.bend +++ b/laws/ChunksStopWithoutFuel.bend @@ -1,6 +1,15 @@ +# For every cut `c` and fuel `f`, the chunked decoder (`chunks`) writes +# nothing once its fuel is spent, and nothing when no CRLF is left to end a +# chunk-size line (RFC 9112 §7.1: a chunk-size line ends with CRLF). import Base import ../src/http.bend as Http -# LAW (RFC 9112 §7.1): no fuel left means no more chunks -law chunks_empty_fuel: - {Http.chunks(0n, Http.NoCut{}) == "" : String} +# LAW: with no fuel left the decoder writes nothing +law chunks_no_fuel: + for c: Http.Cut + {Http.chunks(0n, c) == "" : String} + +# LAW (RFC 9112 §7.1): with no chunk-size line left the decoder writes nothing +law chunks_no_cut: + for f: Nat + {Http.chunks(f, Http.NoCut{}) == "" : String} diff --git a/laws/ContentLengthReadsDecimal.bend b/laws/ContentLengthReadsDecimal.bend index 06a69bb..4ff84b0 100644 --- a/laws/ContentLengthReadsDecimal.bend +++ b/laws/ContentLengthReadsDecimal.bend @@ -1,6 +1,25 @@ +# For every reading so far `acc`, digits still allowed `1n+k`, digit `c` and +# text `t` after it, the Content-Length reader (`digits.go`) takes a decimal +# digit as ten times what it read so far plus the digit's value and reads +# on, and at the end of the text with digits still allowed it has read +# `acc` (RFC 9110 §8.6: Content-Length = 1*DIGIT, a decimal count). import Base import ../src/http.bend as Http -# LAW (RFC 9112 §6.3): Content-Length is a decimal, not a prefix of junk -law digits_read_decimal: - {Http.digits.read("12") == Some{12n} : Maybe<&2, Nat>} +# LAW (RFC 9110 §8.6): a decimal digit is ten times the reading so far plus +# its value +law digits_step: + for c: Char + for t: String + for +acc: Nat + for k: Nat + for e: {True{} == U32.is_lt(Http.digits.val(c), 10) : Bool} + {Http.digits.go(SCon{c, t}, acc, 1n+k) + == Http.digits.go(t, Nat.add(Nat.mul(acc, 10n), U32.to_nat(Http.digits.val(c))), k) + : Maybe<&2, Nat>} + +# LAW (RFC 9110 §8.6): at the end of the digits the reading is the number +law digits_end: + for acc: Nat + for k: Nat + {Http.digits.go("", acc, 1n+k) == Some{acc} : Maybe<&2, Nat>} diff --git a/laws/ContentLengthRejectsJunk.bend b/laws/ContentLengthRejectsJunk.bend index c002203..4cecfb6 100644 --- a/laws/ContentLengthRejectsJunk.bend +++ b/laws/ContentLengthRejectsJunk.bend @@ -1,6 +1,15 @@ +# For every reading so far `acc`, digits still allowed `1n+k`, character `c` +# that is not a decimal digit and text `t` after it, the Content-Length +# reader (`digits.go`) reads nothing (RFC 9110 §8.6: Content-Length = +# 1*DIGIT, so a value with any other character is not a length). import Base import ../src/http.bend as Http -# LAW (RFC 9112 §6.3): a Content-Length that is not all digits is absent -law digits_read_rejects_junk: - {Http.digits.read("12a") == None{} : Maybe<&2, Nat>} +# LAW (RFC 9110 §8.6): a character that is not a digit leaves no length +law digits_junk: + for c: Char + for t: String + for acc: Nat + for k: Nat + for e: {False{} == U32.is_lt(Http.digits.val(c), 10) : Bool} + {Http.digits.go(SCon{c, t}, acc, 1n+k) == None{} : Maybe<&2, Nat>} diff --git a/laws/ContentLengthTakesPrefix.bend b/laws/ContentLengthTakesPrefix.bend deleted file mode 100644 index 60a8c16..0000000 --- a/laws/ContentLengthTakesPrefix.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §8.6): Content-Length takes that many octets and no more -law parse_clen_takes_prefix: - {Http.parse("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\nhello!!") - == Http.Reply{200, [Http.H{"Content-Length", "5"}], "hello"} : Http.Reply} diff --git a/laws/ContinuationLineRejected.bend b/laws/ContinuationLineRejected.bend index 137f940..4e4a72b 100644 --- a/laws/ContinuationLineRejected.bend +++ b/laws/ContinuationLineRejected.bend @@ -1,6 +1,10 @@ +# For every header line with no colon, such as an obs-fold continuation +# line (` folded`), the line gives no field (RFC 9112 §5.1, §5.2). import Base import ../src/http.bend as Http -# LAW: a continuation line with no colon is not a field +# LAW (RFC 9112 §5.2): a line with no colon is not a field law head_line_rejects_continuation: - {Http.head.line(" folded") == None{} : Maybe<&2, Http.Header>} + for h: String + for e: {Http.NoCut{} == Http.divide(h, ":") : Http.Cut} + {Http.head.line(h) == None{} : Maybe<&2, Http.Header>} diff --git a/laws/CookieAliveUnderMaxAge.bend b/laws/CookieAliveUnderMaxAge.bend index 236fb7b..3b7c1c0 100644 --- a/laws/CookieAliveUnderMaxAge.bend +++ b/laws/CookieAliveUnderMaxAge.bend @@ -1,6 +1,23 @@ +# For every Max-Age text and age in seconds: a Max-Age that reads as the +# decimal digits of n keeps the cookie alive exactly while its age is below n +# (so Max-Age=0 is never alive and Max-Age=1 is alive at 0 s, not at 1 s), +# and a Max-Age that is not digits (absent, a session cookie, or junk) +# leaves it alive (RFC 6265 §5.2.2, §5.3 step 3). import Base +import ../src/http.bend as Http import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.4): an age under Max-Age is still alive -law cookie_max_age_open: - {Cookie.cookie.alive("10", 0n) == True{} : Bool} +# LAW (RFC 6265 §5.2.2): alive while the age is below Max-Age +law cookie_alive_max_age: + for max_age: String + for +n: Nat + for +age: Nat + for e: {Some{n} == Http.digits.read(max_age) : Maybe<&2, Nat>} + {Cookie.cookie.alive(max_age, age) == Nat.is_lt(age, n) : Bool} + +# LAW (§5.3 step 3): no Max-Age digits, a session cookie, alive +law cookie_alive_session: + for max_age: String + for +age: Nat + for e: {None{} == Http.digits.read(max_age) : Maybe<&2, Nat>} + {Cookie.cookie.alive(max_age, age) == True{} : Bool} diff --git a/laws/CookieAttributesJoinWithSemicolons.bend b/laws/CookieAttributesJoinWithSemicolons.bend index c92b5b7..9bcca8f 100644 --- a/laws/CookieAttributesJoinWithSemicolons.bend +++ b/laws/CookieAttributesJoinWithSemicolons.bend @@ -1,12 +1,66 @@ +# For every cookie, its Set-Cookie field value (RFC 6265 §4.1.1) is +# `name=value`, then `; Expires=`, `; Max-Age=`, `; Domain=` (only when a +# Domain attribute was set, not host-only), `; Path=` each with its value +# when the value is not empty, then `; Secure` and `; HttpOnly` when their +# flags are set, then `; SameSite=` with its value when not empty: the +# attributes joined by `; `. import Base import ../src/cookie.bend as Cookie -# --- RFC 6265 cookies --- +# LAW (RFC 6265 §4.1.1): the attributes in order after name=value +law cookie_line: + for +name: String + for +value: String + for +expires: String + for +max_age: String + for +domain: String + for +path: String + for +secure: Bool + for +http_only: Bool + for +same_site: String + for +host_only: Bool + {Cookie.cookie.line(Cookie.Cookie{name, value, expires, max_age, domain, path, secure, + http_only, same_site, host_only}) + == name ++ "=" ++ value + ++ Cookie.cookie.opt("; Expires=", expires) + ++ Cookie.cookie.opt("; Max-Age=", max_age) + ++ Cookie.cookie.domain_text(domain, host_only) + ++ Cookie.cookie.opt("; Path=", path) + ++ Cookie.cookie.mark("Secure", secure) + ++ Cookie.cookie.mark("HttpOnly", http_only) + ++ Cookie.cookie.opt("; SameSite=", same_site) : String} -# LAW (RFC 6265 §4.1.1): attributes serialize with `; ` separators -law cookie_line_attributes: - {Cookie.cookie.line(Cookie.Cookie{"a", "b", - "Wed, 21 Oct 2015 07:28:00 GMT", "12", "example.com", "/app", - True{}, True{}, "Lax", False{}}) - == "a=b; Expires=Wed, 21 Oct 2015 07:28:00 GMT; Max-Age=12; Domain=example.com; Path=/app; Secure; HttpOnly; SameSite=Lax" - : String} +# LAW: an empty attribute value writes nothing +law cookie_opt_empty: + for prefix: String + for +value: String + for e: {True{} == String.is_empty(value) : Bool} + {Cookie.cookie.opt(prefix, value) == "" : String} + +# LAW: any other value writes its prefix and the value +law cookie_opt_set: + for +prefix: String + for +value: String + for e: {False{} == String.is_empty(value) : Bool} + {Cookie.cookie.opt(prefix, value) == prefix ++ value : String} + +# LAW: a set flag writes `; ` and its label +law cookie_mark_on: + for +label: String + {Cookie.cookie.mark(label, True{}) == "; " ++ label : String} + +# LAW: an unset flag writes nothing +law cookie_mark_off: + for label: String + {Cookie.cookie.mark(label, False{}) == "" : String} + +# LAW: a host-only cookie writes no Domain +law cookie_domain_text_host_only: + for domain: String + {Cookie.cookie.domain_text(domain, True{}) == "" : String} + +# LAW: a Domain attribute is written as `; Domain=` +law cookie_domain_text_set: + for +domain: String + {Cookie.cookie.domain_text(domain, False{}) + == Cookie.cookie.opt("; Domain=", domain) : String} diff --git a/laws/CookieDefaultPathFallsBackToRoot.bend b/laws/CookieDefaultPathFallsBackToRoot.bend index 8a952b7..cb98995 100644 --- a/laws/CookieDefaultPathFallsBackToRoot.bend +++ b/laws/CookieDefaultPathFallsBackToRoot.bend @@ -1,6 +1,10 @@ +# For every request path with fewer than two `/` (so `/a` and `/`), the +# default-path of a cookie it set is `/` (RFC 6265 §5.1.4 steps 2-3). import Base import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.1.4): fewer than two slashes means default-path `/` +# LAW (RFC 6265 §5.1.4 steps 2-3): fewer than two slashes, default-path / law cookie_default_path_root: - {Cookie.cookie.default_path("/a") == "/" : String} + for +p: String + for e: {True{} == Nat.is_lt(Cookie.cookie.slashes(p), 2n) : Bool} + {Cookie.cookie.default_path(p) == "/" : String} diff --git a/laws/CookieDefaultPathIsDirectory.bend b/laws/CookieDefaultPathIsDirectory.bend index d6c621c..cdad5b8 100644 --- a/laws/CookieDefaultPathIsDirectory.bend +++ b/laws/CookieDefaultPathIsDirectory.bend @@ -1,6 +1,19 @@ +# For every request path with two `/` or more, the default-path of a cookie +# it set is its characters up to, not including, the right-most `/`, so +# `/a/b` gives `/a` and `/foo/bar/` gives `/foo/bar` (RFC 6265 §5.1.4 step +# 4); `cookie.before` is that prefix: the reversed path with everything +# through its first `/` dropped, reversed back. import Base import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.1.4): default-path is the directory of a path with two slashes +# LAW (RFC 6265 §5.1.4 step 4): the path up to its right-most slash law cookie_default_path_dir: - {Cookie.cookie.default_path("/a/b") == "/a" : String} + for +p: String + for e: {False{} == Nat.is_lt(Cookie.cookie.slashes(p), 2n) : Bool} + {Cookie.cookie.default_path(p) == Cookie.cookie.before(p) : String} + +# LAW: the prefix before the right-most slash +law cookie_before: + for p: String + {Cookie.cookie.before(p) + == String.reverse(Cookie.cookie.skip(String.reverse(p))) : String} diff --git a/laws/CookieDefaultPathNeedsTwoSlashes.bend b/laws/CookieDefaultPathNeedsTwoSlashes.bend deleted file mode 100644 index 641915a..0000000 --- a/laws/CookieDefaultPathNeedsTwoSlashes.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/cookie.bend as Cookie - -# LAW (RFC 6265 §5.1.4): one slash is not enough for a directory default-path -law cookie_default_path_one_slash: - {Cookie.cookie.default_path("/") == "/" : String} diff --git a/laws/CookieDefaultPathOmitsTrailingSlash.bend b/laws/CookieDefaultPathOmitsTrailingSlash.bend deleted file mode 100644 index c5bacec..0000000 --- a/laws/CookieDefaultPathOmitsTrailingSlash.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/cookie.bend as Cookie - -# LAW (RFC 6265 §5.1.4): a trailing slash keeps the directory, not the slash -law cookie_default_path_trailing: - {Cookie.cookie.default_path("/foo/bar/") == "/foo/bar" : String} diff --git a/laws/CookieDomainLowercased.bend b/laws/CookieDomainLowercased.bend index a61c740..ec79144 100644 --- a/laws/CookieDomainLowercased.bend +++ b/laws/CookieDomainLowercased.bend @@ -1,8 +1,31 @@ +# For every cookie and Domain attribute value, the attribute (named +# `domain` once lowercased) stores the value lowercased as the cookie's +# domain and clears host-only (RFC 6265 §5.2.3), leaving every other field +# as it was. import Base import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.2.3): a Domain attribute is stored lowercase -law cookie_domain_lowercased: - {Cookie.cookie.parse("a=b; Domain=Example.COM") - == Some{Cookie.Cookie{"a", "b", "", "", "example.com", "", False{}, - False{}, "", False{}}} : Maybe<&2, Cookie.Cookie>} +# LAW (RFC 6265 §5.2.3): Domain is stored lowercase +law cookie_named_domain: + for c: Cookie.Cookie + for value: String + {Cookie.cookie.named(c, "domain", value) + == Cookie.cookie.domain(c, String.to_lower(value)) : Cookie.Cookie} + +# LAW (§5.3 step 6): a Domain attribute clears host-only +law cookie_domain_sets: + for +name: String + for +value: String + for +expires: String + for +max_age: String + for +domain: String + for +path: String + for +secure: Bool + for +http_only: Bool + for +same_site: String + for +host_only: Bool + for host: String + {Cookie.cookie.domain(Cookie.Cookie{name, value, expires, max_age, domain, path, secure, + http_only, same_site, host_only}, host) + == Cookie.Cookie{name, value, expires, max_age, host, path, secure, + http_only, same_site, False{}} : Cookie.Cookie} diff --git a/laws/CookieDomainMatchesDotSuffix.bend b/laws/CookieDomainMatchesDotSuffix.bend index ff0732f..dbddf5c 100644 --- a/laws/CookieDomainMatchesDotSuffix.bend +++ b/laws/CookieDomainMatchesDotSuffix.bend @@ -1,7 +1,18 @@ +# For every request host and cookie domain that differ (compared +# lowercase), when the host is not an IPv4 literal a Domain cookie +# domain-matches exactly when the host ends with `.` and the domain, so +# `www.example.com` matches `example.com` and `notexample.com` does not +# (RFC 6265 §5.1.3). import Base import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.1.3): a domain-match allows a leading-dot suffix +# LAW (RFC 6265 §5.1.3): a host name matches a domain it ends with after a dot law cookie_domain_suffix: - {Cookie.cookie.domain_ok("www.example.com", "example.com", False{}) - == True{} : Bool} + for +host: String + for +domain: String + for e1: {False{} == String.eq(String.to_lower(host), String.to_lower(domain)) + : Bool} + for e2: {False{} == Cookie.cookie.ipv4(String.to_lower(host)) : Bool} + {Cookie.cookie.domain_ok(host, domain, False{}) + == String.ends_with(String.to_lower(host), "." ++ String.to_lower(domain)) + : Bool} diff --git a/laws/CookieDomainNeedsDotBeforeSuffix.bend b/laws/CookieDomainNeedsDotBeforeSuffix.bend deleted file mode 100644 index 478ee00..0000000 --- a/laws/CookieDomainNeedsDotBeforeSuffix.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/cookie.bend as Cookie - -# LAW (RFC 6265 §5.1.3): a suffix without the separating dot does not match -law cookie_domain_not_suffix: - {Cookie.cookie.domain_ok("notexample.com", "example.com", False{}) - == False{} : Bool} diff --git a/laws/CookieHostOnlyNotSentElsewhere.bend b/laws/CookieHostOnlyNotSentElsewhere.bend index faf5551..e116a2a 100644 --- a/laws/CookieHostOnlyNotSentElsewhere.bend +++ b/laws/CookieHostOnlyNotSentElsewhere.bend @@ -1,8 +1,24 @@ +# For every request and cookie, a cookie whose domain does not match the +# request host (host-only: not that exact host; no Domain and no host: +# never) is not sent (RFC 6265 §5.4 step 1). import Base import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.4): a host-only cookie is not sent to another host -law cookie_send_other_host: - {Cookie.cookie.send("other.com", "/", False{}, - Cookie.cookie.receive("example.com", "/", Cookie.cookie.new("a", "b"))) - == False{} : Bool} +# LAW (RFC 6265 §5.4 step 1): no domain-match, not sent +law cookie_send_domain_miss: + for +host: String + for req: String + for tls: Bool + for +name: String + for +value: String + for +expires: String + for +max_age: String + for +domain: String + for +path: String + for +secure: Bool + for +http_only: Bool + for +same_site: String + for +host_only: Bool + for e: {False{} == Cookie.cookie.domain_ok(host, domain, host_only) : Bool} + {Cookie.cookie.send(host, req, tls, Cookie.Cookie{name, value, expires, max_age, domain, path, secure, + http_only, same_site, host_only}) == False{} : Bool} diff --git a/laws/CookieHostOnlySentToHost.bend b/laws/CookieHostOnlySentToHost.bend index e1a16d7..5f50557 100644 --- a/laws/CookieHostOnlySentToHost.bend +++ b/laws/CookieHostOnlySentToHost.bend @@ -1,8 +1,39 @@ +# For every request and cookie whose domain matches the request host, the +# cookie is sent exactly when its path matches the request path and, when +# it is Secure, the request is over TLS (RFC 6265 §5.4 step 1). import Base import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.4): a host-only cookie is sent on its host and default-path -law cookie_send_host_only: - {Cookie.cookie.send("example.com", "/a/x", False{}, - Cookie.cookie.receive("Example.COM", "/a/b", Cookie.cookie.new("a", "b"))) - == True{} : Bool} +# LAW (RFC 6265 §5.4 step 1): a domain-match leaves path and Secure to decide +law cookie_send_domain_hit: + for +host: String + for +req: String + for +tls: Bool + for +name: String + for +value: String + for +expires: String + for +max_age: String + for +domain: String + for +path: String + for +secure: Bool + for +http_only: Bool + for +same_site: String + for +host_only: Bool + for e: {True{} == Cookie.cookie.domain_ok(host, domain, host_only) : Bool} + {Cookie.cookie.send(host, req, tls, Cookie.Cookie{name, value, expires, max_age, domain, path, secure, + http_only, same_site, host_only}) + == Cookie.cookie.send.path(tls, secure, Cookie.cookie.path_ok(req, path)) + : Bool} + +# LAW: no path-match, not sent +law cookie_send_path_miss: + for tls: Bool + for secure: Bool + {Cookie.cookie.send.path(tls, secure, False{}) == False{} : Bool} + +# LAW: a path-match leaves the Secure rule to decide +law cookie_send_path_hit: + for +tls: Bool + for +secure: Bool + {Cookie.cookie.send.path(tls, secure, True{}) + == Cookie.cookie.send.secure(tls, secure) : Bool} diff --git a/laws/CookieHostOnlyStoresHost.bend b/laws/CookieHostOnlyStoresHost.bend index d277e4c..6802302 100644 --- a/laws/CookieHostOnlyStoresHost.bend +++ b/laws/CookieHostOnlyStoresHost.bend @@ -1,8 +1,55 @@ +# For every response host, request path and cookie received: a host-only +# cookie stores the response host lowercased as its domain, a Domain cookie +# keeps its domain; a cookie with no Path takes the request path's +# default-path, any other keeps its Path (RFC 6265 §5.3 steps 6-7); every +# other field is kept. import Base import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.4): a host-only cookie stores the response host and default-path -law cookie_receive_host_only: - {Cookie.cookie.line(Cookie.cookie.receive("Example.COM", "/a/b", - Cookie.cookie.new("a", "b"))) - == "a=b; Path=/a" : String} +# LAW (RFC 6265 §5.3): receiving fills the domain and the path +law cookie_receive: + for +name: String + for +value: String + for +expires: String + for +max_age: String + for +domain: String + for +path: String + for +secure: Bool + for +http_only: Bool + for +same_site: String + for +host_only: Bool + for +host: String + for +req: String + {Cookie.cookie.receive(host, req, Cookie.Cookie{name, value, expires, max_age, domain, path, secure, + http_only, same_site, host_only}) + == Cookie.Cookie{name, value, expires, max_age, + Cookie.cookie.fill_domain(domain, host_only, String.to_lower(host)), + Cookie.cookie.fill_path(path, req), secure, http_only, same_site, + host_only} : Cookie.Cookie} + +# LAW (§5.3 step 6): a host-only cookie takes the host +law cookie_fill_domain_host_only: + for domain: String + for +host: String + {Cookie.cookie.fill_domain(domain, True{}, host) == host : String} + +# LAW (§5.3 step 6): a Domain cookie keeps its domain +law cookie_fill_domain_set: + for +domain: String + for host: String + {Cookie.cookie.fill_domain(domain, False{}, host) == domain : String} + +# LAW (§5.3 step 7): no Path, the default-path +law cookie_fill_path_empty: + for +path: String + for +req: String + for e: {True{} == String.is_empty(path) : Bool} + {Cookie.cookie.fill_path(path, req) == Cookie.cookie.default_path(req) + : String} + +# LAW (§5.3 step 7): a Path is kept +law cookie_fill_path_set: + for +path: String + for +req: String + for e: {False{} == String.is_empty(path) : Bool} + {Cookie.cookie.fill_path(path, req) == path : String} diff --git a/laws/CookieIdenticalPathsMatch.bend b/laws/CookieIdenticalPathsMatch.bend index a5a1f6f..52359e9 100644 --- a/laws/CookieIdenticalPathsMatch.bend +++ b/laws/CookieIdenticalPathsMatch.bend @@ -1,6 +1,9 @@ +# For every path, a cookie-path path-matches the identical request path +# (RFC 6265 §5.1.4, first rule). import Base import ../src/cookie.bend as Cookie # LAW (RFC 6265 §5.1.4): identical paths match law cookie_path_identical: - {Cookie.cookie.path_ok("/app", "/app") == True{} : Bool} + for +p: String + {Cookie.cookie.path_ok(p, p) == True{} : Bool} diff --git a/laws/CookieInsecureSentOnCleartext.bend b/laws/CookieInsecureSentOnCleartext.bend index a042202..e3f4cdf 100644 --- a/laws/CookieInsecureSentOnCleartext.bend +++ b/laws/CookieInsecureSentOnCleartext.bend @@ -1,6 +1,9 @@ +# For every request, TLS or not, a cookie without Secure may be sent +# (RFC 6265 §5.4 step 1). import Base import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.4): a cookie that is not Secure is sent on cleartext -law cookie_insecure_on_tcp: - {Cookie.cookie.send.secure(False{}, False{}) == True{} : Bool} +# LAW (RFC 6265 §5.4): a cookie without Secure rides on any transport +law cookie_insecure_any: + for tls: Bool + {Cookie.cookie.send.secure(tls, False{}) == True{} : Bool} diff --git a/laws/CookieIpHostMatchesExactly.bend b/laws/CookieIpHostMatchesExactly.bend index 6041894..c4b92d1 100644 --- a/laws/CookieIpHostMatchesExactly.bend +++ b/laws/CookieIpHostMatchesExactly.bend @@ -1,6 +1,21 @@ +# For every request host and cookie domain, a host-only cookie matches +# exactly the host it was set by, and a Domain cookie matches a host +# identical to its domain, an IPv4 literal included (RFC 6265 §5.1.3 rule 1, +# §5.4 step 1), both compared lowercase. import Base import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.1.3): an IPv4 host matches its own address exactly -law cookie_domain_ip_exact: - {Cookie.cookie.domain_ok("192.0.2.1", "192.0.2.1", False{}) == True{} : Bool} +# LAW (RFC 6265 §5.1.3): identical host and domain match +law cookie_domain_exact: + for +host: String + for +domain: String + for e: {True{} == String.eq(String.to_lower(host), String.to_lower(domain)) + : Bool} + {Cookie.cookie.domain_ok(host, domain, False{}) == True{} : Bool} + +# LAW (§5.4 step 1): a host-only cookie matches only its own host +law cookie_domain_host_only: + for host: String + for domain: String + {Cookie.cookie.domain_ok(host, domain, True{}) + == String.eq(String.to_lower(host), String.to_lower(domain)) : Bool} diff --git a/laws/CookieIpHostNoSuffixMatch.bend b/laws/CookieIpHostNoSuffixMatch.bend index 3ae8799..8719bfb 100644 --- a/laws/CookieIpHostNoSuffixMatch.bend +++ b/laws/CookieIpHostNoSuffixMatch.bend @@ -1,6 +1,14 @@ +# For every request host that is an IPv4 literal, a Domain cookie whose +# domain differs from it (compared lowercase) does not match: an IP address +# has no subdomains (RFC 6265 §5.1.3). import Base import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.1.3): an IPv4 host does not domain-match a suffix -law cookie_domain_ip_suffix: - {Cookie.cookie.domain_ok("192.0.2.1", "2.1", False{}) == False{} : Bool} +# LAW (RFC 6265 §5.1.3): an IPv4 host matches no domain but itself +law cookie_domain_ip: + for +host: String + for +domain: String + for e1: {False{} == String.eq(String.to_lower(host), String.to_lower(domain)) + : Bool} + for e2: {True{} == Cookie.cookie.ipv4(String.to_lower(host)) : Bool} + {Cookie.cookie.domain_ok(host, domain, False{}) == False{} : Bool} diff --git a/laws/CookieLongerPathFails.bend b/laws/CookieLongerPathFails.bend index 02f41db..99d68d7 100644 --- a/laws/CookieLongerPathFails.bend +++ b/laws/CookieLongerPathFails.bend @@ -1,6 +1,12 @@ +# For every request path and cookie-path, a cookie-path that the request +# path does not start with (a longer one, such as `/app/` for `/app`) does +# not path-match (RFC 6265 §5.1.4). import Base import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.1.4): a cookie-path the request does not extend fails -law cookie_path_longer_cookie: - {Cookie.cookie.path_ok("/app", "/app/") == False{} : Bool} +# LAW (RFC 6265 §5.1.4): no prefix, no path-match +law cookie_path_not_prefix: + for +req: String + for +cpath: String + for e: {False{} == String.starts_with(req, cpath) : Bool} + {Cookie.cookie.path_ok(req, cpath) == False{} : Bool} diff --git a/laws/CookieMaxAgeIgnoresJunk.bend b/laws/CookieMaxAgeIgnoresJunk.bend index bd8f29c..3951844 100644 --- a/laws/CookieMaxAgeIgnoresJunk.bend +++ b/laws/CookieMaxAgeIgnoresJunk.bend @@ -1,7 +1,28 @@ +# For every cookie and Max-Age attribute value (named `max-age` once +# lowercased), a value that reads as decimal digits replaces the cookie's +# Max-Age with the value as written, and any other value is ignored and the +# cookie kept as it was (RFC 6265 §5.2.2). import Base +import ../src/http.bend as Http import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.2.2): a Max-Age that is not digits is ignored -law cookie_max_age_ignores_junk: - {Cookie.cookie.parse("a=b; Max-Age=nope") - == Some{Cookie.cookie.new("a", "b")} : Maybe<&2, Cookie.Cookie>} +# LAW (RFC 6265 §5.2.2): Max-Age is read as digits +law cookie_named_max_age: + for c: Cookie.Cookie + for +value: String + {Cookie.cookie.named(c, "max-age", value) + == Cookie.cookie.age_ok(c, value, Http.digits.read(value)) : Cookie.Cookie} + +# LAW (§5.2.2): a Max-Age that is not digits is ignored +law cookie_age_junk: + for +c: Cookie.Cookie + for raw: String + {Cookie.cookie.age_ok(c, raw, None{}) == c : Cookie.Cookie} + +# LAW (§5.2.2): a Max-Age of digits is stored as written +law cookie_age_digits: + for c: Cookie.Cookie + for raw: String + for n: Nat + {Cookie.cookie.age_ok(c, raw, Some{n}) == Cookie.cookie.age(c, raw) + : Cookie.Cookie} diff --git a/laws/CookieMaxAgeOneStaleAtOne.bend b/laws/CookieMaxAgeOneStaleAtOne.bend deleted file mode 100644 index 2bc6898..0000000 --- a/laws/CookieMaxAgeOneStaleAtOne.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/cookie.bend as Cookie - -# LAW (RFC 6265 §5.4): Max-Age 1 is alive at age 0 and stale at age 1 -law cookie_max_age_one: - {Bool.and(Cookie.cookie.alive("1", 0n), - Bool.not(Cookie.cookie.alive("1", 1n))) == True{} : Bool} diff --git a/laws/CookieMaxAgeZeroNotAlive.bend b/laws/CookieMaxAgeZeroNotAlive.bend deleted file mode 100644 index 7680eed..0000000 --- a/laws/CookieMaxAgeZeroNotAlive.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/cookie.bend as Cookie - -# LAW (RFC 6265 §5.4): Max-Age 0 is not alive at age 0 -law cookie_max_age_zero: - {Cookie.cookie.alive("0", 0n) == False{} : Bool} diff --git a/laws/CookieNameIsNotIpv4.bend b/laws/CookieNameIsNotIpv4.bend index 06d80cd..5999e7f 100644 --- a/laws/CookieNameIsNotIpv4.bend +++ b/laws/CookieNameIsNotIpv4.bend @@ -1,6 +1,15 @@ +# For every host, a character that is neither `.` nor a decimal digit, +# anywhere in it, makes it not an IPv4 literal, so `example.com` is not one +# (RFC 6265 §5.1.3); the rest of the scan is laws/CookieRecognizesIpv4Literal.bend. import Base import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.1.3): a registered name is not an IPv4 address -law cookie_ipv4_name: - {Cookie.cookie.ipv4("example.com") == False{} : Bool} +# LAW: any other character, not an IPv4 literal +law cookie_ipv4_other: + for +h: Char + for t: String + for seen: Bool + for e1: {False{} == U32.is_eq(Char.to_u32(h), 46) : Bool} + for e2: {False{} == Bool.and(U32.is_ge(Char.to_u32(h), 48), + U32.is_le(Char.to_u32(h), 57)) : Bool} + {Cookie.cookie.ipv4.go(SCon{h, t}, seen) == False{} : Bool} diff --git a/laws/CookieNoDomainNotSentElsewhere.bend b/laws/CookieNoDomainNotSentElsewhere.bend deleted file mode 100644 index ef45e2f..0000000 --- a/laws/CookieNoDomainNotSentElsewhere.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/cookie.bend as Cookie - -# LAW (RFC 6265 §5.4): a cookie with no Domain does not match a different host -law cookie_send_unset_domain: - {Cookie.cookie.send("h", "/", False{}, Cookie.cookie.new("a", "b")) - == False{} : Bool} diff --git a/laws/CookiePathMatchesSlashPrefix.bend b/laws/CookiePathMatchesSlashPrefix.bend index 2c1bcb4..87d8539 100644 --- a/laws/CookiePathMatchesSlashPrefix.bend +++ b/laws/CookiePathMatchesSlashPrefix.bend @@ -1,6 +1,15 @@ +# For every request path and cookie-path, a cookie-path that is a prefix of +# the request path, when the first request character after it is `/`, +# path-matches it, so `/app` matches `/app/x` (RFC 6265 §5.1.4, third +# rule). import Base import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.1.4): a path-match allows a prefix whose next character is `/` +# LAW (RFC 6265 §5.1.4): a prefix followed by / matches law cookie_path_prefix: - {Cookie.cookie.path_ok("/app/x", "/app") == True{} : Bool} + for +req: String + for +cpath: String + for e1: {True{} == String.starts_with(req, cpath) : Bool} + for e2: {True{} == String.starts_with(String.drop(req, String.length(cpath)), + "/") : Bool} + {Cookie.cookie.path_ok(req, cpath) == True{} : Bool} diff --git a/laws/CookiePathNeedsSegmentBoundary.bend b/laws/CookiePathNeedsSegmentBoundary.bend index ae88fd6..5e4d6ed 100644 --- a/laws/CookiePathNeedsSegmentBoundary.bend +++ b/laws/CookiePathNeedsSegmentBoundary.bend @@ -1,6 +1,17 @@ +# For every request path and cookie-path, a cookie-path that is a prefix of +# a different request path, does not end with `/`, and is followed in it by +# a character other than `/` does not path-match, so `/app` does not match +# `/application` (RFC 6265 §5.1.4). import Base import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.1.4): a longer segment is not a path-match -law cookie_path_not_prefix: - {Cookie.cookie.path_ok("/application", "/app") == False{} : Bool} +# LAW (RFC 6265 §5.1.4): a prefix that ends inside a segment does not match +law cookie_path_not_boundary: + for +req: String + for +cpath: String + for e1: {True{} == String.starts_with(req, cpath) : Bool} + for e2: {False{} == String.eq(req, cpath) : Bool} + for e3: {False{} == String.ends_with(cpath, "/") : Bool} + for e4: {False{} == String.starts_with(String.drop(req, String.length(cpath)), + "/") : Bool} + {Cookie.cookie.path_ok(req, cpath) == False{} : Bool} diff --git a/laws/CookieRecognizesIpv4Literal.bend b/laws/CookieRecognizesIpv4Literal.bend index b495155..b7e9c17 100644 --- a/laws/CookieRecognizesIpv4Literal.bend +++ b/laws/CookieRecognizesIpv4Literal.bend @@ -1,6 +1,35 @@ +# For every host, `cookie.ipv4` scans it from the start: a `.` goes on and +# notes that a dot was seen, a decimal digit goes on, any other character +# says it is not an IPv4 literal, and the end says whether a dot was seen; +# so a host of digits and dots with a dot, such as `192.0.2.1`, is one +# (RFC 6265 §5.1.3, no subdomain match for an IP address). import Base import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.1.3): an IPv4 literal is recognized, a name is not -law cookie_ipv4_literal: - {Cookie.cookie.ipv4("192.0.2.1") == True{} : Bool} +# LAW: the scan starts with no dot seen +law cookie_ipv4: + for host: String + {Cookie.cookie.ipv4(host) == Cookie.cookie.ipv4.go(host, False{}) : Bool} + +# LAW: at the end, an IPv4 literal when a dot was seen +law cookie_ipv4_end: + for +seen: Bool + {Cookie.cookie.ipv4.go("", seen) == seen : Bool} + +# LAW: a dot goes on, a dot seen +law cookie_ipv4_dot: + for +t: String + for seen: Bool + {Cookie.cookie.ipv4.go(SCon{'.', t}, seen) + == Cookie.cookie.ipv4.go(t, True{}) : Bool} + +# LAW: a decimal digit goes on +law cookie_ipv4_digit: + for +h: Char + for +t: String + for +seen: Bool + for e1: {False{} == U32.is_eq(Char.to_u32(h), 46) : Bool} + for e2: {True{} == Bool.and(U32.is_ge(Char.to_u32(h), 48), + U32.is_le(Char.to_u32(h), 57)) : Bool} + {Cookie.cookie.ipv4.go(SCon{h, t}, seen) == Cookie.cookie.ipv4.go(t, seen) + : Bool} diff --git a/laws/CookieRejectsEmptyName.bend b/laws/CookieRejectsEmptyName.bend index 7e093da..913d8df 100644 --- a/laws/CookieRejectsEmptyName.bend +++ b/laws/CookieRejectsEmptyName.bend @@ -1,6 +1,20 @@ +# For every Set-Cookie line, a name-value-pair with no `=`, or whose name +# is empty once trimmed, sets no cookie (RFC 6265 §5.2 steps 2 and 5). import Base +import ../src/http.bend as Http import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §4.1.1): an empty cookie-name is rejected -law cookie_rejects_empty_name: - {Cookie.cookie.parse("=nope") == None{} : Maybe<&2, Cookie.Cookie>} +# LAW (RFC 6265 §5.2 step 2): no `=`, no cookie +law cookie_from_no_equals: + for pair: String + for attrs: List<&2, String> + {Cookie.cookie.from(pair, attrs, Http.NoCut{}) == None{} + : Maybe<&2, Cookie.Cookie>} + +# LAW (§5.2 step 5): an empty name, no cookie +law cookie_from_empty_name: + for name: String + for value: String + for attrs: List<&2, String> + {Cookie.cookie.from.name(name, value, attrs, True{}) == None{} + : Maybe<&2, Cookie.Cookie>} diff --git a/laws/CookieRequestJoinsPairs.bend b/laws/CookieRequestJoinsPairs.bend index 6d724b3..b9875c1 100644 --- a/laws/CookieRequestJoinsPairs.bend +++ b/laws/CookieRequestJoinsPairs.bend @@ -1,9 +1,53 @@ +# For every list of cookies, the Cookie request field value is the +# `name=value` pair of each cookie with a name, in order, joined by `; `, +# a cookie with an empty name left out (RFC 6265 §5.4 step 4). import Base import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.4): the Cookie header joins pairs with `; ` and drops an -# empty name -law cookie_request_joins: - {Cookie.cookie.join([Cookie.cookie.new("a", "b"), Cookie.cookie.new("c", "d"), - Cookie.cookie.new("", "x")]) - == "a=b; c=d" : String} +# LAW (RFC 6265 §5.4 step 4): the pairs joined by `; ` +law cookie_join: + for cs: List<&2, Cookie.Cookie> + {Cookie.cookie.join(cs) == String.join(Cookie.cookie.pairs(cs), "; ") + : String} + +# LAW: no cookies, no pairs +law cookie_pairs_nil: + for cs: List<&2, Cookie.Cookie> + for e: {[] == cs : List<&2, Cookie.Cookie>} + {Cookie.cookie.pairs(cs) == [] : List<&2, String>} + +# LAW: a cookie with a name gives its pair, then the rest +law cookie_pairs_kept: + for +name: String + for +value: String + for +expires: String + for +max_age: String + for +domain: String + for +path: String + for +secure: Bool + for +http_only: Bool + for +same_site: String + for +host_only: Bool + for t: List<&2, Cookie.Cookie> + for e: {False{} == String.is_empty(name) : Bool} + {Cookie.cookie.pairs(Cookie.Cookie{name, value, expires, max_age, domain, path, secure, + http_only, same_site, host_only} <> t) + == (name ++ "=" ++ value) <> Cookie.cookie.pairs(t) : List<&2, String>} + +# LAW: a cookie with an empty name gives nothing +law cookie_pairs_dropped: + for +name: String + for +value: String + for +expires: String + for +max_age: String + for +domain: String + for +path: String + for +secure: Bool + for +http_only: Bool + for +same_site: String + for +host_only: Bool + for t: List<&2, Cookie.Cookie> + for e: {True{} == String.is_empty(name) : Bool} + {Cookie.cookie.pairs(Cookie.Cookie{name, value, expires, max_age, domain, path, secure, + http_only, same_site, host_only} <> t) + == Cookie.cookie.pairs(t) : List<&2, String>} diff --git a/laws/CookieRootPathMatchesLonger.bend b/laws/CookieRootPathMatchesLonger.bend deleted file mode 100644 index 5e76af7..0000000 --- a/laws/CookieRootPathMatchesLonger.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/cookie.bend as Cookie - -# LAW (RFC 6265 §5.1.4): default-path `/` matches a longer request path -law cookie_path_root: - {Cookie.cookie.path_ok("/a", "/") == True{} : Bool} diff --git a/laws/CookieSameSiteFoldsCase.bend b/laws/CookieSameSiteFoldsCase.bend index 32ae846..57ba6c2 100644 --- a/laws/CookieSameSiteFoldsCase.bend +++ b/laws/CookieSameSiteFoldsCase.bend @@ -1,8 +1,43 @@ +# For every cookie and SameSite attribute value (named `samesite` once +# lowercased): the value is compared lowercase, so `lax`, `strict` and +# `none` in any case are stored in their canonical spelling `Lax`, `Strict` +# and `None`, and any other value is dropped and stored as empty (RFC 6265bis +# §5.6.7). import Base import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §4.1.1): SameSite=STRICT is canonical Strict -law cookie_samesite_strict: - {Cookie.cookie.parse("a=b; SameSite=STRICT") - == Some{Cookie.Cookie{"a", "b", "", "", "", "", False{}, False{}, - "Strict", True{}}} : Maybe<&2, Cookie.Cookie>} +# LAW: SameSite sets the cookie's canonical SameSite +law cookie_named_samesite: + for c: Cookie.Cookie + for value: String + {Cookie.cookie.named(c, "samesite", value) + == Cookie.cookie.site_set(c, Cookie.cookie.site(value)) : Cookie.Cookie} + +# LAW: lax in any case is Lax +law cookie_site_lax: + for +raw: String + for e: {True{} == String.eq(String.to_lower(raw), "lax") : Bool} + {Cookie.cookie.site(raw) == "Lax" : String} + +# LAW: strict in any case is Strict +law cookie_site_strict: + for +raw: String + for e1: {False{} == String.eq(String.to_lower(raw), "lax") : Bool} + for e2: {True{} == String.eq(String.to_lower(raw), "strict") : Bool} + {Cookie.cookie.site(raw) == "Strict" : String} + +# LAW: none in any case is None +law cookie_site_none: + for +raw: String + for e1: {False{} == String.eq(String.to_lower(raw), "lax") : Bool} + for e2: {False{} == String.eq(String.to_lower(raw), "strict") : Bool} + for e3: {True{} == String.eq(String.to_lower(raw), "none") : Bool} + {Cookie.cookie.site(raw) == "None" : String} + +# LAW: any other value is dropped +law cookie_site_unknown: + for +raw: String + for e1: {False{} == String.eq(String.to_lower(raw), "lax") : Bool} + for e2: {False{} == String.eq(String.to_lower(raw), "strict") : Bool} + for e3: {False{} == String.eq(String.to_lower(raw), "none") : Bool} + {Cookie.cookie.site(raw) == "" : String} diff --git a/laws/CookieSameSiteNoneCanonical.bend b/laws/CookieSameSiteNoneCanonical.bend deleted file mode 100644 index 93099c9..0000000 --- a/laws/CookieSameSiteNoneCanonical.bend +++ /dev/null @@ -1,8 +0,0 @@ -import Base -import ../src/cookie.bend as Cookie - -# LAW (RFC 6265 §4.1.1): SameSite=none is canonical None -law cookie_samesite_none: - {Cookie.cookie.parse("a=b; SameSite=none") - == Some{Cookie.Cookie{"a", "b", "", "", "", "", False{}, False{}, - "None", True{}}} : Maybe<&2, Cookie.Cookie>} diff --git a/laws/CookieSecureNeedsTls.bend b/laws/CookieSecureNeedsTls.bend index 62496ae..ad300cd 100644 --- a/laws/CookieSecureNeedsTls.bend +++ b/laws/CookieSecureNeedsTls.bend @@ -1,6 +1,9 @@ +# For every request, a Secure cookie may be sent exactly when the request +# is over TLS (RFC 6265 §5.4 step 1). import Base import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.4): a Secure cookie is not sent on a cleartext request -law cookie_secure_needs_tls: - {Cookie.cookie.send.secure(False{}, True{}) == False{} : Bool} +# LAW (RFC 6265 §5.4): a Secure cookie rides only on TLS +law cookie_secure_tls: + for +tls: Bool + {Cookie.cookie.send.secure(tls, True{}) == tls : Bool} diff --git a/laws/CookieSecureSentOnTls.bend b/laws/CookieSecureSentOnTls.bend deleted file mode 100644 index f623329..0000000 --- a/laws/CookieSecureSentOnTls.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/cookie.bend as Cookie - -# LAW (RFC 6265 §5.4): a Secure cookie is sent when the request is TLS -law cookie_secure_on_tls: - {Cookie.cookie.send.secure(True{}, True{}) == True{} : Bool} diff --git a/laws/CookieSessionStaysAlive.bend b/laws/CookieSessionStaysAlive.bend deleted file mode 100644 index 92e7d84..0000000 --- a/laws/CookieSessionStaysAlive.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/cookie.bend as Cookie - -# LAW (RFC 6265 §5.4): a session cookie (no Max-Age) stays sendable -law cookie_session_alive: - {Cookie.cookie.alive("", 5n) == True{} : Bool} diff --git a/laws/CookieSlashEndedPathIsPrefix.bend b/laws/CookieSlashEndedPathIsPrefix.bend index db32a16..8296b12 100644 --- a/laws/CookieSlashEndedPathIsPrefix.bend +++ b/laws/CookieSlashEndedPathIsPrefix.bend @@ -1,6 +1,14 @@ +# For every request path and cookie-path, a cookie-path that is a prefix of +# the request path and ends with `/` path-matches it, so `/` matches every +# path and `/app/` matches `/app/x` (RFC 6265 §5.1.4, second rule). import Base +import ../src/http.bend as Http import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §5.1.4): a cookie-path that already ends in `/` is a prefix +# LAW (RFC 6265 §5.1.4): a prefix ending in / matches law cookie_path_slash_prefix: - {Cookie.cookie.path_ok("/app/x", "/app/") == True{} : Bool} + for +req: String + for +cpath: String + for e1: {True{} == String.starts_with(req, cpath) : Bool} + for e2: {True{} == String.ends_with(cpath, "/") : Bool} + {Cookie.cookie.path_ok(req, cpath) == True{} : Bool} diff --git a/laws/CookieUnknownSameSiteDropped.bend b/laws/CookieUnknownSameSiteDropped.bend deleted file mode 100644 index fd5e314..0000000 --- a/laws/CookieUnknownSameSiteDropped.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/cookie.bend as Cookie - -# LAW (RFC 6265 §4.1.1): an unknown SameSite attribute is dropped -law cookie_samesite_unknown: - {Cookie.cookie.parse("a=b; SameSite=weird") - == Some{Cookie.cookie.new("a", "b")} : Maybe<&2, Cookie.Cookie>} diff --git a/laws/CorsAllowListReflectsOrigin.bend b/laws/CorsAllowListReflectsOrigin.bend index 5e0ef6b..986691f 100644 --- a/laws/CorsAllowListReflectsOrigin.bend +++ b/laws/CorsAllowListReflectsOrigin.bend @@ -1,7 +1,11 @@ import Base import ../src/cors.bend as Cors -# LAW (Fetch CORS): an explicit allow-list reflects the matching origin +# LAW (Fetch CORS): without `*` and without credentials, an origin on the +# allow-list is reflected as ACAO law cors_explicit_origin: - {Cors.cors.acao(["https://app.example"], False{}, "https://app.example") - == "https://app.example" : String} + for +os: List<&2, String> + for +origin: String + for +e1: {False{} == Cors.cors.star(os) : Bool} + for e2: {True{} == Cors.cors.hit(origin, os) : Bool} + {Cors.cors.acao(os, False{}, origin) == origin : String} diff --git a/laws/CorsAllowedPreflightIs200.bend b/laws/CorsAllowedPreflightIs200.bend index 50477a5..2fc4550 100644 --- a/laws/CorsAllowedPreflightIs200.bend +++ b/laws/CorsAllowedPreflightIs200.bend @@ -2,16 +2,23 @@ import Base import ../src/http.bend as Http import ../src/cors.bend as Cors -# LAW (Fetch CORS): an allowed preflight is 200 with the CORS headers +# LAW (Fetch CORS): a preflight from an allowed origin, with an allowed method +# and only allowed headers, is 200 with the preflight headers for its ACAO +# (credentials, Vary, Allow-Origin, Allow-Methods, Allow-Headers, Max-Age) law cors_preflight_allowed: - {Cors.cors.preflight(Cors.Cfg{["https://app.example"], ["GET", "PUT"], - ["Content-Type"], True{}, "600", ["X-Trace"]}, - "https://app.example", "PUT", "Content-Type") - == Http.Reply{200, [ - Http.H{"Access-Control-Allow-Credentials", "true"}, - Http.H{"Vary", "Origin"}, - Http.H{"Access-Control-Allow-Origin", "https://app.example"}, - Http.H{"Access-Control-Allow-Methods", "GET, PUT"}, - Http.H{"Access-Control-Allow-Headers", "Content-Type"}, - Http.H{"Access-Control-Max-Age", "600"} - ], ""} : Http.Reply} + for +origins: List<&2, String> + for +methods: List<&2, String> + for +headers: List<&2, String> + for +credentials: Bool + for max_age: String + for expose: List<&2, String> + for +origin: String + for +method: String + for +req_headers: String + for +e1: {False{} == String.is_empty(Cors.cors.acao(origins, credentials, origin)) : Bool} + for e2: {True{} == Cors.cors.hit(method, methods) : Bool} + for e3: {True{} == Cors.cors.headers_ok(req_headers, headers) : Bool} + {Cors.cors.preflight(Cors.Cfg{origins, methods, headers, credentials, max_age, + expose}, origin, method, req_headers) + == Http.Reply{200, Cors.cors.preflight_hs(Cors.cors.acao(origins, credentials, origin), methods, + headers, credentials, max_age), ""} : Http.Reply} diff --git a/laws/CorsCredentialsKeepExplicitOrigin.bend b/laws/CorsCredentialsKeepExplicitOrigin.bend deleted file mode 100644 index 76079f4..0000000 --- a/laws/CorsCredentialsKeepExplicitOrigin.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/cors.bend as Cors - -# LAW (Fetch CORS): credentials with an explicit origin still reflect it -law cors_credentials_explicit_origin: - {Cors.cors.acao(["https://app.example"], True{}, "https://app.example") - == "https://app.example" : String} diff --git a/laws/CorsCredentialsReflectOrigin.bend b/laws/CorsCredentialsReflectOrigin.bend index 03b3437..60b56ee 100644 --- a/laws/CorsCredentialsReflectOrigin.bend +++ b/laws/CorsCredentialsReflectOrigin.bend @@ -1,9 +1,10 @@ import Base import ../src/cors.bend as Cors -# --- Fetch CORS (https://fetch.spec.whatwg.org/#cors-protocol) --- - -# LAW (Fetch CORS): credentials reflect the request origin, never `*` +# LAW (Fetch CORS): with credentials, an allowed origin is reflected as ACAO, +# never `*`, whether it is allowed by `*` or by name law cors_credentials_reflect_origin: - {Cors.cors.acao(["*"], True{}, "https://app.example") - == "https://app.example" : String} + for +os: List<&2, String> + for +origin: String + for e: {True{} == Cors.cors.allowed(os, origin) : Bool} + {Cors.cors.acao(os, True{}, origin) == origin : String} diff --git a/laws/CorsGetIsNotPreflight.bend b/laws/CorsGetIsNotPreflight.bend index e2571c3..82883d8 100644 --- a/laws/CorsGetIsNotPreflight.bend +++ b/laws/CorsGetIsNotPreflight.bend @@ -2,7 +2,13 @@ import Base import ../src/http.bend as Http import ../src/cors.bend as Cors -# LAW (Fetch CORS): a GET with no Access-Control-Request-Method is not a preflight +# LAW (Fetch CORS): only an OPTIONS request is a preflight; any other method is +# not, whatever its target, headers and body law cors_get_is_not_preflight: - {Cors.cors.is_preflight(Http.Request{"GET", "/", - [Http.H{"Origin", "https://a"}], ""}) == False{} : Bool} + for +method: String + for target: String + for +headers: List<&2, Http.Header> + for body: String + for e: {False{} == String.eq(method, "OPTIONS") : Bool} + {Cors.cors.is_preflight(Http.Request{method, target, headers, body}) + == False{} : Bool} diff --git a/laws/CorsNoVaryForStar.bend b/laws/CorsNoVaryForStar.bend index dd45431..bc100c1 100644 --- a/laws/CorsNoVaryForStar.bend +++ b/laws/CorsNoVaryForStar.bend @@ -1,6 +1,8 @@ import Base import ../src/cors.bend as Cors -# LAW (Fetch CORS): Vary is not set for `*` +# LAW (Fetch CORS): no Vary when ACAO is `*` law cors_vary_star: - {Cors.cors.vary("*") == False{} : Bool} + for acao: String + for e: {True{} == String.eq(acao, "*") : Bool} + {Cors.cors.vary(acao) == False{} : Bool} diff --git a/laws/CorsNoVaryWhenRefused.bend b/laws/CorsNoVaryWhenRefused.bend index f64612a..7acfb39 100644 --- a/laws/CorsNoVaryWhenRefused.bend +++ b/laws/CorsNoVaryWhenRefused.bend @@ -1,6 +1,8 @@ import Base import ../src/cors.bend as Cors -# LAW (Fetch CORS): Vary is not set when the origin was refused +# LAW (Fetch CORS): no Vary when ACAO is empty (the origin was refused) law cors_vary_empty: - {Cors.cors.vary("") == False{} : Bool} + for acao: String + for e: {True{} == String.is_empty(acao) : Bool} + {Cors.cors.vary(acao) == False{} : Bool} diff --git a/laws/CorsOptionsWithMethodIsPreflight.bend b/laws/CorsOptionsWithMethodIsPreflight.bend index 983f1fe..96760bf 100644 --- a/laws/CorsOptionsWithMethodIsPreflight.bend +++ b/laws/CorsOptionsWithMethodIsPreflight.bend @@ -2,20 +2,19 @@ import Base import ../src/http.bend as Http import ../src/cors.bend as Cors -# LAW (Fetch CORS): OPTIONS plus Access-Control-Request-Method is a preflight +# LAW (Fetch CORS): an OPTIONS request with a non-empty +# Access-Control-Request-Method is answered by the preflight for its Origin, +# requested method and requested headers, whatever the handler's reply law cors_on_preflight: - {Cors.cors.on(Cors.Cfg{["https://app.example"], ["GET", "PUT"], - ["Content-Type"], True{}, "600", ["X-Trace"]}, - Http.Request{"OPTIONS", "/", [ - Http.H{"Origin", "https://app.example"}, - Http.H{"Access-Control-Request-Method", "PUT"}, - Http.H{"Access-Control-Request-Headers", "Content-Type"} - ], ""}, Http.Reply{200, [], "nope"}) - == Http.Reply{200, [ - Http.H{"Access-Control-Allow-Credentials", "true"}, - Http.H{"Vary", "Origin"}, - Http.H{"Access-Control-Allow-Origin", "https://app.example"}, - Http.H{"Access-Control-Allow-Methods", "GET, PUT"}, - Http.H{"Access-Control-Allow-Headers", "Content-Type"}, - Http.H{"Access-Control-Max-Age", "600"} - ], ""} : Http.Reply} + for cfg: Cors.Cfg + for target: String + for +headers: List<&2, Http.Header> + for body: String + for reply: Http.Reply + for e: {False{} == String.is_empty(Http.headers.find(headers, + "access-control-request-method")) : Bool} + {Cors.cors.on(cfg, Http.Request{"OPTIONS", target, headers, body}, reply) + == Cors.cors.preflight(cfg, Http.headers.find(headers, "origin"), + Http.headers.find(headers, "access-control-request-method"), + Http.headers.find(headers, "access-control-request-headers")) + : Http.Reply} diff --git a/laws/CorsPreflightAnswersStar.bend b/laws/CorsPreflightAnswersStar.bend deleted file mode 100644 index f62d65f..0000000 --- a/laws/CorsPreflightAnswersStar.bend +++ /dev/null @@ -1,14 +0,0 @@ -import Base -import ../src/http.bend as Http -import ../src/cors.bend as Cors - -# LAW (Fetch CORS): `*` without credentials is ACAO on a successful preflight -law cors_preflight_star: - {Cors.cors.preflight(Cors.Cfg{["*"], ["GET"], [], False{}, "0", []}, - "https://a", "GET", "") - == Http.Reply{200, [ - Http.H{"Access-Control-Allow-Origin", "*"}, - Http.H{"Access-Control-Allow-Methods", "GET"}, - Http.H{"Access-Control-Allow-Headers", ""}, - Http.H{"Access-Control-Max-Age", "0"} - ], ""} : Http.Reply} diff --git a/laws/CorsPreflightHeaderDenied.bend b/laws/CorsPreflightHeaderDenied.bend index b870ae0..0f358d2 100644 --- a/laws/CorsPreflightHeaderDenied.bend +++ b/laws/CorsPreflightHeaderDenied.bend @@ -2,9 +2,21 @@ import Base import ../src/http.bend as Http import ../src/cors.bend as Cors -# LAW (Fetch CORS): a requested header outside the allow-list fails preflight +# LAW (Fetch CORS): a preflight from an allowed origin with an allowed method +# that requests a header off the allow-list is 400 law cors_preflight_header_denied: - {Cors.cors.preflight(Cors.Cfg{["https://app.example"], ["PUT"], - ["Content-Type"], False{}, "10", []}, - "https://app.example", "PUT", "X-Nope") + for +origins: List<&2, String> + for +methods: List<&2, String> + for +headers: List<&2, String> + for +credentials: Bool + for max_age: String + for expose: List<&2, String> + for +origin: String + for +method: String + for +req_headers: String + for +e1: {False{} == String.is_empty(Cors.cors.acao(origins, credentials, origin)) : Bool} + for e2: {True{} == Cors.cors.hit(method, methods) : Bool} + for e3: {False{} == Cors.cors.headers_ok(req_headers, headers) : Bool} + {Cors.cors.preflight(Cors.Cfg{origins, methods, headers, credentials, max_age, + expose}, origin, method, req_headers) == Http.Reply{400, [], ""} : Http.Reply} diff --git a/laws/CorsPreflightHeadersIgnoreCase.bend b/laws/CorsPreflightHeadersIgnoreCase.bend index d138e30..9e8b7f2 100644 --- a/laws/CorsPreflightHeadersIgnoreCase.bend +++ b/laws/CorsPreflightHeadersIgnoreCase.bend @@ -2,15 +2,11 @@ import Base import ../src/http.bend as Http import ../src/cors.bend as Cors -# LAW (Fetch CORS): requested header names are matched case-insensitively +# LAW (RFC 9110 §5.1): a requested header name matches the allow-list the same +# way as any name with the same lowercase spelling law cors_preflight_header_case: - {Cors.cors.preflight(Cors.Cfg{["https://app.example"], ["PUT"], - ["Content-Type"], False{}, "10", []}, - "https://app.example", "PUT", "content-type") - == Http.Reply{200, [ - Http.H{"Vary", "Origin"}, - Http.H{"Access-Control-Allow-Origin", "https://app.example"}, - Http.H{"Access-Control-Allow-Methods", "PUT"}, - Http.H{"Access-Control-Allow-Headers", "Content-Type"}, - Http.H{"Access-Control-Max-Age", "10"} - ], ""} : Http.Reply} + for +a: String + for +b: String + for +xs: List<&2, String> + for e: {String.to_lower(a) == String.to_lower(b) : String} + {Cors.cors.hit_ci(a, xs) == Cors.cors.hit_ci(b, xs) : Bool} diff --git a/laws/CorsPreflightMethodDenied.bend b/laws/CorsPreflightMethodDenied.bend index f233131..60fe9ba 100644 --- a/laws/CorsPreflightMethodDenied.bend +++ b/laws/CorsPreflightMethodDenied.bend @@ -2,9 +2,20 @@ import Base import ../src/http.bend as Http import ../src/cors.bend as Cors -# LAW (Fetch CORS): a method outside the allow-list is a failed preflight +# LAW (Fetch CORS): a preflight from an allowed origin asking for a method off +# the allow-list is 400, whatever the requested headers law cors_preflight_method_denied: - {Cors.cors.preflight(Cors.Cfg{["https://app.example"], ["GET", "PUT"], - ["Content-Type"], True{}, "600", ["X-Trace"]}, - "https://app.example", "DELETE", "") + for +origins: List<&2, String> + for +methods: List<&2, String> + for +headers: List<&2, String> + for +credentials: Bool + for max_age: String + for expose: List<&2, String> + for +origin: String + for +method: String + for +req_headers: String + for +e1: {False{} == String.is_empty(Cors.cors.acao(origins, credentials, origin)) : Bool} + for e2: {False{} == Cors.cors.hit(method, methods) : Bool} + {Cors.cors.preflight(Cors.Cfg{origins, methods, headers, credentials, max_age, + expose}, origin, method, req_headers) == Http.Reply{400, [], ""} : Http.Reply} diff --git a/laws/CorsPreflightOriginDenied.bend b/laws/CorsPreflightOriginDenied.bend index 31de261..0c8996d 100644 --- a/laws/CorsPreflightOriginDenied.bend +++ b/laws/CorsPreflightOriginDenied.bend @@ -2,9 +2,19 @@ import Base import ../src/http.bend as Http import ../src/cors.bend as Cors -# LAW (Fetch CORS): a preflight whose origin is not allowed is 400 +# LAW (Fetch CORS): a preflight from an origin the allow-list does not allow is +# 400, whatever the method and requested headers law cors_preflight_origin_denied: - {Cors.cors.preflight(Cors.Cfg{["https://app.example"], ["PUT"], - ["Content-Type"], False{}, "10", []}, - "https://no.example", "PUT", "") + for +origins: List<&2, String> + for +methods: List<&2, String> + for +headers: List<&2, String> + for +credentials: Bool + for max_age: String + for expose: List<&2, String> + for +origin: String + for +method: String + for +req_headers: String + for e: {False{} == Cors.cors.allowed(origins, origin) : Bool} + {Cors.cors.preflight(Cors.Cfg{origins, methods, headers, credentials, max_age, + expose}, origin, method, req_headers) == Http.Reply{400, [], ""} : Http.Reply} diff --git a/laws/CorsReadsOriginHeader.bend b/laws/CorsReadsOriginHeader.bend index c0451de..7fa19fb 100644 --- a/laws/CorsReadsOriginHeader.bend +++ b/laws/CorsReadsOriginHeader.bend @@ -2,7 +2,7 @@ import Base import ../src/http.bend as Http import ../src/cors.bend as Cors -# LAW (Fetch CORS): Origin is the request header of that name +# LAW (Fetch CORS): Origin is the request header of that name, for any origin law cors_origin_header: - {Cors.cors.origin("https://app.example") - == Http.H{"Origin", "https://app.example"} : Http.Header} + for origin: String + {Cors.cors.origin(origin) == Http.H{"Origin", origin} : Http.Header} diff --git a/laws/CorsReadsRequestHeaders.bend b/laws/CorsReadsRequestHeaders.bend index 4be7223..fb2fc80 100644 --- a/laws/CorsReadsRequestHeaders.bend +++ b/laws/CorsReadsRequestHeaders.bend @@ -2,7 +2,8 @@ import Base import ../src/http.bend as Http import ../src/cors.bend as Cors -# LAW (Fetch CORS): Access-Control-Request-Headers names the headers +# LAW (Fetch CORS): Access-Control-Request-Headers carries the names as given law cors_request_headers_header: - {Cors.cors.request_headers("Content-Type") - == Http.H{"Access-Control-Request-Headers", "Content-Type"} : Http.Header} + for names: String + {Cors.cors.request_headers(names) + == Http.H{"Access-Control-Request-Headers", names} : Http.Header} diff --git a/laws/CorsReadsRequestMethod.bend b/laws/CorsReadsRequestMethod.bend index 01de247..1ce0bdb 100644 --- a/laws/CorsReadsRequestMethod.bend +++ b/laws/CorsReadsRequestMethod.bend @@ -2,7 +2,8 @@ import Base import ../src/http.bend as Http import ../src/cors.bend as Cors -# LAW (Fetch CORS): Access-Control-Request-Method names the method +# LAW (Fetch CORS): Access-Control-Request-Method carries the method as given law cors_request_method_header: - {Cors.cors.request_method("PUT") - == Http.H{"Access-Control-Request-Method", "PUT"} : Http.Header} + for method: String + {Cors.cors.request_method(method) + == Http.H{"Access-Control-Request-Method", method} : Http.Header} diff --git a/laws/CorsRefusedLeavesReply.bend b/laws/CorsRefusedLeavesReply.bend index ff319c4..77482ae 100644 --- a/laws/CorsRefusedLeavesReply.bend +++ b/laws/CorsRefusedLeavesReply.bend @@ -2,8 +2,17 @@ import Base import ../src/http.bend as Http import ../src/cors.bend as Cors -# LAW (Fetch CORS): a refused origin leaves the handler reply unchanged +# LAW (Fetch CORS): when the origin gets no ACAO (refused, or missing), the +# handler's reply is left unchanged law cors_simple_refused: - {Cors.cors.simple(Cors.Cfg{["https://ok.example"], [], [], False{}, "", []}, - "https://no.example", Http.Reply{200, [], "ok"}) - == Http.Reply{200, [], "ok"} : Http.Reply} + for +origins: List<&2, String> + for methods: List<&2, String> + for headers: List<&2, String> + for +credentials: Bool + for max_age: String + for +expose: List<&2, String> + for +origin: String + for reply: Http.Reply + for e: {True{} == String.is_empty(Cors.cors.acao(origins, credentials, origin)) : Bool} + {Cors.cors.simple(Cors.Cfg{origins, methods, headers, credentials, max_age, expose}, origin, reply) + == reply : Http.Reply} diff --git a/laws/CorsRefusesMissingOrigin.bend b/laws/CorsRefusesMissingOrigin.bend index 20927e6..38f888a 100644 --- a/laws/CorsRefusesMissingOrigin.bend +++ b/laws/CorsRefusesMissingOrigin.bend @@ -1,7 +1,10 @@ import Base import ../src/cors.bend as Cors -# LAW (Fetch CORS): a missing origin is refused +# LAW (Fetch CORS): an origin the allow-list does not allow gets an empty ACAO law cors_refused_origin: - {Cors.cors.acao(["https://ok.example"], False{}, "https://no.example") - == "" : String} + for +os: List<&2, String> + for credentials: Bool + for +origin: String + for e: {False{} == Cors.cors.allowed(os, origin) : Bool} + {Cors.cors.acao(os, credentials, origin) == "" : String} diff --git a/laws/CorsSimpleAnswersStar.bend b/laws/CorsSimpleAnswersStar.bend deleted file mode 100644 index 7775521..0000000 --- a/laws/CorsSimpleAnswersStar.bend +++ /dev/null @@ -1,10 +0,0 @@ -import Base -import ../src/http.bend as Http -import ../src/cors.bend as Cors - -# LAW (Fetch CORS): `*` without credentials is the only ACAO header -law cors_simple_star: - {Cors.cors.simple(Cors.Cfg{["*"], ["GET"], [], False{}, "", []}, - "https://app.example", Http.Reply{200, [], "ok"}) - == Http.Reply{200, [Http.H{"Access-Control-Allow-Origin", "*"}], "ok"} - : Http.Reply} diff --git a/laws/CorsSimpleKeepsBody.bend b/laws/CorsSimpleKeepsBody.bend index ca9ba38..0f905c9 100644 --- a/laws/CorsSimpleKeepsBody.bend +++ b/laws/CorsSimpleKeepsBody.bend @@ -2,14 +2,23 @@ import Base import ../src/http.bend as Http import ../src/cors.bend as Cors -# LAW (Fetch CORS): a simple response keeps its body and gains CORS headers +# LAW (Fetch CORS): when the origin gets an ACAO, a reply keeps its status and +# body and gets the simple CORS headers (credentials, Vary, Expose-Headers, +# Allow-Origin) ahead of its own law cors_simple_reflects: - {Cors.cors.simple(Cors.Cfg{["https://app.example"], ["GET", "PUT"], - ["Content-Type"], True{}, "600", ["X-Trace"]}, - "https://app.example", Http.Reply{200, [], "ok"}) - == Http.Reply{200, [ - Http.H{"Access-Control-Allow-Credentials", "true"}, - Http.H{"Vary", "Origin"}, - Http.H{"Access-Control-Expose-Headers", "X-Trace"}, - Http.H{"Access-Control-Allow-Origin", "https://app.example"} - ], "ok"} : Http.Reply} + for +origins: List<&2, String> + for methods: List<&2, String> + for headers: List<&2, String> + for +credentials: Bool + for max_age: String + for +expose: List<&2, String> + for +origin: String + for status: U32 + for hs: List<&2, Http.Header> + for body: String + for e: {False{} == String.is_empty(Cors.cors.acao(origins, credentials, origin)) : Bool} + {Cors.cors.simple(Cors.Cfg{origins, methods, headers, credentials, max_age, expose}, origin, Http.Reply{status, hs, + body}) + == Http.Reply{status, List.append(&2, Http.Header, + Cors.cors.simple_hs(Cors.cors.acao(origins, credentials, origin), credentials, expose), hs), body} + : Http.Reply} diff --git a/laws/CorsStarStaysStar.bend b/laws/CorsStarStaysStar.bend index fd68b29..684e4e6 100644 --- a/laws/CorsStarStaysStar.bend +++ b/laws/CorsStarStaysStar.bend @@ -1,6 +1,10 @@ import Base import ../src/cors.bend as Cors -# LAW (Fetch CORS): without credentials, `*` stays `*` +# LAW (Fetch CORS): an allow-list holding `*` answers any origin with `*` when +# credentials are off law cors_star_without_credentials: - {Cors.cors.acao(["*"], False{}, "https://app.example") == "*" : String} + for +os: List<&2, String> + for +origin: String + for +e: {True{} == Cors.cors.star(os) : Bool} + {Cors.cors.acao(os, False{}, origin) == "*" : String} diff --git a/laws/CorsVaryOnSpecificOrigin.bend b/laws/CorsVaryOnSpecificOrigin.bend index f6c1666..cb70979 100644 --- a/laws/CorsVaryOnSpecificOrigin.bend +++ b/laws/CorsVaryOnSpecificOrigin.bend @@ -1,6 +1,10 @@ import Base import ../src/cors.bend as Cors -# LAW (Fetch CORS): Vary is set when ACAO is a specific origin +# LAW (Fetch CORS): Vary is set when ACAO is a specific origin (not `*`, not +# empty) law cors_vary_specific: - {Cors.cors.vary("https://app.example") == True{} : Bool} + for acao: String + for e1: {False{} == String.eq(acao, "*") : Bool} + for e2: {False{} == String.is_empty(acao) : Bool} + {Cors.cors.vary(acao) == True{} : Bool} diff --git a/laws/DechunkEmptyIsEmpty.bend b/laws/DechunkEmptyIsEmpty.bend index 56258b1..529e519 100644 --- a/laws/DechunkEmptyIsEmpty.bend +++ b/laws/DechunkEmptyIsEmpty.bend @@ -1,6 +1,11 @@ +# For every body `s` with no CRLF in it, the chunked decoder (`dechunk`) +# reads it as no octets: without a CRLF there is no chunk-size line (RFC 9112 +# §7.1), and the empty body is one such body. import Base import ../src/http.bend as Http -# LAW (RFC 9112 §7.1): an empty chunked body decodes to empty -law dechunk_empty: - {Http.dechunk("") == "" : String} +# LAW (RFC 9112 §7.1): a body with no CRLF decodes to nothing +law dechunk_no_crlf: + for +s: String + for e: {Http.NoCut{} == Http.divide(s, "\r\n") : Http.Cut} + {Http.dechunk(s) == "" : String} diff --git a/laws/DechunkIgnoresExtension.bend b/laws/DechunkIgnoresExtension.bend deleted file mode 100644 index b63f863..0000000 --- a/laws/DechunkIgnoresExtension.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9112 §7.1): a chunk-ext after `;` does not change the decoded body -law dechunk_ignores_extension: - {Http.dechunk("5;ext=1\r\nhello\r\n0\r\n\r\n") == "hello" : String} diff --git a/laws/DechunkJoinsTwoChunks.bend b/laws/DechunkJoinsTwoChunks.bend deleted file mode 100644 index 85f2caa..0000000 --- a/laws/DechunkJoinsTwoChunks.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9112 §7.1): two non-empty chunks round-trip -law dechunk_two_chunks: - {Http.dechunk("1\r\nZ\r\n2\r\nOK\r\n0\r\n\r\n") == "ZOK" : String} diff --git a/laws/DechunkLastChunkAloneIsEmpty.bend b/laws/DechunkLastChunkAloneIsEmpty.bend deleted file mode 100644 index a901f05..0000000 --- a/laws/DechunkLastChunkAloneIsEmpty.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9112 §7.1): a body that is only the last chunk is empty -law dechunk_only_last: - {Http.dechunk("0\r\n\r\n") == "" : String} diff --git a/laws/DechunkRfcExample.bend b/laws/DechunkRfcExample.bend deleted file mode 100644 index 30b639e..0000000 --- a/laws/DechunkRfcExample.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9112 §7.1): the chunked example wiki + pedia is wikipedia -law dechunk_wiki: - {Http.dechunk("4\r\nwiki\r\n5\r\npedia\r\n0\r\n\r\n") == "wikipedia" : String} diff --git a/laws/DechunkStopsAtZero.bend b/laws/DechunkStopsAtZero.bend deleted file mode 100644 index b26a0a4..0000000 --- a/laws/DechunkStopsAtZero.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9112 §7.1): the chunk of size 0 ends the body; a trailer is not data -law dechunk_stops_at_zero: - {Http.dechunk("5\r\nhello\r\n0\r\nIgnored: 1\r\n\r\n") == "hello" : String} diff --git a/laws/DeleteIsIdempotent.bend b/laws/DeleteIsIdempotent.bend deleted file mode 100644 index bbe10c8..0000000 --- a/laws/DeleteIsIdempotent.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW: DELETE is idempotent -law method_idempotent_delete: - {Http.method.idempotent("DELETE") == True{} : Bool} diff --git a/laws/DeleteNotSafe.bend b/laws/DeleteNotSafe.bend deleted file mode 100644 index b6454a1..0000000 --- a/laws/DeleteNotSafe.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §9.2.1): DELETE is not safe -law method_safe_delete: - {Http.method.safe("DELETE") == False{} : Bool} diff --git a/laws/EqualContentLengthsAreOne.bend b/laws/EqualContentLengthsAreOne.bend deleted file mode 100644 index 114080c..0000000 --- a/laws/EqualContentLengthsAreOne.bend +++ /dev/null @@ -1,8 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9112 §6.3): identical Content-Length values are that one length -law parse_equal_content_lengths: - {Http.parse("HTTP/1.1 200 OK\r\nContent-Length: 5\r\nContent-Length: 5\r\n\r\nhello!!") - == Http.Reply{200, [Http.H{"Content-Length", "5"}, - Http.H{"Content-Length", "5"}], "hello"} : Http.Reply} diff --git a/laws/FieldLookupFindsFirst.bend b/laws/FieldLookupFindsFirst.bend index bb1d87c..c90616e 100644 --- a/laws/FieldLookupFindsFirst.bend +++ b/laws/FieldLookupFindsFirst.bend @@ -1,7 +1,28 @@ +# For every header list and field name, a lookup compares names +# case-insensitively (RFC 9110 §5.1): the first field whose lower-case name +# is the asked name's lower-case form gives its value, however the two were +# spelled, and every field before it with another name is passed over, so +# of a repeated name the first field is the one found (RFC 9110 §5.2). import Base import ../src/http.bend as Http -# LAW (RFC 9110 §5.2): the first field of a repeated name is the one found +# LAW (RFC 9110 §5.1, §5.2): a field whose name matches, case aside, is found law headers_find_first: - {Http.headers.find([Http.H{"Host", "a"}, Http.H{"Host", "b"}], "host") - == "a" : String} + for n: String + for v: String + for t: List<&2, Http.Header> + for +name: String + for e: {True{} == String.eq(String.to_lower(n), String.to_lower(name)) + : Bool} + {Http.headers.find(Http.H{n, v} <> t, name) == v : String} + +# LAW (RFC 9110 §5.1): a field with another name is passed over +law headers_find_skips: + for n: String + for v: String + for t: List<&2, Http.Header> + for +name: String + for e: {False{} == String.eq(String.to_lower(n), String.to_lower(name)) + : Bool} + {Http.headers.find(Http.H{n, v} <> t, name) == Http.headers.find(t, name) + : String} diff --git a/laws/FieldLookupIgnoresCase.bend b/laws/FieldLookupIgnoresCase.bend deleted file mode 100644 index 20943b4..0000000 --- a/laws/FieldLookupIgnoresCase.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §5.1): field lookup folds the name and keeps the value -law headers_find_ignores_case: - {Http.headers.find([Http.H{"hOsT", "Ex.COM"}], "host") == "Ex.COM" : String} diff --git a/laws/FieldValueTrimsWhitespace.bend b/laws/FieldValueTrimsWhitespace.bend index 13fd334..e89eef7 100644 --- a/laws/FieldValueTrimsWhitespace.bend +++ b/laws/FieldValueTrimsWhitespace.bend @@ -1,6 +1,16 @@ +# For every header line that has a colon, the field is the text before the +# first colon, as written, and the value is the text after it with +# surrounding whitespace trimmed (RFC 9112 §5.1), when the trimmed value +# holds no line break (laws/ObsFoldRejected.bend). import Base import ../src/http.bend as Http -# LAW (RFC 9110 §5.5): OWS around a field value is trimmed +# LAW (RFC 9112 §5.1): a field value is trimmed of surrounding whitespace law head_line_trims: - {Http.head.line("A: b ") == Some{Http.H{"A", "b"}} : Maybe<&2, Http.Header>} + for h: String + for +before: String + for +after: String + for e: {Http.Cut{before, after} == Http.divide(h, ":") : Http.Cut} + for ef: {False{} == Http.field.folded(String.trim(after)) : Bool} + {Http.head.line(h) == Some{Http.H{before, String.trim(after)}} + : Maybe<&2, Http.Header>} diff --git a/laws/FreshUnderMaxAge.bend b/laws/FreshUnderMaxAge.bend index 0035707..f5bcdd1 100644 --- a/laws/FreshUnderMaxAge.bend +++ b/laws/FreshUnderMaxAge.bend @@ -1,6 +1,20 @@ +# For every age and every directive state with neither no-store nor +# no-cache whose max-age argument reads as delta-seconds `n`, the response +# is fresh exactly when its age is under `n` (`cache.fresh`): fresh below +# max-age, stale at it and after it (so max-age=0 is always stale), whatever +# public, private and the recorded Expires say (max-age overrides Expires). import Base +import ../src/http.bend as Http import ../src/cache.bend as Cache -# LAW (RFC 9111 §4.2.1): an age under max-age is fresh -law fresh_max_age_open: - {Cache.cache.fresh(Cache.cache.parse("max-age=10"), 0n) == True{} : Bool} +# LAW (RFC 9111 §4.2.1): fresh exactly while the age is under max-age +law fresh_max_age: + for public: Bool + for private: Bool + for max_age: String + for expires: String + for n: Nat + for age: Nat + for e: {Some{n} == Http.digits.read(max_age) : Maybe<&2, Nat>} + {Cache.cache.fresh(Cache.Cc{False{}, False{}, public, private, max_age, + expires}, age) == Nat.is_lt(age, n) : Bool} diff --git a/laws/GetAsteriskTargetRejected.bend b/laws/GetAsteriskTargetRejected.bend index daee653..42d08fc 100644 --- a/laws/GetAsteriskTargetRejected.bend +++ b/laws/GetAsteriskTargetRejected.bend @@ -1,7 +1,14 @@ +# For every method other than OPTIONS, header lines and body, the +# asterisk-form target `*` is not accepted, so a `GET *` request is bad: +# asterisk-form is only for OPTIONS (RFC 9112 §3.2.4). import Base import ../src/http.bend as Http -# LAW (RFC 9112 §3.2.4): asterisk-form is not a GET target +# LAW (RFC 9112 §3.2.4): `*` is rejected for every method but OPTIONS law ask_get_asterisk_rejected: - {Http.ask("GET * HTTP/1.1\r\nHost: h\r\n\r\n") + for +method: String + for +ls: List<&2, String> + for body: String + for e: {False{} == String.eq(method, "OPTIONS") : Bool} + {Http.ask.line(method, "*", ls, body) == Http.Bad{"the request-target is not in origin-form"} : Http.Request} diff --git a/laws/GetIsIdempotent.bend b/laws/GetIsIdempotent.bend deleted file mode 100644 index a12e381..0000000 --- a/laws/GetIsIdempotent.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §9.2.2): GET is idempotent -law method_idempotent_get: - {Http.method.idempotent("GET") == True{} : Bool} diff --git a/laws/GetIsSafe.bend b/laws/GetIsSafe.bend deleted file mode 100644 index b71ed8a..0000000 --- a/laws/GetIsSafe.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §9.2.1): GET, HEAD, and OPTIONS are safe; `get` is not GET -law method_safe_get: - {Http.method.safe("GET") == True{} : Bool} diff --git a/laws/GetOmitsContentLength.bend b/laws/GetOmitsContentLength.bend deleted file mode 100644 index e12f4ae..0000000 --- a/laws/GetOmitsContentLength.bend +++ /dev/null @@ -1,13 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §8.6): an empty GET omits Content-Length -law get_omits_content_length: - {Http.get_req("h", "/", []) - == "GET / HTTP/1.1\r\n" - ++ "Host: h\r\n" - ++ "User-Agent: ezhttp\r\n" - ++ "Accept: */*\r\n" - ++ "Connection: close\r\n" - ++ "\r\n" - : String} diff --git a/laws/HeadIsIdempotent.bend b/laws/HeadIsIdempotent.bend deleted file mode 100644 index c9e3718..0000000 --- a/laws/HeadIsIdempotent.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §9.2.2): HEAD is idempotent -law method_idempotent_head: - {Http.method.idempotent("HEAD") == True{} : Bool} diff --git a/laws/HeadIsSafe.bend b/laws/HeadIsSafe.bend deleted file mode 100644 index 601f2d3..0000000 --- a/laws/HeadIsSafe.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §9.2.1): HEAD is safe -law method_safe_head: - {Http.method.safe("HEAD") == True{} : Bool} diff --git a/laws/HeadReplyDropsBody.bend b/laws/HeadReplyDropsBody.bend deleted file mode 100644 index 344266d..0000000 --- a/laws/HeadReplyDropsBody.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §9.3.2): a HEAD response is written with an empty body -law head_reply_drops_body: - {Http.reply.for("HEAD", Http.Reply{200, [], "secret"}) - == Http.Reply{200, [], ""} : Http.Reply} diff --git a/laws/HttpsDefaultsTo443.bend b/laws/HttpsDefaultsTo443.bend index d0d46b1..47fa7a3 100644 --- a/laws/HttpsDefaultsTo443.bend +++ b/laws/HttpsDefaultsTo443.bend @@ -1,6 +1,9 @@ import Base import ../src/url.bend as Url -# LAW: https implies 443 +# LAW (RFC 9110 §4.2.2): every scheme spelled `https` implies port 443 +# (laws/OtherSchemesDefaultTo80.bend has every other scheme) law dflt_https: - {Url.dflt("https") == 443 : U32} + for +scheme: String + for e: {True{} == String.eq(scheme, "https") : Bool} + {Url.dflt(scheme) == 443 : U32} diff --git a/laws/JsonParseIsEzjsonParse.bend b/laws/JsonParseIsEzjsonParse.bend new file mode 100644 index 0000000..8843d6f --- /dev/null +++ b/laws/JsonParseIsEzjsonParse.bend @@ -0,0 +1,23 @@ +# For every text, `json.parse` is ezjson's parse, and `json.as_str` reads +# its result: text ezjson does not parse as JSON (such as `nope`) is none, +# and text that parses to a value gives that value's string, or none when +# it is not a string (so `"\"hi\""` gives `hi`). What ezjson parses is +# ezjson's guarantee (trusted here). +import Base +import ../src/json.bend as Json +import ezjson@1.2.0.0/main.bend as Ezjson +import ezjson@1.2.0.0/src/value.bend as Value + +# LAW: text that is not JSON is none +law json_parse_rejects: + for s: String + for e: {Ezjson.parse(s) == None{} : Maybe<&2, Value.Json>} + {Json.json.as_str(Json.json.parse(s)) == None{} : Maybe<&2, String>} + +# LAW: text that parses to a value gives that value's string +law json_parse_string: + for s: String + for j: Value.Json + for e: {Ezjson.parse(s) == Some{j} : Maybe<&2, Value.Json>} + {Json.json.as_str(Json.json.parse(s)) == Ezjson.as_str(j) + : Maybe<&2, String>} diff --git a/laws/JsonRejectsNonJson.bend b/laws/JsonRejectsNonJson.bend deleted file mode 100644 index 006ad7b..0000000 --- a/laws/JsonRejectsNonJson.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/json.bend as Json - -# LAW: text that is not JSON is none -law json_parse_rejects: - {Json.json.as_str(Json.json.parse("nope")) == None{} : Maybe<&2, String>} diff --git a/laws/JsonStringIsTextBody.bend b/laws/JsonStringIsTextBody.bend index c816738..ec387af 100644 --- a/laws/JsonStringIsTextBody.bend +++ b/laws/JsonStringIsTextBody.bend @@ -1,9 +1,13 @@ +# For every JSON value, its body (`json.body`) is the text body of its +# compact encoding (ezjson's `print`), so a JSON string `"hi"` is the text +# body `"\"hi\""`. The HTTP types stay text (the body is not a JSON value). import Base import ../src/body.bend as Body import ../src/json.bend as Json import ezjson@1.2.0.0/main.bend as Ezjson +import ezjson@1.2.0.0/src/value.bend as Value -# LAW: a JSON string is a text body of its compact encoding. The HTTP types -# stay text (the body is not a JSON value). +# LAW: a JSON value is a text body of its compact encoding law json_string_is_text_body: - {Json.json.body(Ezjson.str("hi")) == Body.body.text("\"hi\"") : Body.Body} + for j: Value.Json + {Json.json.body(j) == Body.body.text(Ezjson.print(j)) : Body.Body} diff --git a/laws/JsonStringParsesBack.bend b/laws/JsonStringParsesBack.bend deleted file mode 100644 index bce40ed..0000000 --- a/laws/JsonStringParsesBack.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/json.bend as Json - -# LAW: a JSON string parses back to that string -law json_parse_string: - {Json.json.as_str(Json.json.parse("\"hi\"")) == Some{"hi"} : Maybe<&2, String>} diff --git a/laws/LowercaseGetNotSafe.bend b/laws/LowercaseGetNotSafe.bend deleted file mode 100644 index 186a354..0000000 --- a/laws/LowercaseGetNotSafe.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW: a lower-case get is not the safe method GET -law method_safe_get_lower: - {Http.method.safe("get") == False{} : Bool} diff --git a/laws/MaxAgeOneFreshThenStale.bend b/laws/MaxAgeOneFreshThenStale.bend deleted file mode 100644 index ba2ae6a..0000000 --- a/laws/MaxAgeOneFreshThenStale.bend +++ /dev/null @@ -1,8 +0,0 @@ -import Base -import ../src/cache.bend as Cache - -# LAW (RFC 9111 §4.2.1): max-age=1 is fresh at 0 and stale at 1 -law fresh_max_age_one: - {Bool.and(Cache.cache.fresh(Cache.cache.parse("max-age=1"), 0n), - Bool.not(Cache.cache.fresh(Cache.cache.parse("max-age=1"), 1n))) - == True{} : Bool} diff --git a/laws/MaxAgeOverridesExpires.bend b/laws/MaxAgeOverridesExpires.bend deleted file mode 100644 index ca60ced..0000000 --- a/laws/MaxAgeOverridesExpires.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/cache.bend as Cache - -# LAW (RFC 9111 §4.2.1): max-age overrides Expires for freshness -law fresh_max_age_overrides_expires: - {Cache.cache.fresh(Cache.cache.note("max-age=0", - "Wed, 21 Oct 2099 07:28:00 GMT"), 0n) == False{} : Bool} diff --git a/laws/MaxAgeZeroIsStale.bend b/laws/MaxAgeZeroIsStale.bend deleted file mode 100644 index d1313e8..0000000 --- a/laws/MaxAgeZeroIsStale.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/cache.bend as Cache - -# LAW (RFC 9111 §4.2.1): max-age=0 is stale at age 0 -law fresh_max_age_zero: - {Cache.cache.fresh(Cache.cache.parse("max-age=0"), 0n) == False{} : Bool} diff --git a/laws/MaxZeroIsNoLimit.bend b/laws/MaxZeroIsNoLimit.bend new file mode 100644 index 0000000..7f67cb2 --- /dev/null +++ b/laws/MaxZeroIsNoLimit.bend @@ -0,0 +1,25 @@ +# For every slots channel, `max`, done channel and tracking, the pool a +# serve hands its forks (`step.pool`) is limited exactly when `max` is not +# 0, so `max` 0 is no concurrency limit, and a limited serve joins its forks +# on the done channel it made the pool with. What the forks do with the pool +# is effects (trusted in src/server.bend). +import Base +import ../src/step.bend as Step + +# LAW: a pool is limited exactly when max is not 0 +law pool_limited: + for slots: Chan(Unit) + for +max: U32 + for done: Chan(Unit) + for tracked: Bool + {Step.step.pool.limited(Step.step.pool(slots, max, done, tracked)) + == U32.is_ne(max, 0) : Bool} + +# LAW: a pool's forks say they are done on the channel it was made with +law pool_done: + for slots: Chan(Unit) + for +max: U32 + for done: Chan(Unit) + for tracked: Bool + {Step.step.pool.done(Step.step.pool(slots, max, done, tracked)) + == done : Chan(Unit)} diff --git a/laws/MethodTokensAreCaseSensitive.bend b/laws/MethodTokensAreCaseSensitive.bend index e452fd6..5bb5ab0 100644 --- a/laws/MethodTokensAreCaseSensitive.bend +++ b/laws/MethodTokensAreCaseSensitive.bend @@ -1,5 +1,9 @@ +# For every rest of a token, a method token that starts with a lowercase `g` +# is not `GET`: method tokens are compared case-sensitively (RFC 9110 §9.1), +# so `get` is not GET. import Base -# LAW (RFC 9110 §9.3): method tokens are case-sensitive +# LAW (RFC 9110 §9.1): method tokens are case-sensitive law method_tokens_are_case_sensitive: - {String.eq("GET", "get") == False{} : Bool} + for t: String + {String.eq("GET", "g" ++ t) == False{} : Bool} diff --git a/laws/MethodsSafeAndIdempotent.bend b/laws/MethodsSafeAndIdempotent.bend new file mode 100644 index 0000000..03f08db --- /dev/null +++ b/laws/MethodsSafeAndIdempotent.bend @@ -0,0 +1,31 @@ +# For every method token, the server's client treats it as safe exactly when +# it is `GET`, `HEAD` or `OPTIONS` (RFC 9110 §9.2.1) and as idempotent +# exactly when it is safe, `PUT` or `DELETE` (RFC 9110 §9.2.2), compared +# case-sensitively (RFC 9110 §9.1, laws/MethodTokensAreCaseSensitive.bend): +# `get` is not safe, POST and PATCH are neither. Every safe method is +# idempotent. +import Base +import ../src/http.bend as Http + +# LAW (RFC 9110 §9.2.1): GET, HEAD and OPTIONS are the safe methods +law method_safe_is: + for +method: String + {Http.method.safe(method) + == Bool.or(String.eq(method, "GET"), + Bool.or(String.eq(method, "HEAD"), String.eq(method, "OPTIONS"))) + : Bool} + +# LAW (RFC 9110 §9.2.2): the idempotent methods are the safe ones, PUT and +# DELETE +law method_idempotent_is: + for +method: String + {Http.method.idempotent(method) + == Bool.or(Http.method.safe(method), + Bool.or(String.eq(method, "PUT"), String.eq(method, "DELETE"))) + : Bool} + +# LAW (RFC 9110 §9.2.2): every safe method is idempotent +law method_safe_idempotent: + for +method: String + for e: {Http.method.safe(method) == True{} : Bool} + {Http.method.idempotent(method) == True{} : Bool} diff --git a/laws/MissingFieldIsEmpty.bend b/laws/MissingFieldIsEmpty.bend index 52ba907..11386ca 100644 --- a/laws/MissingFieldIsEmpty.bend +++ b/laws/MissingFieldIsEmpty.bend @@ -1,6 +1,9 @@ +# For every field name, looking it up in a header list with no fields gives +# the empty value: a field the message did not send reads as "". import Base import ../src/http.bend as Http -# LAW (RFC 9110 §5.1): a missing field looks up as empty +# LAW: an absent field reads as empty law headers_find_missing: - {Http.headers.find([], "host") == "" : String} + for +name: String + {Http.headers.find([], name) == "" : String} diff --git a/laws/NoCacheNotFresh.bend b/laws/NoCacheNotFresh.bend deleted file mode 100644 index 6f19e3e..0000000 --- a/laws/NoCacheNotFresh.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/cache.bend as Cache - -# LAW (RFC 9111 §5.2.2.2): no-cache is not fresh -law fresh_no_cache: - {Cache.cache.fresh(Cache.cache.parse("no-cache, max-age=10"), 0n) - == False{} : Bool} diff --git a/laws/NoMaxAgeNotFresh.bend b/laws/NoMaxAgeNotFresh.bend index 1373b58..2ca04a7 100644 --- a/laws/NoMaxAgeNotFresh.bend +++ b/laws/NoMaxAgeNotFresh.bend @@ -1,6 +1,20 @@ +# For every age and every directive state whose max-age argument does not +# read as delta-seconds (none was given, or it was not digits), the response +# is not fresh (`cache.fresh`), whatever else the directives and the +# recorded Expires say: without max-age nothing is treated as fresh. import Base +import ../src/http.bend as Http import ../src/cache.bend as Cache -# LAW (RFC 9111 §4.2.1): without max-age the response is not treated as fresh -law fresh_public_only: - {Cache.cache.fresh(Cache.cache.parse("public"), 0n) == False{} : Bool} +# LAW (RFC 9111 §4.2.1): without max-age the response is not fresh +law fresh_without_max_age: + for no_store: Bool + for no_cache: Bool + for public: Bool + for private: Bool + for max_age: String + for expires: String + for age: Nat + for e: {None{} == Http.digits.read(max_age) : Maybe<&2, Nat>} + {Cache.cache.fresh(Cache.Cc{no_store, no_cache, public, private, max_age, + expires}, age) == False{} : Bool} diff --git a/laws/NoStoreNotFresh.bend b/laws/NoStoreNotFresh.bend deleted file mode 100644 index f1e1b4c..0000000 --- a/laws/NoStoreNotFresh.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/cache.bend as Cache - -# LAW (RFC 9111 §5.2.2.3): no-store is not fresh -law fresh_no_store: - {Cache.cache.fresh(Cache.cache.parse("no-store, max-age=10"), 0n) - == False{} : Bool} diff --git a/laws/NonHeadReplyKeepsBody.bend b/laws/NonHeadReplyKeepsBody.bend deleted file mode 100644 index 454b2eb..0000000 --- a/laws/NonHeadReplyKeepsBody.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW: any other method keeps the response body -law get_reply_keeps_body: - {Http.reply.for("GET", Http.Reply{200, [], "secret"}) - == Http.Reply{200, [], "secret"} : Http.Reply} diff --git a/laws/NonHexChunkSizeTorn.bend b/laws/NonHexChunkSizeTorn.bend index c03984f..a600dd2 100644 --- a/laws/NonHexChunkSizeTorn.bend +++ b/laws/NonHexChunkSizeTorn.bend @@ -1,7 +1,21 @@ +# For every status, header fields and chunked body of at least one +# character whose first chunk-size line `before` (up to the first CRLF) is +# not hexadecimal digits once its extensions are removed, the response is +# torn with `chunk size is not hexadecimal` (RFC 9112 §7.1: chunk-size is +# 1*HEXDIG). import Base import ../src/http.bend as Http -# LAW (RFC 9112 §7.1): a non-hexadecimal chunk size is torn -law parse_rejects_non_hex_chunk: - {Http.parse("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\nZ\r\n\r\n") - == Http.Torn{"chunk size is not hexadecimal"} : Http.Reply} +# LAW (RFC 9112 §7.1): a chunk size that is not hex tears the response +law chunked_non_hex: + for st: U32 + for hs: List<&2, Http.Header> + for +body: String + for f: Nat + for +before: String + for +after: String + for el: {1n+f == String.length(body) : Nat} + for e: {Http.Cut{before, after} == Http.divide(body, "\r\n") : Http.Cut} + for eh: {False{} == Http.hex.well(Http.chunks.token(before)) : Bool} + {Http.parse.chunks(st, hs, body) == Http.Torn{"chunk size is not hexadecimal"} + : Http.Reply} diff --git a/laws/ObsFoldRejected.bend b/laws/ObsFoldRejected.bend index 43338b5..ca7a761 100644 --- a/laws/ObsFoldRejected.bend +++ b/laws/ObsFoldRejected.bend @@ -1,6 +1,13 @@ +# For every header line that has a colon, a value that still holds a CR or +# LF once trimmed is obs-fold (RFC 9112 §5.2), and the line gives no field. import Base import ../src/http.bend as Http -# LAW (RFC 9112 §5.2): a field value that still holds obs-fold is rejected +# LAW (RFC 9112 §5.2): a folded field value is refused law head_line_rejects_obs_fold: - {Http.head.line("A: b\r\n c") == None{} : Maybe<&2, Http.Header>} + for h: String + for +before: String + for +after: String + for e: {Http.Cut{before, after} == Http.divide(h, ":") : Http.Cut} + for ef: {True{} == Http.field.folded(String.trim(after)) : Bool} + {Http.head.line(h) == None{} : Maybe<&2, Http.Header>} diff --git a/laws/OptionsAsteriskNamesServer.bend b/laws/OptionsAsteriskNamesServer.bend index 877e081..0281400 100644 --- a/laws/OptionsAsteriskNamesServer.bend +++ b/laws/OptionsAsteriskNamesServer.bend @@ -1,7 +1,14 @@ +# For every set of header lines and body, `OPTIONS *` names the server as a +# whole (RFC 9112 §3.2.4): its target `*` is accepted as written and the +# request goes on to its header fields and framing like an origin-form one. import Base import ../src/http.bend as Http -# LAW (RFC 9112 §3.2.4): OPTIONS asterisk-form names the whole server +# LAW (RFC 9112 §3.2.4): `OPTIONS *` is accepted, its target kept law ask_options_asterisk: - {Http.ask("OPTIONS * HTTP/1.1\r\nHost: h\r\n\r\n") - == Http.Request{"OPTIONS", "*", [Http.H{"Host", "h"}], ""} : Http.Request} + for +ls: List<&2, String> + for body: String + {Http.ask.line("OPTIONS", "*", ls, body) + == Http.ask.frame("OPTIONS", "*", Http.head.list(ls), + Http.head.go(ls, "transfer-encoding"), + Http.head.values(ls, "content-length"), body) : Http.Request} diff --git a/laws/OptionsIsIdempotent.bend b/laws/OptionsIsIdempotent.bend deleted file mode 100644 index 6da820a..0000000 --- a/laws/OptionsIsIdempotent.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW: OPTIONS is idempotent because it is safe -law method_idempotent_options: - {Http.method.idempotent("OPTIONS") == True{} : Bool} diff --git a/laws/OptionsIsSafe.bend b/laws/OptionsIsSafe.bend deleted file mode 100644 index 6f302bf..0000000 --- a/laws/OptionsIsSafe.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §9.2.1): OPTIONS is safe -law method_safe_options: - {Http.method.safe("OPTIONS") == True{} : Bool} diff --git a/laws/OriginFormKeepsQuery.bend b/laws/OriginFormKeepsQuery.bend index 83da1bc..02fad00 100644 --- a/laws/OriginFormKeepsQuery.bend +++ b/laws/OriginFormKeepsQuery.bend @@ -1,7 +1,18 @@ +# For every method, target, header lines and body, a target that starts +# with `/` is origin-form (RFC 9112 §3.2.1): it is accepted exactly as +# written, its query included, and the request goes on to its header +# fields and framing. import Base import ../src/http.bend as Http -# LAW (RFC 9112 §3.2.1): origin-form keeps an absolute-path and its query +# LAW (RFC 9112 §3.2.1): an origin-form target is kept as written law ask_origin_form_keeps_query: - {Http.ask("GET /ok?a=1 HTTP/1.1\r\nHost: h\r\n\r\n") - == Http.Request{"GET", "/ok?a=1", [Http.H{"Host", "h"}], ""} : Http.Request} + for +method: String + for +target: String + for +ls: List<&2, String> + for body: String + for e: {True{} == String.starts_with(target, "/") : Bool} + {Http.ask.line(method, target, ls, body) + == Http.ask.frame(method, target, Http.head.list(ls), + Http.head.go(ls, "transfer-encoding"), + Http.head.values(ls, "content-length"), body) : Http.Request} diff --git a/laws/PatchNotIdempotent.bend b/laws/PatchNotIdempotent.bend deleted file mode 100644 index 2eea20a..0000000 --- a/laws/PatchNotIdempotent.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §9.2.2): PATCH is not one of the idempotent methods we name -law method_idempotent_patch: - {Http.method.idempotent("PATCH") == False{} : Bool} diff --git a/laws/PostNotIdempotent.bend b/laws/PostNotIdempotent.bend deleted file mode 100644 index b3dfa39..0000000 --- a/laws/PostNotIdempotent.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW: POST is not idempotent -law method_idempotent_post: - {Http.method.idempotent("POST") == False{} : Bool} diff --git a/laws/PostNotSafe.bend b/laws/PostNotSafe.bend deleted file mode 100644 index 1533cbb..0000000 --- a/laws/PostNotSafe.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW: POST is not safe -law method_safe_post: - {Http.method.safe("POST") == False{} : Bool} diff --git a/laws/PostWritesContentLength.bend b/laws/PostWritesContentLength.bend deleted file mode 100644 index ae30ed3..0000000 --- a/laws/PostWritesContentLength.bend +++ /dev/null @@ -1,15 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §8.6): a non-empty request body is framed by Content-Length -law post_writes_content_length: - {Http.request("POST", "h", "/a", [], "hi") - == "POST /a HTTP/1.1\r\n" - ++ "Host: h\r\n" - ++ "User-Agent: ezhttp\r\n" - ++ "Accept: */*\r\n" - ++ "Connection: close\r\n" - ++ "Content-Length: 2\r\n" - ++ "\r\n" - ++ "hi" - : String} diff --git a/laws/PutIsIdempotent.bend b/laws/PutIsIdempotent.bend deleted file mode 100644 index 0ab47fa..0000000 --- a/laws/PutIsIdempotent.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §9.2.2): PUT is idempotent -law method_idempotent_put: - {Http.method.idempotent("PUT") == True{} : Bool} diff --git a/laws/PutNotSafe.bend b/laws/PutNotSafe.bend deleted file mode 100644 index a2513d6..0000000 --- a/laws/PutNotSafe.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §9.2.1): PUT is not safe -law method_safe_put: - {Http.method.safe("PUT") == False{} : Bool} diff --git a/laws/Reason200IsOk.bend b/laws/Reason200IsOk.bend deleted file mode 100644 index d820360..0000000 --- a/laws/Reason200IsOk.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9112 §4): 200 uses the OK reason-phrase -law reason_200: - {Http.reason(200) == "OK" : String} diff --git a/laws/Reason201IsCreated.bend b/laws/Reason201IsCreated.bend deleted file mode 100644 index e3f027d..0000000 --- a/laws/Reason201IsCreated.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §15.3.2): 201 Created -law reason_201: - {Http.reason(201) == "Created" : String} diff --git a/laws/Reason204IsNoContent.bend b/laws/Reason204IsNoContent.bend deleted file mode 100644 index 3e75ae7..0000000 --- a/laws/Reason204IsNoContent.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §15.3.5): 204 No Content -law reason_204: - {Http.reason(204) == "No Content" : String} diff --git a/laws/Reason400IsBadRequest.bend b/laws/Reason400IsBadRequest.bend deleted file mode 100644 index 40bef94..0000000 --- a/laws/Reason400IsBadRequest.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §15.5.1): 400 Bad Request -law reason_400: - {Http.reason(400) == "Bad Request" : String} diff --git a/laws/Reason404IsNotFound.bend b/laws/Reason404IsNotFound.bend deleted file mode 100644 index 73e2f57..0000000 --- a/laws/Reason404IsNotFound.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §15.5.5): 404 Not Found -law reason_404: - {Http.reason(404) == "Not Found" : String} diff --git a/laws/Reason405IsMethodNotAllowed.bend b/laws/Reason405IsMethodNotAllowed.bend deleted file mode 100644 index 5b0d35f..0000000 --- a/laws/Reason405IsMethodNotAllowed.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §15.5.6): 405 Method Not Allowed -law reason_405: - {Http.reason(405) == "Method Not Allowed" : String} diff --git a/laws/Reason500IsInternalServerError.bend b/laws/Reason500IsInternalServerError.bend deleted file mode 100644 index 45c4f92..0000000 --- a/laws/Reason500IsInternalServerError.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §15.6.1): 500 Internal Server Error -law reason_500: - {Http.reason(500) == "Internal Server Error" : String} diff --git a/laws/RelativeTargetRejected.bend b/laws/RelativeTargetRejected.bend deleted file mode 100644 index 1650683..0000000 --- a/laws/RelativeTargetRejected.bend +++ /dev/null @@ -1,8 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9112 §3.2.1): a request-target without a leading `/` is not -# origin-form -law ask_rejects_relative_target: - {Http.ask("GET relative HTTP/1.1\r\nHost: h\r\n\r\n") - == Http.Bad{"the request-target is not in origin-form"} : Http.Request} diff --git a/laws/RequestDisagreeingContentLengthsRejected.bend b/laws/RequestDisagreeingContentLengthsRejected.bend index b5bd35f..158ea3e 100644 --- a/laws/RequestDisagreeingContentLengthsRejected.bend +++ b/laws/RequestDisagreeingContentLengthsRejected.bend @@ -1,7 +1,26 @@ +# For every request whose Content-Length values disagree, the request is +# bad before any framing (RFC 9112 §6.3): two values that are not the same +# digits disagree, wherever they come in the list, and a list that +# disagrees frames no body. import Base import ../src/http.bend as Http -# LAW (RFC 9112 §6.3): Content-Length values that differ are a bad request +# LAW (RFC 9112 §6.3): a second value unlike the first disagrees +law clen_disagree: + for +v: String + for w: String + for rest: List<&2, String> + for e: {False{} == String.eq(w, v) : Bool} + {Http.clen.agree(v <> w <> rest) == False{} : Bool} + +# LAW (RFC 9112 §6.3): disagreeing Content-Length values are a bad request law ask_rejects_disagreeing_cl: - {Http.ask("GET / HTTP/1.1\r\nContent-Length: 1\r\nContent-Length: 2\r\n\r\nab") + for method: String + for target: String + for hs: List<&2, Http.Header> + for te: String + for +lens: List<&2, String> + for body: String + for e: {False{} == Http.clen.agree(lens) : Bool} + {Http.ask.frame(method, target, hs, te, lens, body) == Http.Bad{"Content-Length values disagree"} : Http.Request} diff --git a/laws/RequestEqualContentLengthsFrameOneBody.bend b/laws/RequestEqualContentLengthsFrameOneBody.bend index 870d220..ada6a4b 100644 --- a/laws/RequestEqualContentLengthsFrameOneBody.bend +++ b/laws/RequestEqualContentLengthsFrameOneBody.bend @@ -1,8 +1,41 @@ +# For every request whose Content-Length values are all the same digits, +# the values agree (RFC 9112 §6.3): a repeated value adds nothing to the +# list it repeats. A request whose values agree and that is not chunked is +# framed by its first value alone, and a body longer than that value is +# cut to it. import Base import ../src/http.bend as Http -# LAW (RFC 9112 §6.3): identical request Content-Length values frame one body +# LAW (RFC 9112 §6.3): a value repeating the first changes nothing +law clen_agree_repeat: + for +v: String + for w: String + for rest: List<&2, String> + for e: {True{} == String.eq(w, v) : Bool} + {Http.clen.agree(v <> w <> rest) == Http.clen.agree(v <> rest) : Bool} + +# LAW (RFC 9112 §6.3): agreeing values frame the body by the first one law ask_equal_content_lengths: - {Http.ask("POST / HTTP/1.1\r\nContent-Length: 5\r\nContent-Length: 5\r\n\r\nhello!!") - == Http.Request{"POST", "/", [Http.H{"Content-Length", "5"}, - Http.H{"Content-Length", "5"}], "hello"} : Http.Request} + for method: String + for target: String + for hs: List<&2, Http.Header> + for +te: String + for +lens: List<&2, String> + for body: String + for ea: {True{} == Http.clen.agree(lens) : Bool} + for ec: {False{} == String.contains(String.to_lower(te), "chunked") : Bool} + {Http.ask.frame(method, target, hs, te, lens, body) + == Http.ask.len(method, target, hs, Http.digits.read(Http.first(lens)), + body) : Http.Request} + +# LAW (RFC 9112 §6.3): a body longer than Content-Length is cut to it +law ask_clen_takes_prefix: + for +method: String + for +target: String + for hs: List<&2, Http.Header> + for +n: Nat + for +body: String + for e: {False{} == Nat.is_lt(Http.octs.len(body), n) : Bool} + {Http.ask.clen(method, target, hs, n, body) + == Http.Request{method, target, hs, Http.octs.take(body, n)} + : Http.Request} diff --git a/laws/RequestKeepsFieldNameSpelling.bend b/laws/RequestKeepsFieldNameSpelling.bend index fd88e37..eefa115 100644 --- a/laws/RequestKeepsFieldNameSpelling.bend +++ b/laws/RequestKeepsFieldNameSpelling.bend @@ -1,7 +1,18 @@ +# For every header line that gives a field and every list of lines after +# it, the request's header fields are that field, its name spelled exactly +# as the line wrote it (field names are compared case-insensitively, RFC +# 9110 §5.1, but never rewritten), and then the fields of the other lines. import Base import ../src/http.bend as Http -# LAW (RFC 9110 §5.1): the wire spelling of a field name is kept +# LAW (RFC 9110 §5.1): a field's name is kept as written law ask_keeps_field_name_spelling: - {Http.ask("GET / HTTP/1.1\r\nhOsT: Ex.COM\r\n\r\n") - == Http.Request{"GET", "/", [Http.H{"hOsT", "Ex.COM"}], ""} : Http.Request} + for h: String + for t: List<&2, String> + for +before: String + for +after: String + for e: {Http.Cut{before, after} == Http.divide(h, ":") : Http.Cut} + for ef: {False{} == Http.field.folded(String.trim(after)) : Bool} + {Http.head.list(h <> t) + == Http.H{before, String.trim(after)} <> Http.head.list(t) + : List<&2, Http.Header>} diff --git a/laws/RequestWithBothFramingsRejected.bend b/laws/RequestWithBothFramingsRejected.bend index 5b05cc6..931b14e 100644 --- a/laws/RequestWithBothFramingsRejected.bend +++ b/laws/RequestWithBothFramingsRejected.bend @@ -1,7 +1,20 @@ +# For every request that sends a Content-Length field and a chunked +# Transfer-Encoding whose Content-Length values agree, the two framings +# conflict and the request is bad (RFC 9112 §6.3). import Base import ../src/http.bend as Http -# LAW (RFC 9112 §6.3): a request with both framings is bad +# LAW (RFC 9112 §6.3): Content-Length with chunked framing is a bad request law ask_rejects_cl_and_te: - {Http.ask("POST / HTTP/1.1\r\nContent-Length: 1\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n\r\n") - == Http.Bad{"Content-Length and Transfer-Encoding conflict"} : Http.Request} + for method: String + for target: String + for hs: List<&2, Http.Header> + for +te: String + for +l: String + for +ls: List<&2, String> + for body: String + for ea: {True{} == Http.clen.agree(l <> ls) : Bool} + for ec: {True{} == String.contains(String.to_lower(te), "chunked") : Bool} + {Http.ask.frame(method, target, hs, te, l <> ls, body) + == Http.Bad{"Content-Length and Transfer-Encoding conflict"} + : Http.Request} diff --git a/laws/Respond200KeepsBody.bend b/laws/Respond200KeepsBody.bend deleted file mode 100644 index 27d6856..0000000 --- a/laws/Respond200KeepsBody.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §15.3.1): a 200 response keeps its body -law respond_200_keeps_body: - {Http.respond.of(Http.Reply{200, [], "ok"}) == Http.respond(200, [], "ok") - : String} diff --git a/laws/Respond204DropsBody.bend b/laws/Respond204DropsBody.bend deleted file mode 100644 index ad442ea..0000000 --- a/laws/Respond204DropsBody.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §15.3.5): a 204 response is written with an empty body -law respond_204_drops_body: - {Http.respond.of(Http.Reply{204, [], "nope"}) == Http.respond(204, [], "") - : String} diff --git a/laws/Respond304DropsBody.bend b/laws/Respond304DropsBody.bend deleted file mode 100644 index b47a56b..0000000 --- a/laws/Respond304DropsBody.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §15.4.5): a 304 response is written with an empty body -law respond_304_drops_body: - {Http.respond.of(Http.Reply{304, [], "nope"}) == Http.respond(304, [], "") - : String} diff --git a/laws/ResponseDisagreeingContentLengthsTorn.bend b/laws/ResponseDisagreeingContentLengthsTorn.bend deleted file mode 100644 index f785fc1..0000000 --- a/laws/ResponseDisagreeingContentLengthsTorn.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9112 §6.3): a response whose Content-Length values differ is torn -law parse_rejects_disagreeing_cl: - {Http.parse("HTTP/1.1 200 OK\r\nContent-Length: 1\r\nContent-Length: 2\r\n\r\nab") - == Http.Torn{"Content-Length values disagree"} : Http.Reply} diff --git a/laws/ResponseWithBothFramingsTorn.bend b/laws/ResponseWithBothFramingsTorn.bend deleted file mode 100644 index b6cf2d7..0000000 --- a/laws/ResponseWithBothFramingsTorn.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9112 §6.3): Content-Length and Transfer-Encoding together are torn -law parse_rejects_cl_and_te: - {Http.parse("HTTP/1.1 200 OK\r\nContent-Length: 1\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n\r\n") - == Http.Torn{"Content-Length and Transfer-Encoding conflict"} : Http.Reply} diff --git a/laws/SetCookieParsesBack.bend b/laws/SetCookieParsesBack.bend index eca0bb4..2f54e9f 100644 --- a/laws/SetCookieParsesBack.bend +++ b/laws/SetCookieParsesBack.bend @@ -1,9 +1,125 @@ +# For every Set-Cookie line (RFC 6265 §5.2): the line is split at `;`; the +# first piece, trimmed, is the name-value-pair, cut at its first `=` (the +# name and the value each trimmed, laws/CookieRejectsEmptyName.bend for the +# pairs that set nothing), and the cookie starts as a session cookie with +# that name and value; each further piece, trimmed, is an attribute applied +# in order: one with an `=` is a named attribute, its name trimmed and +# lowercased and its value trimmed; one without is a flag, trimmed and +# lowercased. `expires` stores the value as written, `path` the path, +# `secure` and `httponly` set their flags (Max-Age, Domain and SameSite: +# laws/CookieMaxAgeIgnoresJunk.bend, laws/CookieDomainLowercased.bend, +# laws/CookieSameSiteFoldsCase.bend). So a line written by `cookie.line` +# parses back to its cookie. import Base +import ../src/http.bend as Http import ../src/cookie.bend as Cookie -# LAW (RFC 6265 §4.1.1): Set-Cookie parses back to those attributes -law cookie_parse_round_trip: - {Cookie.cookie.parse("a=b; Expires=Wed, 21 Oct 2015 07:28:00 GMT; Max-Age=12; Domain=example.com; Path=/app; Secure; HttpOnly; SameSite=Lax") - == Some{Cookie.Cookie{"a", "b", "Wed, 21 Oct 2015 07:28:00 GMT", "12", - "example.com", "/app", True{}, True{}, "Lax", False{}}} +# LAW (RFC 6265 §5.2): the line split at `;` +law cookie_parse: + for line: String + {Cookie.cookie.parse(line) + == Cookie.cookie.parse.parts(String.split(line, ';')) : Maybe<&2, Cookie.Cookie>} + +# LAW (§5.2 step 1): the first piece, trimmed, cut at its first `=` +law cookie_parse_parts: + for h: String + for t: List<&2, String> + {Cookie.cookie.parse.parts(h <> t) + == Cookie.cookie.from(String.trim(h), t, Http.divide(String.trim(h), "=")) + : Maybe<&2, Cookie.Cookie>} + +# LAW (§5.2 steps 3-4): the name and the value, trimmed +law cookie_from_cut: + for pair: String + for attrs: List<&2, String> + for +before: String + for after: String + {Cookie.cookie.from(pair, attrs, Http.Cut{before, after}) + == Cookie.cookie.from.name(String.trim(before), String.trim(after), attrs, + String.is_empty(String.trim(before))) : Maybe<&2, Cookie.Cookie>} + +# LAW (§5.2 step 6): a session cookie with the attributes applied in order +law cookie_from_named: + for name: String + for value: String + for attrs: List<&2, String> + {Cookie.cookie.from.name(name, value, attrs, False{}) + == Some{Cookie.cookie.fold(attrs, Cookie.cookie.new(name, value))} + : Maybe<&2, Cookie.Cookie>} + +# LAW: a session cookie has no attributes and is host-only +law cookie_new: + for name: String + for value: String + {Cookie.cookie.new(name, value) + == Cookie.Cookie{name, value, "", "", "", "", False{}, False{}, "", True{}} + : Cookie.Cookie} + +# LAW: no attributes left, the cookie +law cookie_fold_nil: + for ps: List<&2, String> + for +c: Cookie.Cookie + for e: {[] == ps : List<&2, String>} + {Cookie.cookie.fold(ps, c) == c : Cookie.Cookie} + +# LAW: each attribute, trimmed, in order +law cookie_fold_cons: + for h: String + for t: List<&2, String> + for c: Cookie.Cookie + {Cookie.cookie.fold(h <> t, c) + == Cookie.cookie.fold(t, Cookie.cookie.apply(c, String.trim(h))) + : Cookie.Cookie} + +# LAW (§5.2): an attribute is cut at its first `=` +law cookie_apply: + for c: Cookie.Cookie + for +piece: String + {Cookie.cookie.apply(c, piece) + == Cookie.cookie.apply.cut(c, piece, Http.divide(piece, "=")) + : Cookie.Cookie} + +# LAW (§5.2): with an `=`, a named attribute, name lowercased +law cookie_apply_named: + for c: Cookie.Cookie + for piece: String + for before: String + for after: String + {Cookie.cookie.apply.cut(c, piece, Http.Cut{before, after}) + == Cookie.cookie.named(c, String.to_lower(String.trim(before)), + String.trim(after)) : Cookie.Cookie} + +# LAW (§5.2): without one, a flag, lowercased +law cookie_apply_flag: + for c: Cookie.Cookie + for piece: String + {Cookie.cookie.apply.cut(c, piece, Http.NoCut{}) + == Cookie.cookie.flag(c, String.to_lower(String.trim(piece))) + : Cookie.Cookie} + +# LAW (§5.2.1): Expires is stored as written +law cookie_named_expires: + for c: Cookie.Cookie + for value: String + {Cookie.cookie.named(c, "expires", value) == Cookie.cookie.expires(c, value) + : Cookie.Cookie} + +# LAW (§5.2.4): Path is stored +law cookie_named_path: + for c: Cookie.Cookie + for value: String + {Cookie.cookie.named(c, "path", value) == Cookie.cookie.dir(c, value) + : Cookie.Cookie} + +# LAW (§5.2.5): the secure flag sets Secure +law cookie_flag_secure: + for c: Cookie.Cookie + {Cookie.cookie.flag(c, "secure") == Cookie.cookie.secure_on(c) + : Cookie.Cookie} + +# LAW (§5.2.6): the httponly flag sets HttpOnly +law cookie_flag_http_only: + for c: Cookie.Cookie + {Cookie.cookie.flag(c, "httponly") == Cookie.cookie.http_on(c) + : Cookie.Cookie} diff --git a/laws/StaleAtMaxAge.bend b/laws/StaleAtMaxAge.bend deleted file mode 100644 index 799b3e6..0000000 --- a/laws/StaleAtMaxAge.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/cache.bend as Cache - -# LAW (RFC 9111 §4.2.1): an age equal to max-age is stale -law fresh_max_age_limit: - {Cache.cache.fresh(Cache.cache.parse("max-age=10"), 10n) == False{} : Bool} diff --git a/laws/UnknownStatusHasEmptyReason.bend b/laws/UnknownStatusHasEmptyReason.bend deleted file mode 100644 index e22f668..0000000 --- a/laws/UnknownStatusHasEmptyReason.bend +++ /dev/null @@ -1,6 +0,0 @@ -import Base -import ../src/http.bend as Http - -# LAW (RFC 9110 §15): a status we do not name has an empty reason-phrase -law reason_unknown_empty: - {Http.reason(418) == "" : String} diff --git a/laws/UrlBadPortUsesDefault.bend b/laws/UrlBadPortUsesDefault.bend index f70975f..d28b4f7 100644 --- a/laws/UrlBadPortUsesDefault.bend +++ b/laws/UrlBadPortUsesDefault.bend @@ -1,7 +1,14 @@ import Base import ../src/url.bend as Url +# For every host, port text that does not read as a number, later pieces and +# scheme, an authority split on its colons gets the port its scheme implies. + # LAW (RFC 3986 §3.2.3): a non-numeric port falls back to the scheme default -law url_bad_port_uses_default: - {Url.parse("http://example.com:abc/x") - == Url.Loc{"http", "example.com", 80, "/x"} : Url.Loc} +law port_junk: + for host: String + for port: String + for rest: List<&2, String> + for +scheme: String + for e: {None{} == U32.read(port) : Maybe<&2, U32>} + {Url.port.of(host <> port <> rest, scheme) == Url.dflt(scheme) : U32} diff --git a/laws/UrlEmptyPath.bend b/laws/UrlEmptyPath.bend index 85b703a..9281274 100644 --- a/laws/UrlEmptyPath.bend +++ b/laws/UrlEmptyPath.bend @@ -1,9 +1,9 @@ import Base import ../src/url.bend as Url -# --- RFC 3986 authority, query, fragment --- +# For every authority with nothing after it (no `/`), the path is `/`. -# LAW (RFC 3986 §3.3): an empty path-abempty is the origin-form `/` -law url_empty_path: - {Url.parse("http://example.com") - == Url.Loc{"http", "example.com", 80, "/"} : Url.Loc} +# LAW (RFC 3986 §3.3, RFC 9112 §3.2.1): an empty path is sent as `/` +law path_empty: + for authority: String + {Url.path.of([authority]) == "/" : String} diff --git a/laws/UrlFragmentHidesQuery.bend b/laws/UrlFragmentHidesQuery.bend index fc70d84..72f2346 100644 --- a/laws/UrlFragmentHidesQuery.bend +++ b/laws/UrlFragmentHidesQuery.bend @@ -1,7 +1,14 @@ import Base import ../src/url.bend as Url -# LAW (RFC 3986 §3.5): a `?` inside the fragment is not a query -law url_fragment_hides_query: - {Url.parse("http://example.com/a#b?c") - == Url.Loc{"http", "example.com", 80, "/a"} : Url.Loc} +# For every text whose `#` split starts with `hier`, dropping the fragment +# keeps exactly `hier`: everything from the first `#` on, a `?` in it +# included, is gone before the query is looked for. + +# LAW (RFC 3986 §3.5): the fragment is everything after the first `#` +law frag_first: + for s: String + for hier: String + for rest: List<&2, String> + for e: {hier <> rest == String.split(s, '#') : List<&2, String>} + {Url.frag.drop(s) == hier : String} diff --git a/laws/UrlHttpDefaultPort.bend b/laws/UrlHttpDefaultPort.bend index 0ae26dc..e7c623f 100644 --- a/laws/UrlHttpDefaultPort.bend +++ b/laws/UrlHttpDefaultPort.bend @@ -1,9 +1,12 @@ import Base import ../src/url.bend as Url -# --- thicker fence: more closed witnesses of the same RFCs --- +# For every host and scheme, an authority that names no port (no colon) gets +# the port its scheme implies: 80, or 443 for https +# (laws/OtherSchemesDefaultTo80.bend, laws/HttpsDefaultsTo443.bend). -# LAW (RFC 3986 §3.2.3): http with no port is 80 -law url_http_default_port: - {Url.parse("http://example.com/a") - == Url.Loc{"http", "example.com", 80, "/a"} : Url.Loc} +# LAW (RFC 3986 §3.2.3): an authority without a port takes the scheme's +law port_absent: + for host: String + for scheme: String + {Url.port.of([host], scheme) == Url.dflt(scheme) : U32} diff --git a/laws/UrlHttpsDefaultPort.bend b/laws/UrlHttpsDefaultPort.bend deleted file mode 100644 index 93631c3..0000000 --- a/laws/UrlHttpsDefaultPort.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/url.bend as Url - -# LAW (RFC 3986 §3.2.3 / RFC 2818): https with no port is 443 -law url_https_default_port: - {Url.parse("https://example.com/a") - == Url.Loc{"https", "example.com", 443, "/a"} : Url.Loc} diff --git a/laws/UrlHttpsExplicitPort.bend b/laws/UrlHttpsExplicitPort.bend index e4f4229..25fddd6 100644 --- a/laws/UrlHttpsExplicitPort.bend +++ b/laws/UrlHttpsExplicitPort.bend @@ -1,7 +1,16 @@ import Base import ../src/url.bend as Url -# LAW (RFC 3986 §3.2.3): an explicit https port is kept -law url_https_explicit_port: - {Url.parse("https://example.com:8443/a") - == Url.Loc{"https", "example.com", 8443, "/a"} : Url.Loc} +# For every host, port text that reads as a number `n`, later pieces and +# scheme, an authority split on its colons names port `n`, whatever the +# scheme would imply. + +# LAW (RFC 3986 §3.2.3): an explicit numeric port wins over the default +law port_explicit: + for host: String + for port: String + for rest: List<&2, String> + for n: U32 + for scheme: String + for e: {Some{n} == U32.read(port) : Maybe<&2, U32>} + {Url.port.of(host <> port <> rest, scheme) == n : U32} diff --git a/laws/UrlIpv4Host.bend b/laws/UrlIpv4Host.bend index f5fb39b..9b6e192 100644 --- a/laws/UrlIpv4Host.bend +++ b/laws/UrlIpv4Host.bend @@ -1,7 +1,11 @@ import Base import ../src/url.bend as Url -# LAW (RFC 3986 §3.2.2): an IPv4 literal is the host -law url_ipv4_host: - {Url.parse("http://192.0.2.1/a") - == Url.Loc{"http", "192.0.2.1", 80, "/a"} : Url.Loc} +# For every authority split on its colons, the host is the piece before the +# first colon, unchanged: a name or an IPv4 literal alike. + +# LAW (RFC 3986 §3.2.2): the host is everything before the port's colon +law host_before_colon: + for host: String + for rest: List<&2, String> + {Url.host.of(host <> rest) == host : String} diff --git a/laws/UrlIpv4Port.bend b/laws/UrlIpv4Port.bend deleted file mode 100644 index 5c37e25..0000000 --- a/laws/UrlIpv4Port.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/url.bend as Url - -# LAW (RFC 3986 §3.2.3): an explicit port wins over the scheme default -law url_ipv4_port: - {Url.parse("http://192.0.2.1:8080/a") - == Url.Loc{"http", "192.0.2.1", 8080, "/a"} : Url.Loc} diff --git a/laws/UrlQueryDropsFragment.bend b/laws/UrlQueryDropsFragment.bend deleted file mode 100644 index c7e54cc..0000000 --- a/laws/UrlQueryDropsFragment.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/url.bend as Url - -# LAW (RFC 3986 §3.4, §3.5): the query stays on the path; the fragment does not -law url_query_drops_fragment: - {Url.parse("http://example.com/a/b?x=1#frag") - == Url.Loc{"http", "example.com", 80, "/a/b?x=1"} : Url.Loc} diff --git a/laws/UrlQueryKeepsQuestion.bend b/laws/UrlQueryKeepsQuestion.bend index f9daef2..541f665 100644 --- a/laws/UrlQueryKeepsQuestion.bend +++ b/laws/UrlQueryKeepsQuestion.bend @@ -1,7 +1,18 @@ import Base import ../src/url.bend as Url -# LAW (RFC 3986 §3.4): a later `?` stays inside the query -law url_query_keeps_question: - {Url.parse("http://example.com/a?x=1?y=2") - == Url.Loc{"http", "example.com", 80, "/a?x=1?y=2"} : Url.Loc} +# For every hier-part split on `?`, the part before the first `?` is the +# hier-part and the query is the rest joined back with `?`, so a later `?` +# stays in the query. + +# LAW (RFC 3986 §3.4): the hier-part ends at the first `?` +law query_hier_first: + for hier: String + for rest: List<&2, String> + {Url.query.hier(hier <> rest) == hier : String} + +# LAW (RFC 3986 §3.4): the query keeps every later `?` +law query_keeps_question: + for hier: String + for rest: List<&2, String> + {Url.query.text(hier <> rest) == String.join(rest, "?") : String} diff --git a/laws/UrlQueryOnEmptyPath.bend b/laws/UrlQueryOnEmptyPath.bend index e3c4d3b..f73306d 100644 --- a/laws/UrlQueryOnEmptyPath.bend +++ b/laws/UrlQueryOnEmptyPath.bend @@ -1,7 +1,12 @@ import Base import ../src/url.bend as Url -# LAW (RFC 3986 §3.3, §3.4): an empty path with a query is `/?query` -law url_query_on_empty_path: - {Url.parse("http://example.com?x=1") - == Url.Loc{"http", "example.com", 80, "/?x=1"} : Url.Loc} +# For every path and non-empty query, the origin-form target is the path, +# `?` and the query; an empty path (`/`) with a query is `/?query`. + +# LAW (RFC 3986 §3.4, RFC 9112 §3.2.1): a query follows the path after `?` +law path_target_query: + for path: String + for +query: String + for e: {False{} == String.is_empty(query) : Bool} + {Url.path.target(path, query) == path ++ "?" ++ query : String} diff --git a/laws/UrlSchemeLowercased.bend b/laws/UrlSchemeLowercased.bend deleted file mode 100644 index 5d8d50a..0000000 --- a/laws/UrlSchemeLowercased.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/url.bend as Url - -# LAW (RFC 3986 §3.1): the scheme is lowercased; the host is not -law url_scheme_lowercased: - {Url.parse("HTTPS://Example.com/x") - == Url.Loc{"https", "Example.com", 443, "/x"} : Url.Loc} diff --git a/laws/UrlTrailingSlash.bend b/laws/UrlTrailingSlash.bend index 102e31e..2e2c6b6 100644 --- a/laws/UrlTrailingSlash.bend +++ b/laws/UrlTrailingSlash.bend @@ -1,7 +1,13 @@ import Base import ../src/url.bend as Url -# LAW (RFC 3986 §3.3): a trailing slash is part of the path -law url_trailing_slash: - {Url.parse("http://example.com/a/") - == Url.Loc{"http", "example.com", 80, "/a/"} : Url.Loc} +# For every hier-part split on `/`, the path is `/` and the pieces after the +# authority joined back with `/`, each kept as written, so an empty last +# piece (a trailing slash) stays. + +# LAW (RFC 3986 §3.3): the path keeps its segments, trailing slash included +law path_rejoined: + for authority: String + for segments: List<&2, String> + {Url.path.of(authority <> segments) == "/" ++ String.join(segments, "/") + : String} diff --git a/laws/UrlUserinfoLastAt.bend b/laws/UrlUserinfoLastAt.bend index 37ccf03..8ea7b41 100644 --- a/laws/UrlUserinfoLastAt.bend +++ b/laws/UrlUserinfoLastAt.bend @@ -1,7 +1,14 @@ import Base import ../src/url.bend as Url -# LAW (RFC 3986 §3.2.1): the last `@` piece is the hostport -law url_userinfo_last_at: - {Url.parse("http://a@b@example.com/z") - == Url.Loc{"http", "example.com", 80, "/z"} : Url.Loc} +# For every authority whose `@` split ends in `hostport`, the host and port +# are read from `hostport` alone: every earlier piece, `user:pass` or a +# stray `a@b`, is userinfo and dropped. + +# LAW (RFC 3986 §3.2.1): userinfo is stripped up to the last `@` +law host_after_last_at: + for authority: String + for hostport: String + for e: {Some{hostport} == List.last(&2, String, String.split(authority, '@')) + : Maybe<&2, String>} + {Url.auth.host(authority) == hostport : String} diff --git a/laws/UrlUserinfoStripped.bend b/laws/UrlUserinfoStripped.bend deleted file mode 100644 index fd9ec3b..0000000 --- a/laws/UrlUserinfoStripped.bend +++ /dev/null @@ -1,7 +0,0 @@ -import Base -import ../src/url.bend as Url - -# LAW (RFC 3986 §3.2.1): userinfo is stripped; it is not the host -law url_userinfo_stripped: - {Url.parse("http://user:pass@example.com/a") - == Url.Loc{"http", "example.com", 80, "/a"} : Url.Loc} diff --git a/main.bend b/main.bend index 7ae92fd..15139f6 100644 --- a/main.bend +++ b/main.bend @@ -94,8 +94,11 @@ def parse_request(raw: String) -> Http.Request: # noqa: L001 re-export of Http. Http.ask(raw) # format a response message (server outbound) -def format_response(status: U32, headers: List<&2, Http.Header>, body: String) # noqa: L001 re-export of Http.respond - -> String: +def format_response( # noqa: L001 re-export of Http.respond + status: U32, + headers: List<&2, Http.Header>, + body: String +) -> String: Http.respond(status, headers, body) # empty request body @@ -120,8 +123,12 @@ def form_field(name: String, value: String) -> Form.Upload: # noqa: L001 re-exp # a multipart/form-data file part: field name, filename, content type and the # file's bytes (packed Bytes, sent unchanged) -def form_file(name: String, filename: String, ctype: String, # noqa: L001 re-export of Form.form.file - bytes: Bytes.Bytes) -> Form.Upload: +def form_file( # noqa: L001 re-export of Form.form.file + name: String, + filename: String, + ctype: String, + bytes: Bytes.Bytes +) -> Form.Upload: Form.form.file(name, filename, ctype, bytes) # a multipart/form-data body (RFC 7578) with this boundary: the Content-Type @@ -207,8 +214,10 @@ def http.get(url: String) -> IO(Client.Response): Client.client.get(url, []) # GET with headers -def http.get_with(url: String, headers: List<&2, Http.Header>) - -> IO(Client.Response): +def http.get_with( + url: String, + headers: List<&2, Http.Header> +) -> IO(Client.Response): Client.client.get(url, headers) # GET with headers and a timeout in milliseconds that bounds connecting, @@ -280,8 +289,10 @@ def http.head(url: String) -> IO(Client.Response): Client.client.head(url, []) # HEAD with headers -def http.head_with(url: String, headers: List<&2, Http.Header>) - -> IO(Client.Response): +def http.head_with( + url: String, + headers: List<&2, Http.Header> +) -> IO(Client.Response): Client.client.head(url, headers) # POST with a body and no extra headers @@ -301,8 +312,11 @@ def http.put(url: String, body: Body.Body) -> IO(Client.Response): Client.client.put(url, [], body) # PUT with headers and a body -def http.put_with(url: String, headers: List<&2, Http.Header>, body: Body.Body) - -> IO(Client.Response): +def http.put_with( + url: String, + headers: List<&2, Http.Header>, + body: Body.Body +) -> IO(Client.Response): Client.client.put(url, headers, body) # DELETE with a body and no extra headers @@ -322,8 +336,10 @@ def http.options(url: String) -> IO(Client.Response): Client.client.options(url, []) # OPTIONS with headers -def http.options_with(url: String, headers: List<&2, Http.Header>) - -> IO(Client.Response): +def http.options_with( + url: String, + headers: List<&2, Http.Header> +) -> IO(Client.Response): Client.client.options(url, headers) # listen on host:port and serve up to `limit` connections @@ -394,20 +410,27 @@ def http.serve_io_with( # a reply with a text body, written as UTF-8 def text_reply( # noqa: L001 constructor of Server.Answer, which holds Bytes - status: U32, headers: List<&2, Http.Header>, body: String) -> Server.Answer: + status: U32, + headers: List<&2, Http.Header>, + body: String +) -> Server.Answer: Server.TextReply{status, headers, body} # a reply whose body is packed octets, written unchanged def octets_reply( # noqa: L001 constructor of Server.Answer, which holds Bytes - status: U32, headers: List<&2, Http.Header>, bytes: Bytes.Bytes) - -> Server.Answer: + status: U32, + headers: List<&2, Http.Header>, + bytes: Bytes.Bytes +) -> Server.Answer: Server.OctetsReply{status, headers, bytes} # a reply streamed chunked: each chunk the channel gives is written as it # comes, and the body ends when the channel is closed def stream_reply( # noqa: L001 constructor of Server.Answer, which holds a channel - status: U32, headers: List<&2, Http.Header>, chunks: Chan(Bytes.Bytes)) - -> Server.Answer: + status: U32, + headers: List<&2, Http.Header>, + chunks: Chan(Bytes.Bytes) +) -> Server.Answer: Server.StreamReply{status, headers, chunks} # listen on host:port, serve one connection, then stop diff --git a/proofs/AbsoluteFormTargetRejected.bend b/proofs/AbsoluteFormTargetRejected.bend index 099609d..6fd8fda 100644 --- a/proofs/AbsoluteFormTargetRejected.bend +++ b/proofs/AbsoluteFormTargetRejected.bend @@ -1,6 +1,13 @@ # proofs of laws/AbsoluteFormTargetRejected.bend import Base +import ../src/http.bend as Http import ../laws/AbsoluteFormTargetRejected.bend as Laws -def Laws.ask_rejects_absolute_form(): +def Laws.ask_rejects_absolute_form(method, target, ls, body, es, ea): + %es : {Http.ask.origin(method, target, ls, body, + Http.target.form(method, target, _)) + == Http.Bad{"the request-target is not in origin-form"} : Http.Request} + %ea : {Http.ask.origin(method, target, ls, body, + Http.target.asterisk(method, _)) + == Http.Bad{"the request-target is not in origin-form"} : Http.Request} {==} diff --git a/proofs/Base64EmptyIsEmpty.bend b/proofs/Base64EmptyIsEmpty.bend deleted file mode 100644 index 4f4af82..0000000 --- a/proofs/Base64EmptyIsEmpty.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/Base64EmptyIsEmpty.bend -import Base -import ../laws/Base64EmptyIsEmpty.bend as Laws - -def Laws.b64_empty(): - {==} diff --git a/proofs/Base64EncodesByQuantum.bend b/proofs/Base64EncodesByQuantum.bend new file mode 100644 index 0000000..b41bd14 --- /dev/null +++ b/proofs/Base64EncodesByQuantum.bend @@ -0,0 +1,24 @@ +# proofs of laws/Base64EncodesByQuantum.bend +import Base +import ../laws/Base64EncodesByQuantum.bend as Laws + +def Laws.b64_three(_a, _b, _c, _s): + {==} + +def Laws.b64_two(_a, _b): + {==} + +def Laws.b64_one(_a): + {==} + +# a non-empty input starts a quantum, and every quantum writes characters +def Laws.b64_empty(s): + match s: + case SNil{}: + {==} + case SCon{a, SNil{}}: + {==} + case SCon{a, SCon{b, SNil{}}}: + {==} + case SCon{a, SCon{b, SCon{c, t}}}: + {==} diff --git a/proofs/Base64EncodesF.bend b/proofs/Base64EncodesF.bend deleted file mode 100644 index ce77420..0000000 --- a/proofs/Base64EncodesF.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/Base64EncodesF.bend -import Base -import ../laws/Base64EncodesF.bend as Laws - -def Laws.b64_f(): - {==} diff --git a/proofs/Base64EncodesFo.bend b/proofs/Base64EncodesFo.bend deleted file mode 100644 index e47afd2..0000000 --- a/proofs/Base64EncodesFo.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/Base64EncodesFo.bend -import Base -import ../laws/Base64EncodesFo.bend as Laws - -def Laws.b64_fo(): - {==} diff --git a/proofs/Base64EncodesFoo.bend b/proofs/Base64EncodesFoo.bend deleted file mode 100644 index 7861a11..0000000 --- a/proofs/Base64EncodesFoo.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/Base64EncodesFoo.bend -import Base -import ../laws/Base64EncodesFoo.bend as Laws - -def Laws.b64_foo(): - {==} diff --git a/proofs/Base64EncodesUserPass.bend b/proofs/Base64EncodesUserPass.bend deleted file mode 100644 index 4945cc9..0000000 --- a/proofs/Base64EncodesUserPass.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/Base64EncodesUserPass.bend -import Base -import ../laws/Base64EncodesUserPass.bend as Laws - -def Laws.b64_user_pass(): - {==} diff --git a/proofs/BasicIsBase64OfUserPassword.bend b/proofs/BasicIsBase64OfUserPassword.bend index 92df0b4..bf71af7 100644 --- a/proofs/BasicIsBase64OfUserPassword.bend +++ b/proofs/BasicIsBase64OfUserPassword.bend @@ -2,5 +2,5 @@ import Base import ../laws/BasicIsBase64OfUserPassword.bend as Laws -def Laws.basic_user_pass(): +def Laws.basic_user_pass(_user, _password): {==} diff --git a/proofs/BearerTokenAcceptsPlain.bend b/proofs/BearerTokenAcceptsPlain.bend deleted file mode 100644 index 5e576bd..0000000 --- a/proofs/BearerTokenAcceptsPlain.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/BearerTokenAcceptsPlain.bend -import Base -import ../laws/BearerTokenAcceptsPlain.bend as Laws - -def Laws.token_ok_plain(): - {==} diff --git a/proofs/BearerTokenHasNoWhitespace.bend b/proofs/BearerTokenHasNoWhitespace.bend new file mode 100644 index 0000000..b5fa534 --- /dev/null +++ b/proofs/BearerTokenHasNoWhitespace.bend @@ -0,0 +1,49 @@ +# proofs of laws/BearerTokenHasNoWhitespace.bend +import Base +import ../src/http.bend as Http +import ../laws/BearerTokenHasNoWhitespace.bend as Laws +import ./lemmas/BaseEqualities.bend as M1 + +# LAW: a step whose rest rejects rejects +law step_false: + for x: Bool + for r: Bool + for ih: {r == False{} : Bool} + {Http.token.ok.step(x, _u => r) == False{} : Bool} + +# a step whose rest rejects rejects, whatever the head +def step_false(x, _r, ih): + match x: + case True{}: + {==} + case False{}: + ih + +# LAW: a step on a non-whitespace head is its rest +law step_at: + for x: Bool + for r: Bool + for e: {x == False{} : Bool} + {Http.token.ok.step(x, _u => r) == r : Bool} + +# the step on a head that is not whitespace is its rest +def step_at(x, r, e): + match x: + case True{}: + M1.eq.bit.absurd(&2, {Http.token.ok.step(True{}, _u => r) == r : Bool}, + Equal.sym(Bool, True{}, False{}, e)) + case False{}: + {==} + +def Laws.token_ok_space(a, c, b, e): + match a: + case SNil{}: + %Equal.sym(Bool, Char.is_space(c), True{}, e) + : {Http.token.ok.step(_, _u => Http.token.ok(b)) == False{} : Bool} + {==} + case SCon{h, +t}: + step_false(Char.is_space(h), Http.token.ok(t ++ SCon{c, b}), + Laws.token_ok_space(t, c, b, e)) + +def Laws.token_ok_plain(c, t, e): + step_at(Char.is_space(c), Http.token.ok(t), e) diff --git a/proofs/BearerTokenRejectsNewline.bend b/proofs/BearerTokenRejectsNewline.bend deleted file mode 100644 index 74b7efa..0000000 --- a/proofs/BearerTokenRejectsNewline.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/BearerTokenRejectsNewline.bend -import Base -import ../laws/BearerTokenRejectsNewline.bend as Laws - -def Laws.token_ok_newline(): - {==} diff --git a/proofs/BearerTokenRejectsSpace.bend b/proofs/BearerTokenRejectsSpace.bend deleted file mode 100644 index f5e0d78..0000000 --- a/proofs/BearerTokenRejectsSpace.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/BearerTokenRejectsSpace.bend -import Base -import ../laws/BearerTokenRejectsSpace.bend as Laws - -def Laws.token_ok_space(): - {==} diff --git a/proofs/BearerTokenRejectsTab.bend b/proofs/BearerTokenRejectsTab.bend deleted file mode 100644 index fbccdb9..0000000 --- a/proofs/BearerTokenRejectsTab.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/BearerTokenRejectsTab.bend -import Base -import ../laws/BearerTokenRejectsTab.bend as Laws - -def Laws.token_ok_tab(): - {==} diff --git a/proofs/CacheDirectiveNamesIgnoreCase.bend b/proofs/CacheDirectiveNamesIgnoreCase.bend deleted file mode 100644 index 2b7bb0e..0000000 --- a/proofs/CacheDirectiveNamesIgnoreCase.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CacheDirectiveNamesIgnoreCase.bend -import Base -import ../laws/CacheDirectiveNamesIgnoreCase.bend as Laws - -def Laws.cache_directive_case(): - {==} diff --git a/proofs/CacheIgnoresUnknownDirective.bend b/proofs/CacheIgnoresUnknownDirective.bend deleted file mode 100644 index a2e5a33..0000000 --- a/proofs/CacheIgnoresUnknownDirective.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CacheIgnoresUnknownDirective.bend -import Base -import ../laws/CacheIgnoresUnknownDirective.bend as Laws - -def Laws.cache_ignores_s_maxage(): - {==} diff --git a/proofs/CacheMaxAgeIgnoresJunk.bend b/proofs/CacheMaxAgeIgnoresJunk.bend deleted file mode 100644 index 7872dc5..0000000 --- a/proofs/CacheMaxAgeIgnoresJunk.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CacheMaxAgeIgnoresJunk.bend -import Base -import ../laws/CacheMaxAgeIgnoresJunk.bend as Laws - -def Laws.cache_max_age_ignores_junk(): - {==} diff --git a/proofs/CacheReadsKnownDirectives.bend b/proofs/CacheReadsKnownDirectives.bend index b00cc74..684147a 100644 --- a/proofs/CacheReadsKnownDirectives.bend +++ b/proofs/CacheReadsKnownDirectives.bend @@ -1,6 +1,59 @@ # proofs of laws/CacheReadsKnownDirectives.bend import Base +import ../src/http.bend as Http +import ../src/cache.bend as Cache import ../laws/CacheReadsKnownDirectives.bend as Laws -def Laws.cache_directives(): +def Laws.fold_each(_h, _t, _c): + {==} + +def Laws.fold_end(_c): + {==} + +def Laws.one_no_store(c, piece, e1, e2): + %e1 : {Cache.cache.one.dispatch(c, piece, _) == Cache.cache.store(c) : Cache.Cc} + %e2 : {Cache.cache.one.flag(c, _) == Cache.cache.store(c) : Cache.Cc} + {==} + +def Laws.one_no_cache(c, piece, e1, e2): + %e1 : {Cache.cache.one.dispatch(c, piece, _) == Cache.cache.revalidate(c) : Cache.Cc} + %e2 : {Cache.cache.one.flag(c, _) == Cache.cache.revalidate(c) : Cache.Cc} + {==} + +def Laws.one_public(c, piece, e1, e2): + %e1 : {Cache.cache.one.dispatch(c, piece, _) == Cache.cache.pub(c) : Cache.Cc} + %e2 : {Cache.cache.one.flag(c, _) == Cache.cache.pub(c) : Cache.Cc} + {==} + +def Laws.one_private(c, piece, e1, e2): + %e1 : {Cache.cache.one.dispatch(c, piece, _) == Cache.cache.priv(c) : Cache.Cc} + %e2 : {Cache.cache.one.flag(c, _) == Cache.cache.priv(c) : Cache.Cc} + {==} + +def Laws.one_max_age(c, piece, _before, after, _n, e1, e2, e3): + %e1 : {Cache.cache.one.dispatch(c, piece, _) == Cache.cache.age(c, String.trim(after)) : Cache.Cc} + %e2 : {Cache.cache.one.store(c, _, String.trim(after), String.eq(_, "no-store")) + == Cache.cache.age(c, String.trim(after)) : Cache.Cc} + %e3 : {Cache.cache.one.age_ok(c, String.trim(after), _) == Cache.cache.age(c, String.trim(after)) + : Cache.Cc} + {==} + +def Laws.one_max_age_junk(c, piece, _before, after, e1, e2, e3): + %e1 : {Cache.cache.one.dispatch(c, piece, _) == c : Cache.Cc} + %e2 : {Cache.cache.one.store(c, _, String.trim(after), String.eq(_, "no-store")) == c : Cache.Cc} + %e3 : {Cache.cache.one.age_ok(c, String.trim(after), _) == c : Cache.Cc} + {==} + +def Laws.one_unknown(c, piece, before, after, e1, e2, e3, e4, e5, e6): + %e1 : {Cache.cache.one.dispatch(c, piece, _) == c : Cache.Cc} + %e2 : {Cache.cache.one.store(c, String.to_lower(String.trim(before)), String.trim(after), _) + == c : Cache.Cc} + %e3 : {Cache.cache.one.cache(c, String.to_lower(String.trim(before)), String.trim(after), _) + == c : Cache.Cc} + %e4 : {Cache.cache.one.age(c, String.to_lower(String.trim(before)), String.trim(after), _) + == c : Cache.Cc} + %e5 : {Cache.cache.one.public(c, String.to_lower(String.trim(before)), String.trim(after), _) + == c : Cache.Cc} + %e6 : {Cache.cache.one.private(c, String.to_lower(String.trim(before)), String.trim(after), _) + == c : Cache.Cc} {==} diff --git a/proofs/CacheRecordsExpires.bend b/proofs/CacheRecordsExpires.bend index 7c8c191..b16ef75 100644 --- a/proofs/CacheRecordsExpires.bend +++ b/proofs/CacheRecordsExpires.bend @@ -1,6 +1,19 @@ # proofs of laws/CacheRecordsExpires.bend import Base +import ../src/cache.bend as Cache import ../laws/CacheRecordsExpires.bend as Laws -def Laws.cache_note_expires(): +def Laws.cache_note_expires( + _value, + when, + no_store, + no_cache, + public, + private, + max_age, + _expires, + e +): + %e : {Cache.cache.expires(_, when) + == Cache.Cc{no_store, no_cache, public, private, max_age, when} : Cache.Cc} {==} diff --git a/proofs/CacheRecordsMaxAge.bend b/proofs/CacheRecordsMaxAge.bend index bad0e9f..c651f24 100644 --- a/proofs/CacheRecordsMaxAge.bend +++ b/proofs/CacheRecordsMaxAge.bend @@ -1,6 +1,27 @@ # proofs of laws/CacheRecordsMaxAge.bend import Base +import ../src/http.bend as Http +import ../src/cache.bend as Cache import ../laws/CacheRecordsMaxAge.bend as Laws +import ./lemmas/BaseEqualities.bend as M1 -def Laws.cache_max_age_present(): - {==} +# whether a read is some number +def cm.some(m: Maybe<&2, Nat>) -> Bool: + match m: + case None{}: + False{} + case Some{k}: + True{} + +# a recorded argument is not empty, since digits.read of "" is none +def Laws.cache_max_age_present(c, raw, n, e): + match c: + case Cache.Cc{no_store, no_cache, public, private, max_age, expires}: + match raw: + case SNil{}: + M1.eq.bit.absurd(&2, {Cache.cache.max_age(Cache.cache.age(Cache.Cc{no_store, + no_cache, public, private, max_age, expires}, "")) == True{} : Bool}, + Equal.sym(Bool, True{}, False{}, + Equal.cong(Maybe<&2, Nat>, Bool, cm.some, Some{n}, None{}, e))) + case SCon{h, t}: + {==} diff --git a/proofs/CacheRecordsNoCache.bend b/proofs/CacheRecordsNoCache.bend deleted file mode 100644 index 3fea205..0000000 --- a/proofs/CacheRecordsNoCache.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CacheRecordsNoCache.bend -import Base -import ../laws/CacheRecordsNoCache.bend as Laws - -def Laws.cache_no_cache_alone(): - {==} diff --git a/proofs/CacheRecordsPrivate.bend b/proofs/CacheRecordsPrivate.bend deleted file mode 100644 index e3e577b..0000000 --- a/proofs/CacheRecordsPrivate.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CacheRecordsPrivate.bend -import Base -import ../laws/CacheRecordsPrivate.bend as Laws - -def Laws.cache_private_alone(): - {==} diff --git a/proofs/ChunkDataUnchanged.bend b/proofs/ChunkDataUnchanged.bend index aa5c7b8..87814b7 100644 --- a/proofs/ChunkDataUnchanged.bend +++ b/proofs/ChunkDataUnchanged.bend @@ -7,9 +7,11 @@ import ./lemmas/DropNothing.bend as M1 import ./lemmas/OctetTakeDrop.bend as M2 # what follows |b| + k characters of b ++ r is what follows k of r -def drop_prefix(b: String, r: String, k: Nat) - -> {String.drop(String.append(b, r), Nat.add(String.length(b), k)) - == String.drop(r, k) : String}: +def drop_prefix( + b: String, + r: String, + k: Nat +) -> {String.drop(String.append(b, r), Nat.add(String.length(b), k)) == String.drop(r, k) : String}: match b: case SNil{}: {==} diff --git a/proofs/ChunkSizeHexIgnoresCase.bend b/proofs/ChunkSizeHexIgnoresCase.bend index 9481136..e615e1d 100644 --- a/proofs/ChunkSizeHexIgnoresCase.bend +++ b/proofs/ChunkSizeHexIgnoresCase.bend @@ -2,5 +2,20 @@ import Base import ../laws/ChunkSizeHexIgnoresCase.bend as Laws -def Laws.hexlen_alpha(): +def Laws.hex_a(_acc, _t): + {==} + +def Laws.hex_b(_acc, _t): + {==} + +def Laws.hex_c(_acc, _t): + {==} + +def Laws.hex_d(_acc, _t): + {==} + +def Laws.hex_e(_acc, _t): + {==} + +def Laws.hex_f(_acc, _t): {==} diff --git a/proofs/ChunkSizeReadsHexSkipsExtension.bend b/proofs/ChunkSizeReadsHexSkipsExtension.bend deleted file mode 100644 index fc66697..0000000 --- a/proofs/ChunkSizeReadsHexSkipsExtension.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/ChunkSizeReadsHexSkipsExtension.bend -import Base -import ../laws/ChunkSizeReadsHexSkipsExtension.bend as Laws - -def Laws.hexlen_extension_and_case(): - {==} diff --git a/proofs/ChunkedBodyJoinsChunks.bend b/proofs/ChunkedBodyJoinsChunks.bend index 9625d9a..f0fbbf7 100644 --- a/proofs/ChunkedBodyJoinsChunks.bend +++ b/proofs/ChunkedBodyJoinsChunks.bend @@ -1,6 +1,9 @@ # proofs of laws/ChunkedBodyJoinsChunks.bend import Base +import ../src/http.bend as Http import ../laws/ChunkedBodyJoinsChunks.bend as Laws -def Laws.parse_chunked_body(): +def Laws.chunked_joins(st, hs, body, e): + %e : {Http.parse.chunked(st, hs, body, _) == Http.Reply{st, hs, Http.dechunk(body)} + : Http.Reply} {==} diff --git a/proofs/ChunkedNameIgnoresCase.bend b/proofs/ChunkedNameIgnoresCase.bend deleted file mode 100644 index e32543c..0000000 --- a/proofs/ChunkedNameIgnoresCase.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/ChunkedNameIgnoresCase.bend -import Base -import ../laws/ChunkedNameIgnoresCase.bend as Laws - -def Laws.parse_chunked_ignores_case(): - {==} diff --git a/proofs/ChunksStopWithoutFuel.bend b/proofs/ChunksStopWithoutFuel.bend index ccaa672..86a2e5e 100644 --- a/proofs/ChunksStopWithoutFuel.bend +++ b/proofs/ChunksStopWithoutFuel.bend @@ -2,5 +2,12 @@ import Base import ../laws/ChunksStopWithoutFuel.bend as Laws -def Laws.chunks_empty_fuel(): +def Laws.chunks_no_fuel(_c): {==} + +def Laws.chunks_no_cut(f): + match f: + case 0n: + {==} + case 1n+p: + {==} diff --git a/proofs/ContentLengthFramesBody.bend b/proofs/ContentLengthFramesBody.bend index 11c8287..9998bfe 100644 --- a/proofs/ContentLengthFramesBody.bend +++ b/proofs/ContentLengthFramesBody.bend @@ -13,9 +13,10 @@ def Laws.clen_short(st, hs, n, body, e): {==} # b ++ r is never shorter than b -def lt_prefix(b: String, r: String) - -> {Nat.is_lt(String.length(String.append(b, r)), String.length(b)) - == False{} : Bool}: +def lt_prefix( + b: String, + r: String +) -> {Nat.is_lt(String.length(String.append(b, r)), String.length(b)) == False{} : Bool}: match b: case SNil{}: match r: diff --git a/proofs/ContentLengthReadsDecimal.bend b/proofs/ContentLengthReadsDecimal.bend index 35933b3..b4a019a 100644 --- a/proofs/ContentLengthReadsDecimal.bend +++ b/proofs/ContentLengthReadsDecimal.bend @@ -1,6 +1,14 @@ # proofs of laws/ContentLengthReadsDecimal.bend import Base +import ../src/http.bend as Http import ../laws/ContentLengthReadsDecimal.bend as Laws -def Laws.digits_read_decimal(): +def Laws.digits_step(c, t, acc, k, e): + %e : {Http.digits.step(_, _u => Http.digits.go(t, Nat.add(Nat.mul(acc, 10n), + U32.to_nat(Http.digits.val(c))), k)) + == Http.digits.go(t, Nat.add(Nat.mul(acc, 10n), U32.to_nat(Http.digits.val(c))), k) + : Maybe<&2, Nat>} + {==} + +def Laws.digits_end(_acc, _k): {==} diff --git a/proofs/ContentLengthRejectsJunk.bend b/proofs/ContentLengthRejectsJunk.bend index b08f062..e8fec6e 100644 --- a/proofs/ContentLengthRejectsJunk.bend +++ b/proofs/ContentLengthRejectsJunk.bend @@ -1,6 +1,9 @@ # proofs of laws/ContentLengthRejectsJunk.bend import Base +import ../src/http.bend as Http import ../laws/ContentLengthRejectsJunk.bend as Laws -def Laws.digits_read_rejects_junk(): +def Laws.digits_junk(c, t, acc, k, e): + %e : {Http.digits.step(_, _u => Http.digits.go(t, Nat.add(Nat.mul(acc, 10n), + U32.to_nat(Http.digits.val(c))), k)) == None{} : Maybe<&2, Nat>} {==} diff --git a/proofs/ContentLengthTakesPrefix.bend b/proofs/ContentLengthTakesPrefix.bend deleted file mode 100644 index 92bffd2..0000000 --- a/proofs/ContentLengthTakesPrefix.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/ContentLengthTakesPrefix.bend -import Base -import ../laws/ContentLengthTakesPrefix.bend as Laws - -def Laws.parse_clen_takes_prefix(): - {==} diff --git a/proofs/ContinuationLineRejected.bend b/proofs/ContinuationLineRejected.bend index b8bef6a..f046a3c 100644 --- a/proofs/ContinuationLineRejected.bend +++ b/proofs/ContinuationLineRejected.bend @@ -1,6 +1,8 @@ # proofs of laws/ContinuationLineRejected.bend import Base +import ../src/http.bend as Http import ../laws/ContinuationLineRejected.bend as Laws -def Laws.head_line_rejects_continuation(): +def Laws.head_line_rejects_continuation(_h, e): + %e : {Http.head.from_cut(_) == None{} : Maybe<&2, Http.Header>} {==} diff --git a/proofs/CookieAliveUnderMaxAge.bend b/proofs/CookieAliveUnderMaxAge.bend index 30a0a00..c943789 100644 --- a/proofs/CookieAliveUnderMaxAge.bend +++ b/proofs/CookieAliveUnderMaxAge.bend @@ -1,6 +1,12 @@ # proofs of laws/CookieAliveUnderMaxAge.bend import Base +import ../src/cookie.bend as Cookie import ../laws/CookieAliveUnderMaxAge.bend as Laws -def Laws.cookie_max_age_open(): +def Laws.cookie_alive_max_age(_max_age, n, age, e): + %e : {Cookie.cookie.alive.of(age, _) == Nat.is_lt(age, n) : Bool} + {==} + +def Laws.cookie_alive_session(_max_age, age, e): + %e : {Cookie.cookie.alive.of(age, _) == True{} : Bool} {==} diff --git a/proofs/CookieAttributesJoinWithSemicolons.bend b/proofs/CookieAttributesJoinWithSemicolons.bend index 97d2d35..92f2ea6 100644 --- a/proofs/CookieAttributesJoinWithSemicolons.bend +++ b/proofs/CookieAttributesJoinWithSemicolons.bend @@ -1,6 +1,27 @@ # proofs of laws/CookieAttributesJoinWithSemicolons.bend import Base +import ../src/cookie.bend as Cookie import ../laws/CookieAttributesJoinWithSemicolons.bend as Laws -def Laws.cookie_line_attributes(): +def Laws.cookie_line(_n, _v, _x, _m, _d, _p, _s, _h, _ss, _ho): + {==} + +def Laws.cookie_opt_empty(prefix, value, e): + %e : {Cookie.cookie.opt.of(prefix, value, _) == "" : String} + {==} + +def Laws.cookie_opt_set(prefix, value, e): + %e : {Cookie.cookie.opt.of(prefix, value, _) == prefix ++ value : String} + {==} + +def Laws.cookie_mark_on(_label): + {==} + +def Laws.cookie_mark_off(_label): + {==} + +def Laws.cookie_domain_text_host_only(_domain): + {==} + +def Laws.cookie_domain_text_set(_domain): {==} diff --git a/proofs/CookieDefaultPathFallsBackToRoot.bend b/proofs/CookieDefaultPathFallsBackToRoot.bend index 61299b3..2c61f61 100644 --- a/proofs/CookieDefaultPathFallsBackToRoot.bend +++ b/proofs/CookieDefaultPathFallsBackToRoot.bend @@ -1,6 +1,8 @@ # proofs of laws/CookieDefaultPathFallsBackToRoot.bend import Base +import ../src/cookie.bend as Cookie import ../laws/CookieDefaultPathFallsBackToRoot.bend as Laws -def Laws.cookie_default_path_root(): +def Laws.cookie_default_path_root(p, e): + %e : {Cookie.cookie.default_of(p, _) == "/" : String} {==} diff --git a/proofs/CookieDefaultPathIsDirectory.bend b/proofs/CookieDefaultPathIsDirectory.bend index 7cc3daf..d9f78a4 100644 --- a/proofs/CookieDefaultPathIsDirectory.bend +++ b/proofs/CookieDefaultPathIsDirectory.bend @@ -1,6 +1,11 @@ # proofs of laws/CookieDefaultPathIsDirectory.bend import Base +import ../src/cookie.bend as Cookie import ../laws/CookieDefaultPathIsDirectory.bend as Laws -def Laws.cookie_default_path_dir(): +def Laws.cookie_default_path_dir(p, e): + %e : {Cookie.cookie.default_of(p, _) == Cookie.cookie.before(p) : String} + {==} + +def Laws.cookie_before(_p): {==} diff --git a/proofs/CookieDefaultPathNeedsTwoSlashes.bend b/proofs/CookieDefaultPathNeedsTwoSlashes.bend deleted file mode 100644 index b123155..0000000 --- a/proofs/CookieDefaultPathNeedsTwoSlashes.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CookieDefaultPathNeedsTwoSlashes.bend -import Base -import ../laws/CookieDefaultPathNeedsTwoSlashes.bend as Laws - -def Laws.cookie_default_path_one_slash(): - {==} diff --git a/proofs/CookieDefaultPathOmitsTrailingSlash.bend b/proofs/CookieDefaultPathOmitsTrailingSlash.bend deleted file mode 100644 index 50c45bf..0000000 --- a/proofs/CookieDefaultPathOmitsTrailingSlash.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CookieDefaultPathOmitsTrailingSlash.bend -import Base -import ../laws/CookieDefaultPathOmitsTrailingSlash.bend as Laws - -def Laws.cookie_default_path_trailing(): - {==} diff --git a/proofs/CookieDomainLowercased.bend b/proofs/CookieDomainLowercased.bend index 94feed2..416dabb 100644 --- a/proofs/CookieDomainLowercased.bend +++ b/proofs/CookieDomainLowercased.bend @@ -2,5 +2,8 @@ import Base import ../laws/CookieDomainLowercased.bend as Laws -def Laws.cookie_domain_lowercased(): +def Laws.cookie_named_domain(_c, _value): + {==} + +def Laws.cookie_domain_sets(_n, _v, _x, _m, _d, _p, _s, _h, _ss, _ho, _host): {==} diff --git a/proofs/CookieDomainMatchesDotSuffix.bend b/proofs/CookieDomainMatchesDotSuffix.bend index 7ee049d..a7ead0f 100644 --- a/proofs/CookieDomainMatchesDotSuffix.bend +++ b/proofs/CookieDomainMatchesDotSuffix.bend @@ -1,6 +1,13 @@ # proofs of laws/CookieDomainMatchesDotSuffix.bend import Base +import ../src/cookie.bend as Cookie import ../laws/CookieDomainMatchesDotSuffix.bend as Laws -def Laws.cookie_domain_suffix(): +def Laws.cookie_domain_suffix(host, domain, e1, e2): + %e1 : {Cookie.cookie.domain_eq(String.to_lower(host), String.to_lower(domain), _) + == String.ends_with(String.to_lower(host), "." ++ String.to_lower(domain)) + : Bool} + %e2 : {Cookie.cookie.domain_suffix(String.to_lower(host), String.to_lower(domain), _) + == String.ends_with(String.to_lower(host), "." ++ String.to_lower(domain)) + : Bool} {==} diff --git a/proofs/CookieDomainNeedsDotBeforeSuffix.bend b/proofs/CookieDomainNeedsDotBeforeSuffix.bend deleted file mode 100644 index e0e10df..0000000 --- a/proofs/CookieDomainNeedsDotBeforeSuffix.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CookieDomainNeedsDotBeforeSuffix.bend -import Base -import ../laws/CookieDomainNeedsDotBeforeSuffix.bend as Laws - -def Laws.cookie_domain_not_suffix(): - {==} diff --git a/proofs/CookieHostOnlyNotSentElsewhere.bend b/proofs/CookieHostOnlyNotSentElsewhere.bend index 7d8be16..3ec387b 100644 --- a/proofs/CookieHostOnlyNotSentElsewhere.bend +++ b/proofs/CookieHostOnlyNotSentElsewhere.bend @@ -1,6 +1,23 @@ # proofs of laws/CookieHostOnlyNotSentElsewhere.bend import Base +import ../src/cookie.bend as Cookie import ../laws/CookieHostOnlyNotSentElsewhere.bend as Laws -def Laws.cookie_send_other_host(): +def Laws.cookie_send_domain_miss( + _host, + req, + tls, + _n, + _v, + _x, + _m, + _domain, + path, + secure, + _h, + _ss, + _host_only, + e +): + %e : {Cookie.cookie.send.domain(req, tls, secure, path, _) == False{} : Bool} {==} diff --git a/proofs/CookieHostOnlySentToHost.bend b/proofs/CookieHostOnlySentToHost.bend index 46d35cd..88bbdd8 100644 --- a/proofs/CookieHostOnlySentToHost.bend +++ b/proofs/CookieHostOnlySentToHost.bend @@ -1,6 +1,31 @@ # proofs of laws/CookieHostOnlySentToHost.bend import Base +import ../src/cookie.bend as Cookie import ../laws/CookieHostOnlySentToHost.bend as Laws -def Laws.cookie_send_host_only(): +def Laws.cookie_send_domain_hit( + _host, + req, + tls, + _n, + _v, + _x, + _m, + _domain, + path, + secure, + _h, + _ss, + _host_only, + e +): + %e : {Cookie.cookie.send.domain(req, tls, secure, path, _) + == Cookie.cookie.send.path(tls, secure, Cookie.cookie.path_ok(req, path)) + : Bool} + {==} + +def Laws.cookie_send_path_miss(_tls, _secure): + {==} + +def Laws.cookie_send_path_hit(_tls, _secure): {==} diff --git a/proofs/CookieHostOnlyStoresHost.bend b/proofs/CookieHostOnlyStoresHost.bend index 373ac1a..44c9a59 100644 --- a/proofs/CookieHostOnlyStoresHost.bend +++ b/proofs/CookieHostOnlyStoresHost.bend @@ -1,6 +1,22 @@ # proofs of laws/CookieHostOnlyStoresHost.bend import Base +import ../src/cookie.bend as Cookie import ../laws/CookieHostOnlyStoresHost.bend as Laws -def Laws.cookie_receive_host_only(): +def Laws.cookie_receive(_n, _v, _x, _m, _d, _p, _s, _h, _ss, _ho, _host, _req): + {==} + +def Laws.cookie_fill_domain_host_only(_domain, _host): + {==} + +def Laws.cookie_fill_domain_set(_domain, _host): + {==} + +def Laws.cookie_fill_path_empty(path, req, e): + %e : {Cookie.cookie.fill_path.of(path, req, _) == Cookie.cookie.default_path(req) + : String} + {==} + +def Laws.cookie_fill_path_set(path, req, e): + %e : {Cookie.cookie.fill_path.of(path, req, _) == path : String} {==} diff --git a/proofs/CookieIdenticalPathsMatch.bend b/proofs/CookieIdenticalPathsMatch.bend index f02889a..17adddc 100644 --- a/proofs/CookieIdenticalPathsMatch.bend +++ b/proofs/CookieIdenticalPathsMatch.bend @@ -1,6 +1,12 @@ # proofs of laws/CookieIdenticalPathsMatch.bend import Base +import ../src/cookie.bend as Cookie +import ./lemmas/CookieStrings.bend as CS import ../laws/CookieIdenticalPathsMatch.bend as Laws -def Laws.cookie_path_identical(): +def Laws.cookie_path_identical(p): + %Equal.sym(Bool, String.starts_with(p, p), True{}, CS.starts_self(p)) + : {Cookie.cookie.path_prefix(p, p, _) == True{} : Bool} + %Equal.sym(Cmp, String.order(p, p), EQ{}, CS.order_self(p)) + : {Cookie.cookie.path_rest(p, p, Cmp.is_eq(_)) == True{} : Bool} {==} diff --git a/proofs/CookieInsecureSentOnCleartext.bend b/proofs/CookieInsecureSentOnCleartext.bend index e8165ed..b340751 100644 --- a/proofs/CookieInsecureSentOnCleartext.bend +++ b/proofs/CookieInsecureSentOnCleartext.bend @@ -2,5 +2,5 @@ import Base import ../laws/CookieInsecureSentOnCleartext.bend as Laws -def Laws.cookie_insecure_on_tcp(): +def Laws.cookie_insecure_any(_tls): {==} diff --git a/proofs/CookieIpHostMatchesExactly.bend b/proofs/CookieIpHostMatchesExactly.bend index 4a6b21f..4282b9e 100644 --- a/proofs/CookieIpHostMatchesExactly.bend +++ b/proofs/CookieIpHostMatchesExactly.bend @@ -1,6 +1,12 @@ # proofs of laws/CookieIpHostMatchesExactly.bend import Base +import ../src/cookie.bend as Cookie import ../laws/CookieIpHostMatchesExactly.bend as Laws -def Laws.cookie_domain_ip_exact(): +def Laws.cookie_domain_exact(host, domain, e): + %e : {Cookie.cookie.domain_eq(String.to_lower(host), String.to_lower(domain), _) + == True{} : Bool} + {==} + +def Laws.cookie_domain_host_only(_host, _domain): {==} diff --git a/proofs/CookieIpHostNoSuffixMatch.bend b/proofs/CookieIpHostNoSuffixMatch.bend index 58026b8..b405cd4 100644 --- a/proofs/CookieIpHostNoSuffixMatch.bend +++ b/proofs/CookieIpHostNoSuffixMatch.bend @@ -1,6 +1,11 @@ # proofs of laws/CookieIpHostNoSuffixMatch.bend import Base +import ../src/cookie.bend as Cookie import ../laws/CookieIpHostNoSuffixMatch.bend as Laws -def Laws.cookie_domain_ip_suffix(): +def Laws.cookie_domain_ip(host, domain, e1, e2): + %e1 : {Cookie.cookie.domain_eq(String.to_lower(host), String.to_lower(domain), _) + == False{} : Bool} + %e2 : {Cookie.cookie.domain_suffix(String.to_lower(host), String.to_lower(domain), _) + == False{} : Bool} {==} diff --git a/proofs/CookieLongerPathFails.bend b/proofs/CookieLongerPathFails.bend index 8cab393..5c5fa45 100644 --- a/proofs/CookieLongerPathFails.bend +++ b/proofs/CookieLongerPathFails.bend @@ -1,6 +1,8 @@ # proofs of laws/CookieLongerPathFails.bend import Base +import ../src/cookie.bend as Cookie import ../laws/CookieLongerPathFails.bend as Laws -def Laws.cookie_path_longer_cookie(): +def Laws.cookie_path_not_prefix(req, cpath, e): + %e : {Cookie.cookie.path_prefix(req, cpath, _) == False{} : Bool} {==} diff --git a/proofs/CookieMaxAgeIgnoresJunk.bend b/proofs/CookieMaxAgeIgnoresJunk.bend index 19584b6..3bd105f 100644 --- a/proofs/CookieMaxAgeIgnoresJunk.bend +++ b/proofs/CookieMaxAgeIgnoresJunk.bend @@ -2,5 +2,11 @@ import Base import ../laws/CookieMaxAgeIgnoresJunk.bend as Laws -def Laws.cookie_max_age_ignores_junk(): +def Laws.cookie_named_max_age(_c, _value): + {==} + +def Laws.cookie_age_junk(_c, _raw): + {==} + +def Laws.cookie_age_digits(_c, _raw, _n): {==} diff --git a/proofs/CookieMaxAgeOneStaleAtOne.bend b/proofs/CookieMaxAgeOneStaleAtOne.bend deleted file mode 100644 index 6a46d11..0000000 --- a/proofs/CookieMaxAgeOneStaleAtOne.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CookieMaxAgeOneStaleAtOne.bend -import Base -import ../laws/CookieMaxAgeOneStaleAtOne.bend as Laws - -def Laws.cookie_max_age_one(): - {==} diff --git a/proofs/CookieMaxAgeZeroNotAlive.bend b/proofs/CookieMaxAgeZeroNotAlive.bend deleted file mode 100644 index d61f131..0000000 --- a/proofs/CookieMaxAgeZeroNotAlive.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CookieMaxAgeZeroNotAlive.bend -import Base -import ../laws/CookieMaxAgeZeroNotAlive.bend as Laws - -def Laws.cookie_max_age_zero(): - {==} diff --git a/proofs/CookieNameIsNotIpv4.bend b/proofs/CookieNameIsNotIpv4.bend index cec2688..1daa43a 100644 --- a/proofs/CookieNameIsNotIpv4.bend +++ b/proofs/CookieNameIsNotIpv4.bend @@ -1,6 +1,15 @@ # proofs of laws/CookieNameIsNotIpv4.bend import Base +import ../src/cookie.bend as Cookie import ../laws/CookieNameIsNotIpv4.bend as Laws -def Laws.cookie_ipv4_name(): - {==} +def Laws.cookie_ipv4_other(h, t, seen, e1, e2): + match h: + case Chr{+x}: + %e1 : {Cookie.cookie.ipv4.step(_, Bool.and(U32.is_ge(x, 48), U32.is_le(x, 57)), + _u => Cookie.cookie.ipv4.go(t, True{}), _d => Cookie.cookie.ipv4.go(t, seen)) + == False{} : Bool} + %e2 : {Cookie.cookie.ipv4.step(False{}, _, + _u => Cookie.cookie.ipv4.go(t, True{}), _d => Cookie.cookie.ipv4.go(t, seen)) + == False{} : Bool} + {==} diff --git a/proofs/CookieNoDomainNotSentElsewhere.bend b/proofs/CookieNoDomainNotSentElsewhere.bend deleted file mode 100644 index 65be8d4..0000000 --- a/proofs/CookieNoDomainNotSentElsewhere.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CookieNoDomainNotSentElsewhere.bend -import Base -import ../laws/CookieNoDomainNotSentElsewhere.bend as Laws - -def Laws.cookie_send_unset_domain(): - {==} diff --git a/proofs/CookiePathMatchesSlashPrefix.bend b/proofs/CookiePathMatchesSlashPrefix.bend index 4b1dfc6..df559e6 100644 --- a/proofs/CookiePathMatchesSlashPrefix.bend +++ b/proofs/CookiePathMatchesSlashPrefix.bend @@ -1,6 +1,35 @@ # proofs of laws/CookiePathMatchesSlashPrefix.bend import Base +import ../src/cookie.bend as Cookie import ../laws/CookiePathMatchesSlashPrefix.bend as Laws -def Laws.cookie_path_prefix(): - {==} +# the third rule whatever the other tests give +def boundary.slash( + +req: String, + +cpath: String, + slash: Bool, + e2: {True{} == String.starts_with(String.drop(req, String.length(cpath)), "/") : Bool} +) -> {Cookie.cookie.path_slash(req, cpath, slash) == True{} : Bool}: + match slash: + case True{}: + {==} + case False{}: + Equal.sym(Bool, True{}, + String.starts_with(String.drop(req, String.length(cpath)), "/"), e2) + +# the third rule whatever the identity test gives +def boundary.rest( + +req: String, + +cpath: String, + same: Bool, + e2: {True{} == String.starts_with(String.drop(req, String.length(cpath)), "/") : Bool} +) -> {Cookie.cookie.path_rest(req, cpath, same) == True{} : Bool}: + match same: + case True{}: + {==} + case False{}: + boundary.slash(req, cpath, String.ends_with(cpath, "/"), e2) + +def Laws.cookie_path_prefix(req, cpath, e1, e2): + %e1 : {Cookie.cookie.path_prefix(req, cpath, _) == True{} : Bool} + boundary.rest(req, cpath, String.eq(req, cpath), e2) diff --git a/proofs/CookiePathNeedsSegmentBoundary.bend b/proofs/CookiePathNeedsSegmentBoundary.bend index 6831334..58fd657 100644 --- a/proofs/CookiePathNeedsSegmentBoundary.bend +++ b/proofs/CookiePathNeedsSegmentBoundary.bend @@ -1,6 +1,11 @@ # proofs of laws/CookiePathNeedsSegmentBoundary.bend import Base +import ../src/cookie.bend as Cookie import ../laws/CookiePathNeedsSegmentBoundary.bend as Laws -def Laws.cookie_path_not_prefix(): - {==} +def Laws.cookie_path_not_boundary(req, cpath, e1, e2, e3, e4): + %e1 : {Cookie.cookie.path_prefix(req, cpath, _) == False{} : Bool} + %e2 : {Cookie.cookie.path_rest(req, cpath, _) == False{} : Bool} + %e3 : {Cookie.cookie.path_slash(req, cpath, _) == False{} : Bool} + Equal.sym(Bool, False{}, + String.starts_with(String.drop(req, String.length(cpath)), "/"), e4) diff --git a/proofs/CookieRecognizesIpv4Literal.bend b/proofs/CookieRecognizesIpv4Literal.bend index d49acfc..ecbb167 100644 --- a/proofs/CookieRecognizesIpv4Literal.bend +++ b/proofs/CookieRecognizesIpv4Literal.bend @@ -1,6 +1,24 @@ # proofs of laws/CookieRecognizesIpv4Literal.bend import Base +import ../src/cookie.bend as Cookie import ../laws/CookieRecognizesIpv4Literal.bend as Laws -def Laws.cookie_ipv4_literal(): +def Laws.cookie_ipv4(_host): {==} + +def Laws.cookie_ipv4_end(_seen): + {==} + +def Laws.cookie_ipv4_dot(_t, _seen): + {==} + +def Laws.cookie_ipv4_digit(h, t, seen, e1, e2): + match h: + case Chr{+x}: + %e1 : {Cookie.cookie.ipv4.step(_, Bool.and(U32.is_ge(x, 48), U32.is_le(x, 57)), + _u => Cookie.cookie.ipv4.go(t, True{}), _d => Cookie.cookie.ipv4.go(t, seen)) + == Cookie.cookie.ipv4.go(t, seen) : Bool} + %e2 : {Cookie.cookie.ipv4.step(False{}, _, + _u => Cookie.cookie.ipv4.go(t, True{}), _d => Cookie.cookie.ipv4.go(t, seen)) + == Cookie.cookie.ipv4.go(t, seen) : Bool} + {==} diff --git a/proofs/CookieRejectsEmptyName.bend b/proofs/CookieRejectsEmptyName.bend index 9081dbe..35110e4 100644 --- a/proofs/CookieRejectsEmptyName.bend +++ b/proofs/CookieRejectsEmptyName.bend @@ -2,5 +2,8 @@ import Base import ../laws/CookieRejectsEmptyName.bend as Laws -def Laws.cookie_rejects_empty_name(): +def Laws.cookie_from_no_equals(_pair, _attrs): + {==} + +def Laws.cookie_from_empty_name(_name, _value, _attrs): {==} diff --git a/proofs/CookieRequestJoinsPairs.bend b/proofs/CookieRequestJoinsPairs.bend index 4cb6429..bdd05aa 100644 --- a/proofs/CookieRequestJoinsPairs.bend +++ b/proofs/CookieRequestJoinsPairs.bend @@ -1,6 +1,21 @@ # proofs of laws/CookieRequestJoinsPairs.bend import Base +import ../src/cookie.bend as Cookie import ../laws/CookieRequestJoinsPairs.bend as Laws -def Laws.cookie_request_joins(): +def Laws.cookie_join(_cs): + {==} + +def Laws.cookie_pairs_nil(_cs, e): + %e : {Cookie.cookie.pairs(_) == [] : List<&2, String>} + {==} + +def Laws.cookie_pairs_kept(name, value, _x, _m, _d, _p, _s, _h, _ss, _ho, t, e): + %e : {Cookie.cookie.pairs.keep(name, value, _, _u => Cookie.cookie.pairs(t)) + == (name ++ "=" ++ value) <> Cookie.cookie.pairs(t) : List<&2, String>} + {==} + +def Laws.cookie_pairs_dropped(name, value, _x, _m, _d, _p, _s, _h, _ss, _ho, t, e): + %e : {Cookie.cookie.pairs.keep(name, value, _, _u => Cookie.cookie.pairs(t)) + == Cookie.cookie.pairs(t) : List<&2, String>} {==} diff --git a/proofs/CookieRootPathMatchesLonger.bend b/proofs/CookieRootPathMatchesLonger.bend deleted file mode 100644 index 930535e..0000000 --- a/proofs/CookieRootPathMatchesLonger.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CookieRootPathMatchesLonger.bend -import Base -import ../laws/CookieRootPathMatchesLonger.bend as Laws - -def Laws.cookie_path_root(): - {==} diff --git a/proofs/CookieSameSiteFoldsCase.bend b/proofs/CookieSameSiteFoldsCase.bend index 073c130..73c45a7 100644 --- a/proofs/CookieSameSiteFoldsCase.bend +++ b/proofs/CookieSameSiteFoldsCase.bend @@ -1,6 +1,28 @@ # proofs of laws/CookieSameSiteFoldsCase.bend import Base +import ../src/cookie.bend as Cookie import ../laws/CookieSameSiteFoldsCase.bend as Laws -def Laws.cookie_samesite_strict(): +def Laws.cookie_named_samesite(_c, _value): + {==} + +def Laws.cookie_site_lax(raw, e): + %e : {Cookie.cookie.site.lax(String.to_lower(raw), _) == "Lax" : String} + {==} + +def Laws.cookie_site_strict(raw, e1, e2): + %e1 : {Cookie.cookie.site.lax(String.to_lower(raw), _) == "Strict" : String} + %e2 : {Cookie.cookie.site.strict(String.to_lower(raw), _) == "Strict" : String} + {==} + +def Laws.cookie_site_none(raw, e1, e2, e3): + %e1 : {Cookie.cookie.site.lax(String.to_lower(raw), _) == "None" : String} + %e2 : {Cookie.cookie.site.strict(String.to_lower(raw), _) == "None" : String} + %e3 : {Cookie.cookie.site.none(String.to_lower(raw), _) == "None" : String} + {==} + +def Laws.cookie_site_unknown(raw, e1, e2, e3): + %e1 : {Cookie.cookie.site.lax(String.to_lower(raw), _) == "" : String} + %e2 : {Cookie.cookie.site.strict(String.to_lower(raw), _) == "" : String} + %e3 : {Cookie.cookie.site.none(String.to_lower(raw), _) == "" : String} {==} diff --git a/proofs/CookieSameSiteNoneCanonical.bend b/proofs/CookieSameSiteNoneCanonical.bend deleted file mode 100644 index dd2cb96..0000000 --- a/proofs/CookieSameSiteNoneCanonical.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CookieSameSiteNoneCanonical.bend -import Base -import ../laws/CookieSameSiteNoneCanonical.bend as Laws - -def Laws.cookie_samesite_none(): - {==} diff --git a/proofs/CookieSecureNeedsTls.bend b/proofs/CookieSecureNeedsTls.bend index 14560cc..922d1d9 100644 --- a/proofs/CookieSecureNeedsTls.bend +++ b/proofs/CookieSecureNeedsTls.bend @@ -2,5 +2,5 @@ import Base import ../laws/CookieSecureNeedsTls.bend as Laws -def Laws.cookie_secure_needs_tls(): +def Laws.cookie_secure_tls(_tls): {==} diff --git a/proofs/CookieSecureSentOnTls.bend b/proofs/CookieSecureSentOnTls.bend deleted file mode 100644 index 6f275d5..0000000 --- a/proofs/CookieSecureSentOnTls.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CookieSecureSentOnTls.bend -import Base -import ../laws/CookieSecureSentOnTls.bend as Laws - -def Laws.cookie_secure_on_tls(): - {==} diff --git a/proofs/CookieSessionStaysAlive.bend b/proofs/CookieSessionStaysAlive.bend deleted file mode 100644 index 216e09a..0000000 --- a/proofs/CookieSessionStaysAlive.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CookieSessionStaysAlive.bend -import Base -import ../laws/CookieSessionStaysAlive.bend as Laws - -def Laws.cookie_session_alive(): - {==} diff --git a/proofs/CookieSlashEndedPathIsPrefix.bend b/proofs/CookieSlashEndedPathIsPrefix.bend index dc483cb..059f0c5 100644 --- a/proofs/CookieSlashEndedPathIsPrefix.bend +++ b/proofs/CookieSlashEndedPathIsPrefix.bend @@ -1,6 +1,22 @@ # proofs of laws/CookieSlashEndedPathIsPrefix.bend import Base +import ../src/cookie.bend as Cookie import ../laws/CookieSlashEndedPathIsPrefix.bend as Laws -def Laws.cookie_path_slash_prefix(): - {==} +# the second rule whatever the identity test gives +def slash.rest( + +req: String, + +cpath: String, + same: Bool, + e2: {True{} == String.ends_with(cpath, "/") : Bool} +) -> {Cookie.cookie.path_rest(req, cpath, same) == True{} : Bool}: + match same: + case True{}: + {==} + case False{}: + %e2 : {Cookie.cookie.path_slash(req, cpath, _) == True{} : Bool} + {==} + +def Laws.cookie_path_slash_prefix(req, cpath, e1, e2): + %e1 : {Cookie.cookie.path_prefix(req, cpath, _) == True{} : Bool} + slash.rest(req, cpath, String.eq(req, cpath), e2) diff --git a/proofs/CookieUnknownSameSiteDropped.bend b/proofs/CookieUnknownSameSiteDropped.bend deleted file mode 100644 index 8e5896e..0000000 --- a/proofs/CookieUnknownSameSiteDropped.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CookieUnknownSameSiteDropped.bend -import Base -import ../laws/CookieUnknownSameSiteDropped.bend as Laws - -def Laws.cookie_samesite_unknown(): - {==} diff --git a/proofs/CorsAllowListReflectsOrigin.bend b/proofs/CorsAllowListReflectsOrigin.bend index e347a09..2cbebe1 100644 --- a/proofs/CorsAllowListReflectsOrigin.bend +++ b/proofs/CorsAllowListReflectsOrigin.bend @@ -1,6 +1,11 @@ # proofs of laws/CorsAllowListReflectsOrigin.bend import Base +import ../src/cors.bend as Cors import ../laws/CorsAllowListReflectsOrigin.bend as Laws -def Laws.cors_explicit_origin(): +def Laws.cors_explicit_origin(os, origin, e1, e2): + %e1 : {Cors.cors.acao.ok(os, False{}, origin, Bool.or(_, Cors.cors.hit(origin, os))) + == origin : String} + %e2 : {Cors.cors.acao.ok(os, False{}, origin, _) == origin : String} + %e1 : {Cors.cors.acao.star(origin, _) == origin : String} {==} diff --git a/proofs/CorsAllowedPreflightIs200.bend b/proofs/CorsAllowedPreflightIs200.bend index 5af59e9..3ac9415 100644 --- a/proofs/CorsAllowedPreflightIs200.bend +++ b/proofs/CorsAllowedPreflightIs200.bend @@ -1,6 +1,30 @@ # proofs of laws/CorsAllowedPreflightIs200.bend import Base +import ../src/http.bend as Http +import ../src/cors.bend as Cors import ../laws/CorsAllowedPreflightIs200.bend as Laws -def Laws.cors_preflight_allowed(): +def Laws.cors_preflight_allowed( + origins, + methods, + headers, + credentials, + max_age, + _expose, + origin, + method, + req_headers, + e1, + e2, + e3 +): + %e1 : {Cors.cors.preflight.denied(Cors.cors.acao(origins, credentials, origin), methods, headers, credentials, + max_age, req_headers, method, _) == Http.Reply{200, Cors.cors.preflight_hs(Cors.cors.acao(origins, credentials, + origin), methods, headers, credentials, max_age), ""} : Http.Reply} + %e2 : {Cors.cors.preflight.method(Cors.cors.acao(origins, credentials, origin), methods, headers, credentials, + max_age, req_headers, method, _) == Http.Reply{200, Cors.cors.preflight_hs(Cors.cors.acao(origins, credentials, + origin), methods, headers, credentials, max_age), ""} : Http.Reply} + %e3 : {Cors.cors.preflight.headers(Cors.cors.acao(origins, credentials, origin), methods, headers, credentials, + max_age, req_headers, _) == Http.Reply{200, Cors.cors.preflight_hs(Cors.cors.acao(origins, credentials, origin), + methods, headers, credentials, max_age), ""} : Http.Reply} {==} diff --git a/proofs/CorsCredentialsKeepExplicitOrigin.bend b/proofs/CorsCredentialsKeepExplicitOrigin.bend deleted file mode 100644 index 7574024..0000000 --- a/proofs/CorsCredentialsKeepExplicitOrigin.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CorsCredentialsKeepExplicitOrigin.bend -import Base -import ../laws/CorsCredentialsKeepExplicitOrigin.bend as Laws - -def Laws.cors_credentials_explicit_origin(): - {==} diff --git a/proofs/CorsCredentialsReflectOrigin.bend b/proofs/CorsCredentialsReflectOrigin.bend index 03f64dc..6c07889 100644 --- a/proofs/CorsCredentialsReflectOrigin.bend +++ b/proofs/CorsCredentialsReflectOrigin.bend @@ -1,6 +1,8 @@ # proofs of laws/CorsCredentialsReflectOrigin.bend import Base +import ../src/cors.bend as Cors import ../laws/CorsCredentialsReflectOrigin.bend as Laws -def Laws.cors_credentials_reflect_origin(): +def Laws.cors_credentials_reflect_origin(os, origin, e): + %e : {Cors.cors.acao.ok(os, True{}, origin, _) == origin : String} {==} diff --git a/proofs/CorsGetIsNotPreflight.bend b/proofs/CorsGetIsNotPreflight.bend index 0a0f821..45b675a 100644 --- a/proofs/CorsGetIsNotPreflight.bend +++ b/proofs/CorsGetIsNotPreflight.bend @@ -1,6 +1,10 @@ # proofs of laws/CorsGetIsNotPreflight.bend import Base +import ../src/http.bend as Http +import ../src/cors.bend as Cors import ../laws/CorsGetIsNotPreflight.bend as Laws -def Laws.cors_get_is_not_preflight(): +def Laws.cors_get_is_not_preflight(_method, _target, headers, _body, e): + %e : {Bool.and(_, Bool.not(String.is_empty(Http.headers.find(headers, + "access-control-request-method")))) == False{} : Bool} {==} diff --git a/proofs/CorsNoVaryForStar.bend b/proofs/CorsNoVaryForStar.bend index 3589de8..58f059e 100644 --- a/proofs/CorsNoVaryForStar.bend +++ b/proofs/CorsNoVaryForStar.bend @@ -2,5 +2,6 @@ import Base import ../laws/CorsNoVaryForStar.bend as Laws -def Laws.cors_vary_star(): +def Laws.cors_vary_star(acao, e): + %e : {Bool.and(Bool.not(_), Bool.not(String.is_empty(acao))) == False{} : Bool} {==} diff --git a/proofs/CorsNoVaryWhenRefused.bend b/proofs/CorsNoVaryWhenRefused.bend index 3187313..47fefd0 100644 --- a/proofs/CorsNoVaryWhenRefused.bend +++ b/proofs/CorsNoVaryWhenRefused.bend @@ -1,6 +1,8 @@ # proofs of laws/CorsNoVaryWhenRefused.bend import Base import ../laws/CorsNoVaryWhenRefused.bend as Laws +import ./lemmas/CorsBool.bend as M -def Laws.cors_vary_empty(): - {==} +def Laws.cors_vary_empty(acao, e): + %e : {Bool.and(Bool.not(String.eq(acao, "*")), Bool.not(_)) == False{} : Bool} + M.and_false(Bool.not(String.eq(acao, "*"))) diff --git a/proofs/CorsOptionsWithMethodIsPreflight.bend b/proofs/CorsOptionsWithMethodIsPreflight.bend index 462a349..b48cc59 100644 --- a/proofs/CorsOptionsWithMethodIsPreflight.bend +++ b/proofs/CorsOptionsWithMethodIsPreflight.bend @@ -1,6 +1,14 @@ # proofs of laws/CorsOptionsWithMethodIsPreflight.bend import Base +import ../src/http.bend as Http +import ../src/cors.bend as Cors import ../laws/CorsOptionsWithMethodIsPreflight.bend as Laws -def Laws.cors_on_preflight(): +def Laws.cors_on_preflight(cfg, target, headers, body, reply, e): + %e : {Cors.cors.route(cfg, Http.Request{"OPTIONS", target, headers, body}, reply, + Bool.and(String.eq("OPTIONS", "OPTIONS"), Bool.not(_))) + == Cors.cors.preflight(cfg, Http.headers.find(headers, "origin"), + Http.headers.find(headers, "access-control-request-method"), + Http.headers.find(headers, "access-control-request-headers")) + : Http.Reply} {==} diff --git a/proofs/CorsPreflightAnswersStar.bend b/proofs/CorsPreflightAnswersStar.bend deleted file mode 100644 index 575f20e..0000000 --- a/proofs/CorsPreflightAnswersStar.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CorsPreflightAnswersStar.bend -import Base -import ../laws/CorsPreflightAnswersStar.bend as Laws - -def Laws.cors_preflight_star(): - {==} diff --git a/proofs/CorsPreflightHeaderDenied.bend b/proofs/CorsPreflightHeaderDenied.bend index 89c8cd2..7860767 100644 --- a/proofs/CorsPreflightHeaderDenied.bend +++ b/proofs/CorsPreflightHeaderDenied.bend @@ -1,6 +1,27 @@ # proofs of laws/CorsPreflightHeaderDenied.bend import Base +import ../src/http.bend as Http +import ../src/cors.bend as Cors import ../laws/CorsPreflightHeaderDenied.bend as Laws -def Laws.cors_preflight_header_denied(): +def Laws.cors_preflight_header_denied( + origins, + methods, + headers, + credentials, + max_age, + _expose, + origin, + method, + req_headers, + e1, + e2, + e3 +): + %e1 : {Cors.cors.preflight.denied(Cors.cors.acao(origins, credentials, origin), methods, headers, credentials, + max_age, req_headers, method, _) == Http.Reply{400, [], ""} : Http.Reply} + %e2 : {Cors.cors.preflight.method(Cors.cors.acao(origins, credentials, origin), methods, headers, credentials, + max_age, req_headers, method, _) == Http.Reply{400, [], ""} : Http.Reply} + %e3 : {Cors.cors.preflight.headers(Cors.cors.acao(origins, credentials, origin), methods, headers, credentials, + max_age, req_headers, _) == Http.Reply{400, [], ""} : Http.Reply} {==} diff --git a/proofs/CorsPreflightHeadersIgnoreCase.bend b/proofs/CorsPreflightHeadersIgnoreCase.bend index bfa7aad..aa2b75c 100644 --- a/proofs/CorsPreflightHeadersIgnoreCase.bend +++ b/proofs/CorsPreflightHeadersIgnoreCase.bend @@ -1,6 +1,10 @@ # proofs of laws/CorsPreflightHeadersIgnoreCase.bend import Base +import ../src/http.bend as Http +import ../src/cors.bend as Cors import ../laws/CorsPreflightHeadersIgnoreCase.bend as Laws -def Laws.cors_preflight_header_case(): +def Laws.cors_preflight_header_case(a, _b, xs, e): + %e : {Cors.cors.hit(String.to_lower(a), Cors.cors.lower(xs)) + == Cors.cors.hit(_, Cors.cors.lower(xs)) : Bool} {==} diff --git a/proofs/CorsPreflightMethodDenied.bend b/proofs/CorsPreflightMethodDenied.bend index 0ec11fe..a1cec8a 100644 --- a/proofs/CorsPreflightMethodDenied.bend +++ b/proofs/CorsPreflightMethodDenied.bend @@ -1,6 +1,24 @@ # proofs of laws/CorsPreflightMethodDenied.bend import Base +import ../src/http.bend as Http +import ../src/cors.bend as Cors import ../laws/CorsPreflightMethodDenied.bend as Laws -def Laws.cors_preflight_method_denied(): +def Laws.cors_preflight_method_denied( + origins, + methods, + headers, + credentials, + max_age, + _expose, + origin, + method, + req_headers, + e1, + e2 +): + %e1 : {Cors.cors.preflight.denied(Cors.cors.acao(origins, credentials, origin), methods, headers, credentials, + max_age, req_headers, method, _) == Http.Reply{400, [], ""} : Http.Reply} + %e2 : {Cors.cors.preflight.method(Cors.cors.acao(origins, credentials, origin), methods, headers, credentials, + max_age, req_headers, method, _) == Http.Reply{400, [], ""} : Http.Reply} {==} diff --git a/proofs/CorsPreflightOriginDenied.bend b/proofs/CorsPreflightOriginDenied.bend index 0fbb6ec..7157ef8 100644 --- a/proofs/CorsPreflightOriginDenied.bend +++ b/proofs/CorsPreflightOriginDenied.bend @@ -1,6 +1,23 @@ # proofs of laws/CorsPreflightOriginDenied.bend import Base +import ../src/http.bend as Http +import ../src/cors.bend as Cors import ../laws/CorsPreflightOriginDenied.bend as Laws -def Laws.cors_preflight_origin_denied(): +def Laws.cors_preflight_origin_denied( + origins, + methods, + headers, + credentials, + max_age, + _expose, + origin, + method, + req_headers, + e +): + %e : {Cors.cors.preflight.denied(Cors.cors.acao.ok(origins, credentials, origin, _), + methods, headers, credentials, max_age, req_headers, method, + String.is_empty(Cors.cors.acao.ok(origins, credentials, origin, _))) + == Http.Reply{400, [], ""} : Http.Reply} {==} diff --git a/proofs/CorsReadsOriginHeader.bend b/proofs/CorsReadsOriginHeader.bend index 4a5b2eb..424a34b 100644 --- a/proofs/CorsReadsOriginHeader.bend +++ b/proofs/CorsReadsOriginHeader.bend @@ -2,5 +2,5 @@ import Base import ../laws/CorsReadsOriginHeader.bend as Laws -def Laws.cors_origin_header(): +def Laws.cors_origin_header(_origin): {==} diff --git a/proofs/CorsReadsRequestHeaders.bend b/proofs/CorsReadsRequestHeaders.bend index eb4d5be..e2a3a44 100644 --- a/proofs/CorsReadsRequestHeaders.bend +++ b/proofs/CorsReadsRequestHeaders.bend @@ -2,5 +2,5 @@ import Base import ../laws/CorsReadsRequestHeaders.bend as Laws -def Laws.cors_request_headers_header(): +def Laws.cors_request_headers_header(_names): {==} diff --git a/proofs/CorsReadsRequestMethod.bend b/proofs/CorsReadsRequestMethod.bend index c46d6a1..d996a5e 100644 --- a/proofs/CorsReadsRequestMethod.bend +++ b/proofs/CorsReadsRequestMethod.bend @@ -2,5 +2,5 @@ import Base import ../laws/CorsReadsRequestMethod.bend as Laws -def Laws.cors_request_method_header(): +def Laws.cors_request_method_header(_method): {==} diff --git a/proofs/CorsRefusedLeavesReply.bend b/proofs/CorsRefusedLeavesReply.bend index bd03cd7..f9074a3 100644 --- a/proofs/CorsRefusedLeavesReply.bend +++ b/proofs/CorsRefusedLeavesReply.bend @@ -1,6 +1,20 @@ # proofs of laws/CorsRefusedLeavesReply.bend import Base +import ../src/http.bend as Http +import ../src/cors.bend as Cors import ../laws/CorsRefusedLeavesReply.bend as Laws -def Laws.cors_simple_refused(): +def Laws.cors_simple_refused( + origins, + _methods, + _headers, + credentials, + _max_age, + expose, + origin, + reply, + e +): + %e : {Cors.cors.simple.add(reply, Cors.cors.acao(origins, credentials, origin), credentials, expose, + Bool.not(_)) == reply : Http.Reply} {==} diff --git a/proofs/CorsRefusesMissingOrigin.bend b/proofs/CorsRefusesMissingOrigin.bend index 68ce7e1..8745ca1 100644 --- a/proofs/CorsRefusesMissingOrigin.bend +++ b/proofs/CorsRefusesMissingOrigin.bend @@ -1,6 +1,8 @@ # proofs of laws/CorsRefusesMissingOrigin.bend import Base +import ../src/cors.bend as Cors import ../laws/CorsRefusesMissingOrigin.bend as Laws -def Laws.cors_refused_origin(): +def Laws.cors_refused_origin(os, credentials, origin, e): + %e : {Cors.cors.acao.ok(os, credentials, origin, _) == "" : String} {==} diff --git a/proofs/CorsSimpleAnswersStar.bend b/proofs/CorsSimpleAnswersStar.bend deleted file mode 100644 index 7af27f3..0000000 --- a/proofs/CorsSimpleAnswersStar.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/CorsSimpleAnswersStar.bend -import Base -import ../laws/CorsSimpleAnswersStar.bend as Laws - -def Laws.cors_simple_star(): - {==} diff --git a/proofs/CorsSimpleKeepsBody.bend b/proofs/CorsSimpleKeepsBody.bend index 9cab59c..82fb50b 100644 --- a/proofs/CorsSimpleKeepsBody.bend +++ b/proofs/CorsSimpleKeepsBody.bend @@ -1,6 +1,23 @@ # proofs of laws/CorsSimpleKeepsBody.bend import Base +import ../src/http.bend as Http +import ../src/cors.bend as Cors import ../laws/CorsSimpleKeepsBody.bend as Laws -def Laws.cors_simple_reflects(): +def Laws.cors_simple_reflects( + origins, + _methods, + _headers, + credentials, + _max_age, + expose, + origin, + status, + hs, + body, + e +): + %e : {Cors.cors.simple.add(Http.Reply{status, hs, body}, Cors.cors.acao(origins, credentials, origin), credentials, + expose, Bool.not(_)) == Http.Reply{status, List.append(&2, Http.Header, + Cors.cors.simple_hs(Cors.cors.acao(origins, credentials, origin), credentials, expose), hs), body} : Http.Reply} {==} diff --git a/proofs/CorsStarStaysStar.bend b/proofs/CorsStarStaysStar.bend index 9e438f2..1d11a30 100644 --- a/proofs/CorsStarStaysStar.bend +++ b/proofs/CorsStarStaysStar.bend @@ -1,6 +1,10 @@ # proofs of laws/CorsStarStaysStar.bend import Base +import ../src/cors.bend as Cors import ../laws/CorsStarStaysStar.bend as Laws -def Laws.cors_star_without_credentials(): +def Laws.cors_star_without_credentials(os, origin, e): + %e : {Cors.cors.acao.ok(os, False{}, origin, Bool.or(_, Cors.cors.hit(origin, os))) + == "*" : String} + %e : {Cors.cors.acao.star(origin, _) == "*" : String} {==} diff --git a/proofs/CorsVaryOnSpecificOrigin.bend b/proofs/CorsVaryOnSpecificOrigin.bend index a795aa5..bb9ef63 100644 --- a/proofs/CorsVaryOnSpecificOrigin.bend +++ b/proofs/CorsVaryOnSpecificOrigin.bend @@ -2,5 +2,7 @@ import Base import ../laws/CorsVaryOnSpecificOrigin.bend as Laws -def Laws.cors_vary_specific(): +def Laws.cors_vary_specific(acao, e1, e2): + %e1 : {Bool.and(Bool.not(_), Bool.not(String.is_empty(acao))) == True{} : Bool} + %e2 : {Bool.and(True{}, Bool.not(_)) == True{} : Bool} {==} diff --git a/proofs/DechunkEmptyIsEmpty.bend b/proofs/DechunkEmptyIsEmpty.bend index c00da85..3127e7e 100644 --- a/proofs/DechunkEmptyIsEmpty.bend +++ b/proofs/DechunkEmptyIsEmpty.bend @@ -1,6 +1,20 @@ # proofs of laws/DechunkEmptyIsEmpty.bend import Base +import ../src/http.bend as Http import ../laws/DechunkEmptyIsEmpty.bend as Laws -def Laws.dechunk_empty(): - {==} +# the decoder writes nothing when no chunk-size line is left +law dk.no_cut: + for f: Nat + {Http.chunks(f, Http.NoCut{}) == "" : String} + +def dk.no_cut(f): + match f: + case 0n: + {==} + case 1n+p: + {==} + +def Laws.dechunk_no_crlf(s, e): + %e : {Http.chunks(String.length(s), _) == "" : String} + dk.no_cut(String.length(s)) diff --git a/proofs/DechunkIgnoresExtension.bend b/proofs/DechunkIgnoresExtension.bend deleted file mode 100644 index 75238cd..0000000 --- a/proofs/DechunkIgnoresExtension.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/DechunkIgnoresExtension.bend -import Base -import ../laws/DechunkIgnoresExtension.bend as Laws - -def Laws.dechunk_ignores_extension(): - {==} diff --git a/proofs/DechunkJoinsTwoChunks.bend b/proofs/DechunkJoinsTwoChunks.bend deleted file mode 100644 index f315d4c..0000000 --- a/proofs/DechunkJoinsTwoChunks.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/DechunkJoinsTwoChunks.bend -import Base -import ../laws/DechunkJoinsTwoChunks.bend as Laws - -def Laws.dechunk_two_chunks(): - {==} diff --git a/proofs/DechunkLastChunkAloneIsEmpty.bend b/proofs/DechunkLastChunkAloneIsEmpty.bend deleted file mode 100644 index ee64d6f..0000000 --- a/proofs/DechunkLastChunkAloneIsEmpty.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/DechunkLastChunkAloneIsEmpty.bend -import Base -import ../laws/DechunkLastChunkAloneIsEmpty.bend as Laws - -def Laws.dechunk_only_last(): - {==} diff --git a/proofs/DechunkRfcExample.bend b/proofs/DechunkRfcExample.bend deleted file mode 100644 index ef7f2e0..0000000 --- a/proofs/DechunkRfcExample.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/DechunkRfcExample.bend -import Base -import ../laws/DechunkRfcExample.bend as Laws - -def Laws.dechunk_wiki(): - {==} diff --git a/proofs/DechunkStopsAtZero.bend b/proofs/DechunkStopsAtZero.bend deleted file mode 100644 index 5023108..0000000 --- a/proofs/DechunkStopsAtZero.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/DechunkStopsAtZero.bend -import Base -import ../laws/DechunkStopsAtZero.bend as Laws - -def Laws.dechunk_stops_at_zero(): - {==} diff --git a/proofs/DeleteIsIdempotent.bend b/proofs/DeleteIsIdempotent.bend deleted file mode 100644 index 0244dcf..0000000 --- a/proofs/DeleteIsIdempotent.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/DeleteIsIdempotent.bend -import Base -import ../laws/DeleteIsIdempotent.bend as Laws - -def Laws.method_idempotent_delete(): - {==} diff --git a/proofs/DeleteNotSafe.bend b/proofs/DeleteNotSafe.bend deleted file mode 100644 index ccd7401..0000000 --- a/proofs/DeleteNotSafe.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/DeleteNotSafe.bend -import Base -import ../laws/DeleteNotSafe.bend as Laws - -def Laws.method_safe_delete(): - {==} diff --git a/proofs/EqualContentLengthsAreOne.bend b/proofs/EqualContentLengthsAreOne.bend deleted file mode 100644 index 458ca08..0000000 --- a/proofs/EqualContentLengthsAreOne.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/EqualContentLengthsAreOne.bend -import Base -import ../laws/EqualContentLengthsAreOne.bend as Laws - -def Laws.parse_equal_content_lengths(): - {==} diff --git a/proofs/ExchangeCarriesMethod.bend b/proofs/ExchangeCarriesMethod.bend index 2dcf460..e5e3d8d 100644 --- a/proofs/ExchangeCarriesMethod.bend +++ b/proofs/ExchangeCarriesMethod.bend @@ -7,9 +7,11 @@ import ./lemmas/BaseEqualities.bend as M1 # --- the request's header fields --- # a string prefix both sides share does not change starts_with -def eq.starts_cancel(+a: String, +x: String, +y: String) - -> {String.starts_with.go(String.append(a, y), String.append(a, x)) - == String.starts_with.go(y, x) : Bool}: +def eq.starts_cancel( + +a: String, + +x: String, + +y: String +) -> {String.starts_with.go(String.append(a, y), String.append(a, x)) == String.starts_with.go(y, x) : Bool}: match a: case SNil{}: {==} diff --git a/proofs/FailuresReportedByPhase.bend b/proofs/FailuresReportedByPhase.bend index c048dc1..56f825e 100644 --- a/proofs/FailuresReportedByPhase.bend +++ b/proofs/FailuresReportedByPhase.bend @@ -4,10 +4,15 @@ import ../src/wirespec.bend as Spec import ../laws/FailuresReportedByPhase.bend as Laws # a resolve's failure is fail.resolve, ran out of time or not -def fail.resolve.any(host: String, +port: U32, +ms: U32, +n: U32, why: String, - late: Bool) - -> {Spec.wire.fail.of(Spec.Resolve{}, host, port, ms, n, why, late) - == Spec.wire.fail.resolve(host, n, U32.is_eq(n, 2)) : String}: +def fail.resolve.any( + host: String, + +port: U32, + +ms: U32, + +n: U32, + why: String, + late: Bool +) -> {Spec.wire.fail.of(Spec.Resolve{}, host, port, ms, n, why, late) == Spec.wire.fail.resolve(host, n, U32.is_eq(n, + 2)) : String}: match late: case True{}: {==} @@ -15,21 +20,23 @@ def fail.resolve.any(host: String, +port: U32, +ms: U32, +n: U32, why: String, {==} # a resolve that failed with another number names the cause -def fail.resolve.some(host: String, +n: U32, - e: {False{} == U32.is_eq(n, 2) : Bool}) - -> {Spec.wire.fail.resolve(host, n, U32.is_eq(n, 2)) - == "6\ncould not resolve " ++ host ++ ": " ++ Spec.wire.cause(n) - : String}: +def fail.resolve.some( + host: String, + +n: U32, + e: {False{} == U32.is_eq(n, 2) : Bool} +) -> {Spec.wire.fail.resolve(host, n, U32.is_eq(n, 2)) == "6\ncould not resolve " ++ host ++ ": " + ++ Spec.wire.cause(n) : String}: %e : {Spec.wire.fail.resolve(host, n, _) == "6\ncould not resolve " ++ host ++ ": " ++ Spec.wire.cause(n) : String} {==} # a name with no address names the host alone -def fail.resolve.none(host: String, +n: U32, - e: {True{} == U32.is_eq(n, 2) : Bool}) - -> {Spec.wire.fail.resolve(host, n, U32.is_eq(n, 2)) - == "6\ncould not resolve " ++ host : String}: +def fail.resolve.none( + host: String, + +n: U32, + e: {True{} == U32.is_eq(n, 2) : Bool} +) -> {Spec.wire.fail.resolve(host, n, U32.is_eq(n, 2)) == "6\ncould not resolve " ++ host : String}: %e : {Spec.wire.fail.resolve(host, n, _) == "6\ncould not resolve " ++ host : String} {==} @@ -51,19 +58,29 @@ def Laws.fail_resolve_none(host, port, ms, n, e, why): fail.resolve.none(host, n, e)) # a call that ran out of time is reported by fail.late -def fail.at.late(p: Spec.Phase, host: String, +port: U32, +ms: U32, +n: U32, - why: String, e: {True{} == U32.is_eq(n, 110) : Bool}) - -> {Spec.wire.fail(p, host, port, ms, n, why) - == Spec.wire.fail.late(p, host, port, ms, n) : String}: +def fail.at.late( + p: Spec.Phase, + host: String, + +port: U32, + +ms: U32, + +n: U32, + why: String, + e: {True{} == U32.is_eq(n, 110) : Bool} +) -> {Spec.wire.fail(p, host, port, ms, n, why) == Spec.wire.fail.late(p, host, port, ms, n) : String}: %e : {Spec.wire.fail.of(p, host, port, ms, n, why, _) == Spec.wire.fail.late(p, host, port, ms, n) : String} {==} # a call that failed otherwise is reported by fail.other -def fail.at.other(p: Spec.Phase, host: String, +port: U32, +ms: U32, +n: U32, - why: String, e: {False{} == U32.is_eq(n, 110) : Bool}) - -> {Spec.wire.fail(p, host, port, ms, n, why) - == Spec.wire.fail.other(p, host, port, n, why) : String}: +def fail.at.other( + p: Spec.Phase, + host: String, + +port: U32, + +ms: U32, + +n: U32, + why: String, + e: {False{} == U32.is_eq(n, 110) : Bool} +) -> {Spec.wire.fail(p, host, port, ms, n, why) == Spec.wire.fail.other(p, host, port, n, why) : String}: %e : {Spec.wire.fail.of(p, host, port, ms, n, why, _) == Spec.wire.fail.other(p, host, port, n, why) : String} {==} diff --git a/proofs/FieldLookupFindsFirst.bend b/proofs/FieldLookupFindsFirst.bend index 91aaacc..7eb8a2d 100644 --- a/proofs/FieldLookupFindsFirst.bend +++ b/proofs/FieldLookupFindsFirst.bend @@ -1,6 +1,15 @@ # proofs of laws/FieldLookupFindsFirst.bend import Base +import ../src/http.bend as Http import ../laws/FieldLookupFindsFirst.bend as Laws -def Laws.headers_find_first(): +def Laws.headers_find_first(_n, v, t, name, e): + %e : {Http.headers.find.pick(v, _, + _u => Http.headers.find.go(t, String.to_lower(name))) == v : String} + {==} + +def Laws.headers_find_skips(_n, v, t, name, e): + %e : {Http.headers.find.pick(v, _, + _u => Http.headers.find.go(t, String.to_lower(name))) + == Http.headers.find(t, name) : String} {==} diff --git a/proofs/FieldLookupIgnoresCase.bend b/proofs/FieldLookupIgnoresCase.bend deleted file mode 100644 index 0452a3c..0000000 --- a/proofs/FieldLookupIgnoresCase.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/FieldLookupIgnoresCase.bend -import Base -import ../laws/FieldLookupIgnoresCase.bend as Laws - -def Laws.headers_find_ignores_case(): - {==} diff --git a/proofs/FieldValueTrimsWhitespace.bend b/proofs/FieldValueTrimsWhitespace.bend index 9d3915a..bb79fcd 100644 --- a/proofs/FieldValueTrimsWhitespace.bend +++ b/proofs/FieldValueTrimsWhitespace.bend @@ -1,6 +1,11 @@ # proofs of laws/FieldValueTrimsWhitespace.bend import Base +import ../src/http.bend as Http import ../laws/FieldValueTrimsWhitespace.bend as Laws -def Laws.head_line_trims(): +def Laws.head_line_trims(_h, before, after, e, ef): + %e : {Http.head.from_cut(_) == Some{Http.H{before, String.trim(after)}} + : Maybe<&2, Http.Header>} + %ef : {Http.field.keep(before, String.trim(after), _) + == Some{Http.H{before, String.trim(after)}} : Maybe<&2, Http.Header>} {==} diff --git a/proofs/FreshUnderMaxAge.bend b/proofs/FreshUnderMaxAge.bend index 19ca5c6..13ad081 100644 --- a/proofs/FreshUnderMaxAge.bend +++ b/proofs/FreshUnderMaxAge.bend @@ -1,6 +1,8 @@ # proofs of laws/FreshUnderMaxAge.bend import Base +import ../src/cache.bend as Cache import ../laws/FreshUnderMaxAge.bend as Laws -def Laws.fresh_max_age_open(): +def Laws.fresh_max_age(_public, _private, _max_age, _expires, n, age, e): + %e : {Cache.cache.fresh.go(age, _) == Nat.is_lt(age, n) : Bool} {==} diff --git a/proofs/GetAsteriskTargetRejected.bend b/proofs/GetAsteriskTargetRejected.bend index 2e20387..952647e 100644 --- a/proofs/GetAsteriskTargetRejected.bend +++ b/proofs/GetAsteriskTargetRejected.bend @@ -1,6 +1,9 @@ # proofs of laws/GetAsteriskTargetRejected.bend import Base +import ../src/http.bend as Http import ../laws/GetAsteriskTargetRejected.bend as Laws -def Laws.ask_get_asterisk_rejected(): +def Laws.ask_get_asterisk_rejected(method, ls, body, e): + %e : {Http.ask.origin(method, "*", ls, body, _) + == Http.Bad{"the request-target is not in origin-form"} : Http.Request} {==} diff --git a/proofs/GetIsIdempotent.bend b/proofs/GetIsIdempotent.bend deleted file mode 100644 index 4d34365..0000000 --- a/proofs/GetIsIdempotent.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/GetIsIdempotent.bend -import Base -import ../laws/GetIsIdempotent.bend as Laws - -def Laws.method_idempotent_get(): - {==} diff --git a/proofs/GetIsSafe.bend b/proofs/GetIsSafe.bend deleted file mode 100644 index ac03ed3..0000000 --- a/proofs/GetIsSafe.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/GetIsSafe.bend -import Base -import ../laws/GetIsSafe.bend as Laws - -def Laws.method_safe_get(): - {==} diff --git a/proofs/GetOmitsContentLength.bend b/proofs/GetOmitsContentLength.bend deleted file mode 100644 index 1f3c0bc..0000000 --- a/proofs/GetOmitsContentLength.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/GetOmitsContentLength.bend -import Base -import ../laws/GetOmitsContentLength.bend as Laws - -def Laws.get_omits_content_length(): - {==} diff --git a/proofs/HeadIsIdempotent.bend b/proofs/HeadIsIdempotent.bend deleted file mode 100644 index 905912e..0000000 --- a/proofs/HeadIsIdempotent.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/HeadIsIdempotent.bend -import Base -import ../laws/HeadIsIdempotent.bend as Laws - -def Laws.method_idempotent_head(): - {==} diff --git a/proofs/HeadIsSafe.bend b/proofs/HeadIsSafe.bend deleted file mode 100644 index 207743d..0000000 --- a/proofs/HeadIsSafe.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/HeadIsSafe.bend -import Base -import ../laws/HeadIsSafe.bend as Laws - -def Laws.method_safe_head(): - {==} diff --git a/proofs/HeadReplyDropsBody.bend b/proofs/HeadReplyDropsBody.bend deleted file mode 100644 index 4444c3c..0000000 --- a/proofs/HeadReplyDropsBody.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/HeadReplyDropsBody.bend -import Base -import ../laws/HeadReplyDropsBody.bend as Laws - -def Laws.head_reply_drops_body(): - {==} diff --git a/proofs/HttpsDefaultsTo443.bend b/proofs/HttpsDefaultsTo443.bend index b3eb220..13d2fb6 100644 --- a/proofs/HttpsDefaultsTo443.bend +++ b/proofs/HttpsDefaultsTo443.bend @@ -2,5 +2,6 @@ import Base import ../laws/HttpsDefaultsTo443.bend as Laws -def Laws.dflt_https(): +def Laws.dflt_https(_scheme, e): + %e : {Bool.pick(U32, _, 443, 80) == 443 : U32} {==} diff --git a/proofs/JsonParseIsEzjsonParse.bend b/proofs/JsonParseIsEzjsonParse.bend new file mode 100644 index 0000000..d012a68 --- /dev/null +++ b/proofs/JsonParseIsEzjsonParse.bend @@ -0,0 +1,14 @@ +# proofs of laws/JsonParseIsEzjsonParse.bend +import Base +import ../src/json.bend as Json +import ezjson@1.2.0.0/main.bend as Ezjson +import ezjson@1.2.0.0/src/value.bend as Value +import ../laws/JsonParseIsEzjsonParse.bend as Laws + +def Laws.json_parse_rejects(s, e): + Equal.cong(Maybe<&2, Value.Json>, Maybe<&2, String>, + x => Json.json.as_str(x), Ezjson.parse(s), None{}, e) + +def Laws.json_parse_string(s, j, e): + Equal.cong(Maybe<&2, Value.Json>, Maybe<&2, String>, + x => Json.json.as_str(x), Ezjson.parse(s), Some{j}, e) diff --git a/proofs/JsonRejectsNonJson.bend b/proofs/JsonRejectsNonJson.bend deleted file mode 100644 index c501bb1..0000000 --- a/proofs/JsonRejectsNonJson.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/JsonRejectsNonJson.bend -import Base -import ../laws/JsonRejectsNonJson.bend as Laws - -def Laws.json_parse_rejects(): - {==} diff --git a/proofs/JsonStringIsTextBody.bend b/proofs/JsonStringIsTextBody.bend index 0de1558..ffb26b6 100644 --- a/proofs/JsonStringIsTextBody.bend +++ b/proofs/JsonStringIsTextBody.bend @@ -2,5 +2,5 @@ import Base import ../laws/JsonStringIsTextBody.bend as Laws -def Laws.json_string_is_text_body(): +def Laws.json_string_is_text_body(_j): {==} diff --git a/proofs/JsonStringParsesBack.bend b/proofs/JsonStringParsesBack.bend deleted file mode 100644 index 302c8ba..0000000 --- a/proofs/JsonStringParsesBack.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/JsonStringParsesBack.bend -import Base -import ../laws/JsonStringParsesBack.bend as Laws - -def Laws.json_parse_string(): - {==} diff --git a/proofs/LowercaseGetNotSafe.bend b/proofs/LowercaseGetNotSafe.bend deleted file mode 100644 index 02f74ae..0000000 --- a/proofs/LowercaseGetNotSafe.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/LowercaseGetNotSafe.bend -import Base -import ../laws/LowercaseGetNotSafe.bend as Laws - -def Laws.method_safe_get_lower(): - {==} diff --git a/proofs/MaxAgeOneFreshThenStale.bend b/proofs/MaxAgeOneFreshThenStale.bend deleted file mode 100644 index a54cd2e..0000000 --- a/proofs/MaxAgeOneFreshThenStale.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/MaxAgeOneFreshThenStale.bend -import Base -import ../laws/MaxAgeOneFreshThenStale.bend as Laws - -def Laws.fresh_max_age_one(): - {==} diff --git a/proofs/MaxAgeOverridesExpires.bend b/proofs/MaxAgeOverridesExpires.bend deleted file mode 100644 index 64c2215..0000000 --- a/proofs/MaxAgeOverridesExpires.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/MaxAgeOverridesExpires.bend -import Base -import ../laws/MaxAgeOverridesExpires.bend as Laws - -def Laws.fresh_max_age_overrides_expires(): - {==} diff --git a/proofs/MaxAgeZeroIsStale.bend b/proofs/MaxAgeZeroIsStale.bend deleted file mode 100644 index 230bdf3..0000000 --- a/proofs/MaxAgeZeroIsStale.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/MaxAgeZeroIsStale.bend -import Base -import ../laws/MaxAgeZeroIsStale.bend as Laws - -def Laws.fresh_max_age_zero(): - {==} diff --git a/proofs/MaxZeroIsNoLimit.bend b/proofs/MaxZeroIsNoLimit.bend new file mode 100644 index 0000000..eb4567d --- /dev/null +++ b/proofs/MaxZeroIsNoLimit.bend @@ -0,0 +1,9 @@ +# proofs of laws/MaxZeroIsNoLimit.bend +import Base +import ../laws/MaxZeroIsNoLimit.bend as Laws + +def Laws.pool_limited(_slots, _max, _done, _tracked): + {==} + +def Laws.pool_done(_slots, _max, _done, _tracked): + {==} diff --git a/proofs/MethodTokensAreCaseSensitive.bend b/proofs/MethodTokensAreCaseSensitive.bend index ee944f1..2a2ed86 100644 --- a/proofs/MethodTokensAreCaseSensitive.bend +++ b/proofs/MethodTokensAreCaseSensitive.bend @@ -2,5 +2,9 @@ import Base import ../laws/MethodTokensAreCaseSensitive.bend as Laws -def Laws.method_tokens_are_case_sensitive(): - {==} +def Laws.method_tokens_are_case_sensitive(t): + match t: + case SNil{}: + {==} + case SCon{Chr{y}, tt}: + {==} diff --git a/proofs/MethodsSafeAndIdempotent.bend b/proofs/MethodsSafeAndIdempotent.bend new file mode 100644 index 0000000..8a57000 --- /dev/null +++ b/proofs/MethodsSafeAndIdempotent.bend @@ -0,0 +1,16 @@ +# proofs of laws/MethodsSafeAndIdempotent.bend +import Base +import ../src/http.bend as Http +import ../laws/MethodsSafeAndIdempotent.bend as Laws + +def Laws.method_safe_is(_method): + {==} + +def Laws.method_idempotent_is(_method): + {==} + +def Laws.method_safe_idempotent(method, e): + %Equal.sym(Bool, Http.method.safe(method), True{}, e) + : {Bool.or(_, Bool.or(String.eq(method, "PUT"), String.eq(method, "DELETE"))) + == True{} : Bool} + {==} diff --git a/proofs/MissingFieldIsEmpty.bend b/proofs/MissingFieldIsEmpty.bend index b2489b9..abc1134 100644 --- a/proofs/MissingFieldIsEmpty.bend +++ b/proofs/MissingFieldIsEmpty.bend @@ -2,5 +2,5 @@ import Base import ../laws/MissingFieldIsEmpty.bend as Laws -def Laws.headers_find_missing(): +def Laws.headers_find_missing(_name): {==} diff --git a/proofs/NoCacheNotFresh.bend b/proofs/NoCacheNotFresh.bend deleted file mode 100644 index 8dfccb8..0000000 --- a/proofs/NoCacheNotFresh.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/NoCacheNotFresh.bend -import Base -import ../laws/NoCacheNotFresh.bend as Laws - -def Laws.fresh_no_cache(): - {==} diff --git a/proofs/NoMaxAgeNotFresh.bend b/proofs/NoMaxAgeNotFresh.bend index f9f12ae..e2eaa54 100644 --- a/proofs/NoMaxAgeNotFresh.bend +++ b/proofs/NoMaxAgeNotFresh.bend @@ -1,6 +1,26 @@ # proofs of laws/NoMaxAgeNotFresh.bend import Base +import ../src/cache.bend as Cache import ../laws/NoMaxAgeNotFresh.bend as Laws -def Laws.fresh_public_only(): - {==} +# no-store and no-cache are not fresh either way; past them, max-age decides +def Laws.fresh_without_max_age( + no_store, + no_cache, + _public, + _private, + _max_age, + _expires, + age, + e +): + match no_store: + case True{}: + {==} + case False{}: + match no_cache: + case True{}: + {==} + case False{}: + %e : {Cache.cache.fresh.go(age, _) == False{} : Bool} + {==} diff --git a/proofs/NoStoreNotFresh.bend b/proofs/NoStoreNotFresh.bend deleted file mode 100644 index cf1947a..0000000 --- a/proofs/NoStoreNotFresh.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/NoStoreNotFresh.bend -import Base -import ../laws/NoStoreNotFresh.bend as Laws - -def Laws.fresh_no_store(): - {==} diff --git a/proofs/NonHeadReplyKeepsBody.bend b/proofs/NonHeadReplyKeepsBody.bend deleted file mode 100644 index 593b7db..0000000 --- a/proofs/NonHeadReplyKeepsBody.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/NonHeadReplyKeepsBody.bend -import Base -import ../laws/NonHeadReplyKeepsBody.bend as Laws - -def Laws.get_reply_keeps_body(): - {==} diff --git a/proofs/NonHexChunkSizeTorn.bend b/proofs/NonHexChunkSizeTorn.bend index c93e6e5..c1a541f 100644 --- a/proofs/NonHexChunkSizeTorn.bend +++ b/proofs/NonHexChunkSizeTorn.bend @@ -1,6 +1,16 @@ # proofs of laws/NonHexChunkSizeTorn.bend import Base +import ../src/http.bend as Http import ../laws/NonHexChunkSizeTorn.bend as Laws -def Laws.parse_rejects_non_hex_chunk(): +def Laws.chunked_non_hex(st, hs, body, f, before, after, el, e, eh): + %el : {Http.parse.chunked(st, hs, body, + Http.chunks.scan(_, Http.divide(body, "\r\n"))) + == Http.Torn{"chunk size is not hexadecimal"} : Http.Reply} + %e : {Http.parse.chunked(st, hs, body, Http.chunks.scan(1n+f, _)) + == Http.Torn{"chunk size is not hexadecimal"} : Http.Reply} + %eh : {Http.parse.chunked(st, hs, body, + Http.chunks.scan.step(Http.chunks.next.hex(before, after, _), + cut => Http.chunks.scan(f, cut))) + == Http.Torn{"chunk size is not hexadecimal"} : Http.Reply} {==} diff --git a/proofs/ObsFoldRejected.bend b/proofs/ObsFoldRejected.bend index eb27a5b..b50fd10 100644 --- a/proofs/ObsFoldRejected.bend +++ b/proofs/ObsFoldRejected.bend @@ -1,6 +1,10 @@ # proofs of laws/ObsFoldRejected.bend import Base +import ../src/http.bend as Http import ../laws/ObsFoldRejected.bend as Laws -def Laws.head_line_rejects_obs_fold(): +def Laws.head_line_rejects_obs_fold(_h, before, after, e, ef): + %e : {Http.head.from_cut(_) == None{} : Maybe<&2, Http.Header>} + %ef : {Http.field.keep(before, String.trim(after), _) == None{} + : Maybe<&2, Http.Header>} {==} diff --git a/proofs/OneOctetPerChar.bend b/proofs/OneOctetPerChar.bend index 876eea5..636ce17 100644 --- a/proofs/OneOctetPerChar.bend +++ b/proofs/OneOctetPerChar.bend @@ -3,5 +3,3 @@ import Base import ../laws/OneOctetPerChar.bend as Laws import ./lemmas/OctetLength.bend as M1 import ./lemmas/OctetTakeDrop.bend as M2 - - diff --git a/proofs/OptionsAsteriskNamesServer.bend b/proofs/OptionsAsteriskNamesServer.bend index 2db4387..b671302 100644 --- a/proofs/OptionsAsteriskNamesServer.bend +++ b/proofs/OptionsAsteriskNamesServer.bend @@ -2,5 +2,5 @@ import Base import ../laws/OptionsAsteriskNamesServer.bend as Laws -def Laws.ask_options_asterisk(): +def Laws.ask_options_asterisk(_ls, _body): {==} diff --git a/proofs/OptionsIsIdempotent.bend b/proofs/OptionsIsIdempotent.bend deleted file mode 100644 index 94594c4..0000000 --- a/proofs/OptionsIsIdempotent.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/OptionsIsIdempotent.bend -import Base -import ../laws/OptionsIsIdempotent.bend as Laws - -def Laws.method_idempotent_options(): - {==} diff --git a/proofs/OptionsIsSafe.bend b/proofs/OptionsIsSafe.bend deleted file mode 100644 index 7963ce7..0000000 --- a/proofs/OptionsIsSafe.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/OptionsIsSafe.bend -import Base -import ../laws/OptionsIsSafe.bend as Laws - -def Laws.method_safe_options(): - {==} diff --git a/proofs/OriginFormKeepsQuery.bend b/proofs/OriginFormKeepsQuery.bend index 6506f28..a91cfd6 100644 --- a/proofs/OriginFormKeepsQuery.bend +++ b/proofs/OriginFormKeepsQuery.bend @@ -1,6 +1,12 @@ # proofs of laws/OriginFormKeepsQuery.bend import Base +import ../src/http.bend as Http import ../laws/OriginFormKeepsQuery.bend as Laws -def Laws.ask_origin_form_keeps_query(): +def Laws.ask_origin_form_keeps_query(method, target, ls, body, e): + %e : {Http.ask.origin(method, target, ls, body, + Http.target.form(method, target, _)) + == Http.ask.frame(method, target, Http.head.list(ls), + Http.head.go(ls, "transfer-encoding"), + Http.head.values(ls, "content-length"), body) : Http.Request} {==} diff --git a/proofs/PatchNotIdempotent.bend b/proofs/PatchNotIdempotent.bend deleted file mode 100644 index 1420a65..0000000 --- a/proofs/PatchNotIdempotent.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/PatchNotIdempotent.bend -import Base -import ../laws/PatchNotIdempotent.bend as Laws - -def Laws.method_idempotent_patch(): - {==} diff --git a/proofs/PostNotIdempotent.bend b/proofs/PostNotIdempotent.bend deleted file mode 100644 index 1bcd08a..0000000 --- a/proofs/PostNotIdempotent.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/PostNotIdempotent.bend -import Base -import ../laws/PostNotIdempotent.bend as Laws - -def Laws.method_idempotent_post(): - {==} diff --git a/proofs/PostNotSafe.bend b/proofs/PostNotSafe.bend deleted file mode 100644 index 424b73c..0000000 --- a/proofs/PostNotSafe.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/PostNotSafe.bend -import Base -import ../laws/PostNotSafe.bend as Laws - -def Laws.method_safe_post(): - {==} diff --git a/proofs/PostWritesContentLength.bend b/proofs/PostWritesContentLength.bend deleted file mode 100644 index 2d64572..0000000 --- a/proofs/PostWritesContentLength.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/PostWritesContentLength.bend -import Base -import ../laws/PostWritesContentLength.bend as Laws - -def Laws.post_writes_content_length(): - {==} diff --git a/proofs/PutIsIdempotent.bend b/proofs/PutIsIdempotent.bend deleted file mode 100644 index 76dd3ce..0000000 --- a/proofs/PutIsIdempotent.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/PutIsIdempotent.bend -import Base -import ../laws/PutIsIdempotent.bend as Laws - -def Laws.method_idempotent_put(): - {==} diff --git a/proofs/PutNotSafe.bend b/proofs/PutNotSafe.bend deleted file mode 100644 index 20f163c..0000000 --- a/proofs/PutNotSafe.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/PutNotSafe.bend -import Base -import ../laws/PutNotSafe.bend as Laws - -def Laws.method_safe_put(): - {==} diff --git a/proofs/ReadStateMatchesWholeText.bend b/proofs/ReadStateMatchesWholeText.bend index 09105c4..1621c38 100644 --- a/proofs/ReadStateMatchesWholeText.bend +++ b/proofs/ReadStateMatchesWholeText.bend @@ -2,5 +2,3 @@ import Base import ../laws/ReadStateMatchesWholeText.bend as Laws import ./lemmas/WalksOverAppendedText.bend as M1 - - diff --git a/proofs/ReadsJudgedByCount.bend b/proofs/ReadsJudgedByCount.bend index 4370225..ef4d9a9 100644 --- a/proofs/ReadsJudgedByCount.bend +++ b/proofs/ReadsJudgedByCount.bend @@ -64,7 +64,10 @@ def Laws.hear_count(h, b, e): +f = Nat.add(g, String.length(b)) +lt = Equal.sym(Bool, Nat.is_lt(owed, String.length(b)), False{}, M1.eq.not.true(Nat.is_lt(owed, String.length(b)), Equal.sym(Bool, True{}, - Bool.not(Nat.is_lt(owed, String.length(b))), e))) + Bool.not(Nat.is_lt(owed, String.length(b))), + Equal.trans(Bool, True{}, Nat.is_ge(owed, String.length(b)), + Bool.not(Nat.is_lt(owed, String.length(b))), e, + M2.ge_not_lt(owed, String.length(b)))))) Equal.cong(Http.Skip, Http.Hear, x => Http.Walking{Http.walk.data(f, x, s => Http.walk(f, s))}, Http.Short{Nat.sub(owed, String.length(b))}, Http.octs.skip(b, owed), diff --git a/proofs/Reason200IsOk.bend b/proofs/Reason200IsOk.bend deleted file mode 100644 index 4d5c906..0000000 --- a/proofs/Reason200IsOk.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/Reason200IsOk.bend -import Base -import ../laws/Reason200IsOk.bend as Laws - -def Laws.reason_200(): - {==} diff --git a/proofs/Reason201IsCreated.bend b/proofs/Reason201IsCreated.bend deleted file mode 100644 index 331276b..0000000 --- a/proofs/Reason201IsCreated.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/Reason201IsCreated.bend -import Base -import ../laws/Reason201IsCreated.bend as Laws - -def Laws.reason_201(): - {==} diff --git a/proofs/Reason204IsNoContent.bend b/proofs/Reason204IsNoContent.bend deleted file mode 100644 index a79ab49..0000000 --- a/proofs/Reason204IsNoContent.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/Reason204IsNoContent.bend -import Base -import ../laws/Reason204IsNoContent.bend as Laws - -def Laws.reason_204(): - {==} diff --git a/proofs/Reason400IsBadRequest.bend b/proofs/Reason400IsBadRequest.bend deleted file mode 100644 index 3fc3ab2..0000000 --- a/proofs/Reason400IsBadRequest.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/Reason400IsBadRequest.bend -import Base -import ../laws/Reason400IsBadRequest.bend as Laws - -def Laws.reason_400(): - {==} diff --git a/proofs/Reason404IsNotFound.bend b/proofs/Reason404IsNotFound.bend deleted file mode 100644 index 83db435..0000000 --- a/proofs/Reason404IsNotFound.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/Reason404IsNotFound.bend -import Base -import ../laws/Reason404IsNotFound.bend as Laws - -def Laws.reason_404(): - {==} diff --git a/proofs/Reason405IsMethodNotAllowed.bend b/proofs/Reason405IsMethodNotAllowed.bend deleted file mode 100644 index aeaa19a..0000000 --- a/proofs/Reason405IsMethodNotAllowed.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/Reason405IsMethodNotAllowed.bend -import Base -import ../laws/Reason405IsMethodNotAllowed.bend as Laws - -def Laws.reason_405(): - {==} diff --git a/proofs/Reason500IsInternalServerError.bend b/proofs/Reason500IsInternalServerError.bend deleted file mode 100644 index 090b060..0000000 --- a/proofs/Reason500IsInternalServerError.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/Reason500IsInternalServerError.bend -import Base -import ../laws/Reason500IsInternalServerError.bend as Laws - -def Laws.reason_500(): - {==} diff --git a/proofs/RelativeTargetRejected.bend b/proofs/RelativeTargetRejected.bend deleted file mode 100644 index 846ae2c..0000000 --- a/proofs/RelativeTargetRejected.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/RelativeTargetRejected.bend -import Base -import ../laws/RelativeTargetRejected.bend as Laws - -def Laws.ask_rejects_relative_target(): - {==} diff --git a/proofs/RequestDisagreeingContentLengthsRejected.bend b/proofs/RequestDisagreeingContentLengthsRejected.bend index 210b657..59ef1be 100644 --- a/proofs/RequestDisagreeingContentLengthsRejected.bend +++ b/proofs/RequestDisagreeingContentLengthsRejected.bend @@ -1,6 +1,14 @@ # proofs of laws/RequestDisagreeingContentLengthsRejected.bend import Base +import ../src/http.bend as Http import ../laws/RequestDisagreeingContentLengthsRejected.bend as Laws -def Laws.ask_rejects_disagreeing_cl(): +def Laws.clen_disagree(v, _w, rest, e): + %e : {Http.clen.agree.step(_, _u => Http.clen.agree.go(rest, v)) + == False{} : Bool} + {==} + +def Laws.ask_rejects_disagreeing_cl(method, target, hs, te, lens, body, e): + %e : {Http.ask.agree(method, target, hs, te, lens, body, _) + == Http.Bad{"Content-Length values disagree"} : Http.Request} {==} diff --git a/proofs/RequestEqualContentLengthsFrameOneBody.bend b/proofs/RequestEqualContentLengthsFrameOneBody.bend index ba9ec5f..b8bd900 100644 --- a/proofs/RequestEqualContentLengthsFrameOneBody.bend +++ b/proofs/RequestEqualContentLengthsFrameOneBody.bend @@ -1,6 +1,24 @@ # proofs of laws/RequestEqualContentLengthsFrameOneBody.bend import Base +import ../src/http.bend as Http import ../laws/RequestEqualContentLengthsFrameOneBody.bend as Laws -def Laws.ask_equal_content_lengths(): +def Laws.clen_agree_repeat(v, _w, rest, e): + %e : {Http.clen.agree.step(_, _u => Http.clen.agree.go(rest, v)) + == Http.clen.agree.go(rest, v) : Bool} + {==} + +def Laws.ask_equal_content_lengths(method, target, hs, te, lens, body, ea, ec): + %ea : {Http.ask.agree(method, target, hs, te, lens, body, _) + == Http.ask.len(method, target, hs, Http.digits.read(Http.first(lens)), + body) : Http.Request} + %ec : {Http.ask.te(method, target, hs, lens, body, _) + == Http.ask.len(method, target, hs, Http.digits.read(Http.first(lens)), + body) : Http.Request} + {==} + +def Laws.ask_clen_takes_prefix(method, target, hs, n, body, e): + %e : {Http.ask.short(method, target, hs, n, body, _) + == Http.Request{method, target, hs, Http.octs.take(body, n)} + : Http.Request} {==} diff --git a/proofs/RequestHeaderFieldsOrdered.bend b/proofs/RequestHeaderFieldsOrdered.bend index 8733ce9..ecbea57 100644 --- a/proofs/RequestHeaderFieldsOrdered.bend +++ b/proofs/RequestHeaderFieldsOrdered.bend @@ -40,9 +40,9 @@ def Laws.request_text(_method, _host, _path, _hs, _body): {==} # a list's tail after an empty append is the list -def hd.app_nil(+xs: List<&2, - Http.Header>) -> {List.append(&2, Http.Header, xs, []) == xs : List<&2, - Http.Header>}: +def hd.app_nil( + +xs: List<&2, Http.Header> +) -> {List.append(&2, Http.Header, xs, []) == xs : List<&2, Http.Header>}: match xs: case []: {==} @@ -52,13 +52,15 @@ def hd.app_nil(+xs: List<&2, hd.app_nil(t)) # one step of idem -def hd.idem.put(+f: Http.Field, +k: Bool, +h: Http.Header, +t: List<&2, - Http.Header>, +def hd.idem.put( + +f: Http.Field, + +k: Bool, + +h: Http.Header, + +t: List<&2, Http.Header>, +ek: {k == Http.field.same(f, Http.header.field(h)) : Bool}, - +ih: {Http.fields.of(f, Http.fields.of(f, t)) - == Http.fields.of(f, t) : List<&2, Http.Header>}) - -> {Http.fields.of(f, Http.fields.put(k, h, Http.fields.of(f, t))) - == Http.fields.put(k, h, Http.fields.of(f, t)) : List<&2, Http.Header>}: + +ih: {Http.fields.of(f, Http.fields.of(f, t)) == Http.fields.of(f, t) : List<&2, Http.Header>} +) -> {Http.fields.of(f, Http.fields.put(k, h, Http.fields.of(f, t))) == Http.fields.put(k, h, Http.fields.of(f, + t)) : List<&2, Http.Header>}: match k: case True{}: %ek : {Http.fields.put(_, h, Http.fields.of(f, Http.fields.of(f, t))) @@ -70,9 +72,10 @@ def hd.idem.put(+f: Http.Field, +k: Bool, +h: Http.Header, +t: List<&2, ih # the fields of a name among the fields of that name are all of them -def hd.idem(+f: Http.Field, +hs: List<&2, Http.Header>) - -> {Http.fields.of(f, Http.fields.of(f, hs)) - == Http.fields.of(f, hs) : List<&2, Http.Header>}: +def hd.idem( + +f: Http.Field, + +hs: List<&2, Http.Header> +) -> {Http.fields.of(f, Http.fields.of(f, hs)) == Http.fields.of(f, hs) : List<&2, Http.Header>}: match hs: case []: {==} @@ -82,12 +85,13 @@ def hd.idem(+f: Http.Field, +hs: List<&2, Http.Header>) # a slot holds itself when the caller's list and the default are all of a # name -def hd.or_keep(+f: Http.Field, +given: List<&2, Http.Header>, +d: List<&2, - Http.Header>, +def hd.or_keep( + +f: Http.Field, + +given: List<&2, Http.Header>, + +d: List<&2, Http.Header>, +eg: {Http.fields.of(f, given) == given : List<&2, Http.Header>}, - +ed: {Http.fields.of(f, d) == d : List<&2, Http.Header>}) - -> {Http.fields.or(given, d) - == Http.fields.of(f, Http.fields.or(given, d)) : List<&2, Http.Header>}: + +ed: {Http.fields.of(f, d) == d : List<&2, Http.Header>} +) -> {Http.fields.or(given, d) == Http.fields.of(f, Http.fields.or(given, d)) : List<&2, Http.Header>}: match given: case []: Equal.sym(List<&2, Http.Header>, Http.fields.of(f, d), d, ed) @@ -95,10 +99,12 @@ def hd.or_keep(+f: Http.Field, +given: List<&2, Http.Header>, +d: List<&2, Equal.sym(List<&2, Http.Header>, Http.fields.of(f, h <> t), h <> t, eg) # a computed Content-Length is no other field -def hd.clen_gone(+f: Http.Field, - +efc: {False{} == Http.field.same(f, Http.FClen{}) : Bool}, +n: Nat, - +e: Bool) -> {[] == Http.fields.of(f, Http.clen.field(n, e)) : List<&2, - Http.Header>}: +def hd.clen_gone( + +f: Http.Field, + +efc: {False{} == Http.field.same(f, Http.FClen{}) : Bool}, + +n: Nat, + +e: Bool +) -> {[] == Http.fields.of(f, Http.clen.field(n, e)) : List<&2, Http.Header>}: match e: case True{}: {==} @@ -413,9 +419,11 @@ def Laws.fields_other(host, hs, body): hd.app_nil(Http.fields.of(Http.FOther{}, hs))) # string append is associative -def eq.app_assoc(+a: String, +b: String, +c: String) - -> {String.append(String.append(a, b), c) - == String.append(a, String.append(b, c)) : String}: +def eq.app_assoc( + +a: String, + +b: String, + +c: String +) -> {String.append(String.append(a, b), c) == String.append(a, String.append(b, c)) : String}: match a: case SNil{}: {==} @@ -425,9 +433,11 @@ def eq.app_assoc(+a: String, +b: String, +c: String) String.append(t, String.append(b, c)), eq.app_assoc(t, b, c)) # the lines of an append are the lines of each part -def hd.lines_app(+a: List<&2, Http.Header>, +b: List<&2, Http.Header>) - -> {Http.headers.lines(List.append(&2, Http.Header, a, b)) - == String.append(Http.headers.lines(a), Http.headers.lines(b)) : String}: +def hd.lines_app( + +a: List<&2, Http.Header>, + +b: List<&2, Http.Header> +) -> {Http.headers.lines(List.append(&2, Http.Header, a, b)) == String.append(Http.headers.lines(a), + Http.headers.lines(b)) : String}: match a: case []: {==} @@ -453,16 +463,16 @@ def hd.lines_app(+a: List<&2, Http.Header>, +b: List<&2, Http.Header>) # with none of Host, User-Agent, Accept from the caller and only other # fields, the request's fields are the defaults, the caller's, Content-Length -def hd.plain_fields(+host: String, +hs: List<&2, Http.Header>, +body: String, +def hd.plain_fields( + +host: String, + +hs: List<&2, Http.Header>, + +body: String, +eh: {Http.fields.of(Http.FHost{}, hs) == [] : List<&2, Http.Header>}, +ea: {Http.fields.of(Http.FAgent{}, hs) == [] : List<&2, Http.Header>}, +ec: {Http.fields.of(Http.FAccept{}, hs) == [] : List<&2, Http.Header>}, - +eo: {Http.fields.of(Http.FOther{}, hs) == hs : List<&2, Http.Header>}) - -> {Http.request.fields(host, hs, body) == Http.H{"Host", host} - <> Http.H{"User-Agent", "ezhttp"} <> Http.H{"Accept", "*/*"} - <> Http.H{"Connection", "close"} - <> List.append(&2, Http.Header, hs, - Http.clen.field(Http.utf8.len(body), + +eo: {Http.fields.of(Http.FOther{}, hs) == hs : List<&2, Http.Header>} +) -> {Http.request.fields(host, hs, body) == Http.H{"Host", host} <> Http.H{"User-Agent", "ezhttp"} <> Http.H{"Accept", + "*/*"} <> Http.H{"Connection", "close"} <> List.append(&2, Http.Header, hs, Http.clen.field(Http.utf8.len(body), Nat.is_eq(Http.utf8.len(body), 0n))) : List<&2, Http.Header>}: %Equal.sym(List<&2, Http.Header>, Http.fields.of(Http.FHost{}, hs), [], eh) : {List.append(&2, Http.Header, Http.fields.or(_, [Http.H{"Host", host}]), @@ -528,17 +538,15 @@ def hd.plain_fields(+host: String, +hs: List<&2, Http.Header>, +body: String, {==} # the plain request's text after `Host: ` -def hd.plain_tail(+host: String, +hs: List<&2, Http.Header>, +body: String) - -> {String.append(String.append(String.append(host, "\r\n"), - Http.headers.lines(Http.H{"User-Agent", "ezhttp"} - <> Http.H{"Accept", "*/*"} <> Http.H{"Connection", "close"} - <> List.append(&2, Http.Header, hs, - Http.clen.field(Http.utf8.len(body), - Nat.is_eq(Http.utf8.len(body), 0n))))), "\r\n" ++ body) - == String.append(host, "\r\n" ++ "User-Agent: ezhttp\r\n" - ++ "Accept: */*\r\n" ++ "Connection: close\r\n" - ++ String.append(Http.headers.lines(hs), - String.append(Http.headers.lines(Http.clen.field(Http.utf8.len(body), +def hd.plain_tail( + +host: String, + +hs: List<&2, Http.Header>, + +body: String +) -> {String.append(String.append(String.append(host, "\r\n"), Http.headers.lines(Http.H{"User-Agent", "ezhttp"} + <> Http.H{"Accept", "*/*"} <> Http.H{"Connection", "close"} <> List.append(&2, Http.Header, hs, + Http.clen.field(Http.utf8.len(body), Nat.is_eq(Http.utf8.len(body), 0n))))), "\r\n" ++ body) == String.append(host, + "\r\n" ++ "User-Agent: ezhttp\r\n" ++ "Accept: */*\r\n" ++ "Connection: close\r\n" + ++ String.append(Http.headers.lines(hs), String.append(Http.headers.lines(Http.clen.field(Http.utf8.len(body), Nat.is_eq(Http.utf8.len(body), 0n))), "\r\n" ++ body))) : String}: Equal.trans(String, String.append(String.append(String.append(host, "\r\n"), diff --git a/proofs/RequestKeepsFieldNameSpelling.bend b/proofs/RequestKeepsFieldNameSpelling.bend index 8fd15d3..2201264 100644 --- a/proofs/RequestKeepsFieldNameSpelling.bend +++ b/proofs/RequestKeepsFieldNameSpelling.bend @@ -1,6 +1,14 @@ # proofs of laws/RequestKeepsFieldNameSpelling.bend import Base +import ../src/http.bend as Http import ../laws/RequestKeepsFieldNameSpelling.bend as Laws -def Laws.ask_keeps_field_name_spelling(): +def Laws.ask_keeps_field_name_spelling(_h, t, before, after, e, ef): + %e : {Http.head.cons(Http.head.from_cut(_), Http.head.list(t)) + == Http.H{before, String.trim(after)} <> Http.head.list(t) + : List<&2, Http.Header>} + %ef : {Http.head.cons(Http.field.keep(before, String.trim(after), _), + Http.head.list(t)) + == Http.H{before, String.trim(after)} <> Http.head.list(t) + : List<&2, Http.Header>} {==} diff --git a/proofs/RequestWithBothFramingsRejected.bend b/proofs/RequestWithBothFramingsRejected.bend index fed48c4..fcaaedb 100644 --- a/proofs/RequestWithBothFramingsRejected.bend +++ b/proofs/RequestWithBothFramingsRejected.bend @@ -1,6 +1,13 @@ # proofs of laws/RequestWithBothFramingsRejected.bend import Base +import ../src/http.bend as Http import ../laws/RequestWithBothFramingsRejected.bend as Laws -def Laws.ask_rejects_cl_and_te(): +def Laws.ask_rejects_cl_and_te(method, target, hs, te, l, ls, body, ea, ec): + %ea : {Http.ask.agree(method, target, hs, te, l <> ls, body, _) + == Http.Bad{"Content-Length and Transfer-Encoding conflict"} + : Http.Request} + %ec : {Http.ask.te(method, target, hs, l <> ls, body, _) + == Http.Bad{"Content-Length and Transfer-Encoding conflict"} + : Http.Request} {==} diff --git a/proofs/Respond200KeepsBody.bend b/proofs/Respond200KeepsBody.bend deleted file mode 100644 index 9fe4369..0000000 --- a/proofs/Respond200KeepsBody.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/Respond200KeepsBody.bend -import Base -import ../laws/Respond200KeepsBody.bend as Laws - -def Laws.respond_200_keeps_body(): - {==} diff --git a/proofs/Respond204DropsBody.bend b/proofs/Respond204DropsBody.bend deleted file mode 100644 index 5230a90..0000000 --- a/proofs/Respond204DropsBody.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/Respond204DropsBody.bend -import Base -import ../laws/Respond204DropsBody.bend as Laws - -def Laws.respond_204_drops_body(): - {==} diff --git a/proofs/Respond304DropsBody.bend b/proofs/Respond304DropsBody.bend deleted file mode 100644 index f293c9f..0000000 --- a/proofs/Respond304DropsBody.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/Respond304DropsBody.bend -import Base -import ../laws/Respond304DropsBody.bend as Laws - -def Laws.respond_304_drops_body(): - {==} diff --git a/proofs/ResponseCompleteByFraming.bend b/proofs/ResponseCompleteByFraming.bend index 6241084..ab68b34 100644 --- a/proofs/ResponseCompleteByFraming.bend +++ b/proofs/ResponseCompleteByFraming.bend @@ -3,6 +3,7 @@ import Base import ../src/http.bend as Http import ../laws/ResponseCompleteByFraming.bend as Laws import ./lemmas/BaseEqualities.bend as M1 +import ./lemmas/NatOrder.bend as M2 def Laws.whole_open(_f, _asked): {==} @@ -124,7 +125,7 @@ law has_len: def has_len(s, n): match s: case SNil{}: - {==} + M2.ge_not_lt(0n, n) case SCon{+h, +t}: +w = Http.octs.width(Char.to_u32(h)) has_len.arm(n, w, Http.octs.len(t), Http.octs.has(t, Nat.sub(n, w)), @@ -133,8 +134,8 @@ def has_len(s, n): def Laws.whole_bare(_body): {==} -def Laws.whole_sized(_n, _body): - {==} +def Laws.whole_sized(n, body): + M2.ge_not_lt(Http.octs.len(body), n) def Laws.whole_chunked(_body): {==} diff --git a/proofs/ResponseDisagreeingContentLengthsTorn.bend b/proofs/ResponseDisagreeingContentLengthsTorn.bend deleted file mode 100644 index d7639e7..0000000 --- a/proofs/ResponseDisagreeingContentLengthsTorn.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/ResponseDisagreeingContentLengthsTorn.bend -import Base -import ../laws/ResponseDisagreeingContentLengthsTorn.bend as Laws - -def Laws.parse_rejects_disagreeing_cl(): - {==} diff --git a/proofs/ResponseWithBothFramingsTorn.bend b/proofs/ResponseWithBothFramingsTorn.bend deleted file mode 100644 index b79381a..0000000 --- a/proofs/ResponseWithBothFramingsTorn.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/ResponseWithBothFramingsTorn.bend -import Base -import ../laws/ResponseWithBothFramingsTorn.bend as Laws - -def Laws.parse_rejects_cl_and_te(): - {==} diff --git a/proofs/SetCookieParsesBack.bend b/proofs/SetCookieParsesBack.bend index 10c31c5..63149d6 100644 --- a/proofs/SetCookieParsesBack.bend +++ b/proofs/SetCookieParsesBack.bend @@ -1,6 +1,47 @@ # proofs of laws/SetCookieParsesBack.bend import Base +import ../src/cookie.bend as Cookie import ../laws/SetCookieParsesBack.bend as Laws -def Laws.cookie_parse_round_trip(): +def Laws.cookie_parse(_line): + {==} + +def Laws.cookie_parse_parts(_h, _t): + {==} + +def Laws.cookie_from_cut(_pair, _attrs, _before, _after): + {==} + +def Laws.cookie_from_named(_name, _value, _attrs): + {==} + +def Laws.cookie_new(_name, _value): + {==} + +def Laws.cookie_fold_nil(_ps, c, e): + %e : {Cookie.cookie.fold(_, c) == c : Cookie.Cookie} + {==} + +def Laws.cookie_fold_cons(_h, _t, _c): + {==} + +def Laws.cookie_apply(_c, _piece): + {==} + +def Laws.cookie_apply_named(_c, _piece, _before, _after): + {==} + +def Laws.cookie_apply_flag(_c, _piece): + {==} + +def Laws.cookie_named_expires(_c, _value): + {==} + +def Laws.cookie_named_path(_c, _value): + {==} + +def Laws.cookie_flag_secure(_c): + {==} + +def Laws.cookie_flag_http_only(_c): {==} diff --git a/proofs/SplitAtCharacter.bend b/proofs/SplitAtCharacter.bend index 4575f94..47b3444 100644 --- a/proofs/SplitAtCharacter.bend +++ b/proofs/SplitAtCharacter.bend @@ -2,5 +2,3 @@ import Base import ../laws/SplitAtCharacter.bend as Laws import ./lemmas/BaseEqualities.bend as M1 - - diff --git a/proofs/StaleAtMaxAge.bend b/proofs/StaleAtMaxAge.bend deleted file mode 100644 index a88e80d..0000000 --- a/proofs/StaleAtMaxAge.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/StaleAtMaxAge.bend -import Base -import ../laws/StaleAtMaxAge.bend as Laws - -def Laws.fresh_max_age_limit(): - {==} diff --git a/proofs/UnescapeUndoesEscape.bend b/proofs/UnescapeUndoesEscape.bend index 38c218e..a90d984 100644 --- a/proofs/UnescapeUndoesEscape.bend +++ b/proofs/UnescapeUndoesEscape.bend @@ -25,8 +25,11 @@ def eq.cmp.gt(e: {GT{} == EQ{} : Cmp}) -> Empty: %e : eq.cmp.emp(_) Unit{} -def eq.bool_cmp_eq(a: Bool, b: Bool, e: {Bool.cmp(a, b) == EQ{} : Cmp}) - -> {a == b : Bool}: +def eq.bool_cmp_eq( + a: Bool, + b: Bool, + e: {Bool.cmp(a, b) == EQ{} : Cmp} +) -> {a == b : Bool}: match a b: case False{} False{}: {==} @@ -37,8 +40,12 @@ def eq.bool_cmp_eq(a: Bool, b: Bool, e: {Bool.cmp(a, b) == EQ{} : Cmp}) case True{} True{}: {==} -def eq.fin.t(ab: Bool, bb: Bool, t: Cmp, - e: {Word.cmp.fin(ab, bb, t) == EQ{} : Cmp}) -> {t == EQ{} : Cmp}: +def eq.fin.t( + ab: Bool, + bb: Bool, + t: Cmp, + e: {Word.cmp.fin(ab, bb, t) == EQ{} : Cmp} +) -> {t == EQ{} : Cmp}: match t: case LT{}: M1.eq.bit.gone(&2, {LT{} == EQ{} : Cmp}, eq.cmp.lt(e)) @@ -47,8 +54,12 @@ def eq.fin.t(ab: Bool, bb: Bool, t: Cmp, case GT{}: M1.eq.bit.gone(&2, {GT{} == EQ{} : Cmp}, eq.cmp.gt(e)) -def eq.fin.b(ab: Bool, bb: Bool, t: Cmp, - e: {Word.cmp.fin(ab, bb, t) == EQ{} : Cmp}) -> {Bool.cmp(ab, bb) == EQ{} : Cmp}: +def eq.fin.b( + ab: Bool, + bb: Bool, + t: Cmp, + e: {Word.cmp.fin(ab, bb, t) == EQ{} : Cmp} +) -> {Bool.cmp(ab, bb) == EQ{} : Cmp}: match t: case LT{}: M1.eq.bit.gone(&2, {Bool.cmp(ab, bb) == EQ{} : Cmp}, eq.cmp.lt(e)) @@ -57,8 +68,12 @@ def eq.fin.b(ab: Bool, bb: Bool, t: Cmp, case GT{}: M1.eq.bit.gone(&2, {Bool.cmp(ab, bb) == EQ{} : Cmp}, eq.cmp.gt(e)) -def eq.word_cmp_eq(n: Nat, a: Word(n), b: Word(n), - +e: {Word.cmp(n, a, b) == EQ{} : Cmp}) -> {a == b : Word(n)}: +def eq.word_cmp_eq( + n: Nat, + a: Word(n), + b: Word(n), + +e: {Word.cmp(n, a, b) == EQ{} : Cmp} +) -> {a == b : Word(n)}: match n: case 0n: match a b: @@ -73,8 +88,10 @@ def eq.word_cmp_eq(n: Nat, a: Word(n), b: Word(n), %we : {WCon{ab, at} == WCon{ab, _} : Word(1n+p)} {==} -def eq.cmp_is_eq(t: Cmp, e: {Cmp.is_eq(t) == True{} : Bool}) - -> {t == EQ{} : Cmp}: +def eq.cmp_is_eq( + t: Cmp, + e: {Cmp.is_eq(t) == True{} : Bool} +) -> {t == EQ{} : Cmp}: match t: case LT{}: M1.eq.bit.absurd(&2, {LT{} == EQ{} : Cmp}, e) @@ -83,8 +100,11 @@ def eq.cmp_is_eq(t: Cmp, e: {Cmp.is_eq(t) == True{} : Bool}) case GT{}: M1.eq.bit.absurd(&2, {GT{} == EQ{} : Cmp}, e) -def eq.char_eq_true(c: Char, d: Char, e: {Char.is_eq(c, d) == True{} : Bool}) - -> {c == d : Char}: +def eq.char_eq_true( + c: Char, + d: Char, + e: {Char.is_eq(c, d) == True{} : Bool} +) -> {c == d : Char}: match c d: case Chr{U32{+w}} Chr{U32{+v}}: we = eq.word_cmp_eq(32n, w, v, eq.cmp_is_eq(Word.cmp(32n, w, v), e)) @@ -92,17 +112,22 @@ def eq.char_eq_true(c: Char, d: Char, e: {Char.is_eq(c, d) == True{} : Bool}) {==} # a character that is not `&`, `<`, `>`, `"` or `'` scans as itself -def rt.other(+c: Char, x: String, e: {False{} == Char.is_eq(c, '&') : Bool}) - -> {Ref.scan(SCon{c, x}, Ref.Txt{}) == SCon{c, Ref.scan(x, Ref.Txt{})} - : String}: +def rt.other( + +c: Char, + x: String, + e: {False{} == Char.is_eq(c, '&') : Bool} +) -> {Ref.scan(SCon{c, x}, Ref.Txt{}) == SCon{c, Ref.scan(x, Ref.Txt{})} : String}: %e : {Ref.text.of(c, st2 => Ref.scan(x, st2), _) == SCon{c, Ref.scan(x, Ref.Txt{})} : String} {==} -def rt.sq(+c: Char, x: String, ea: {False{} == Char.is_eq(c, '&') : Bool}, - b: Bool, e: {Char.is_eq(c, '\'') == b : Bool}) - -> {Ref.scan(Html.one.sq(c, x, b), Ref.Txt{}) - == SCon{c, Ref.scan(x, Ref.Txt{})} : String}: +def rt.sq( + +c: Char, + x: String, + ea: {False{} == Char.is_eq(c, '&') : Bool}, + b: Bool, + e: {Char.is_eq(c, '\'') == b : Bool} +) -> {Ref.scan(Html.one.sq(c, x, b), Ref.Txt{}) == SCon{c, Ref.scan(x, Ref.Txt{})} : String}: match b: case True{}: ce = Equal.sym(Char, c, '\'', eq.char_eq_true(c, '\'', e)) @@ -112,10 +137,13 @@ def rt.sq(+c: Char, x: String, ea: {False{} == Char.is_eq(c, '&') : Bool}, case False{}: rt.other(c, x, ea) -def rt.dq(+c: Char, x: String, ea: {False{} == Char.is_eq(c, '&') : Bool}, - b: Bool, e: {Char.is_eq(c, '"') == b : Bool}) - -> {Ref.scan(Html.one.dq(c, x, b), Ref.Txt{}) - == SCon{c, Ref.scan(x, Ref.Txt{})} : String}: +def rt.dq( + +c: Char, + x: String, + ea: {False{} == Char.is_eq(c, '&') : Bool}, + b: Bool, + e: {Char.is_eq(c, '"') == b : Bool} +) -> {Ref.scan(Html.one.dq(c, x, b), Ref.Txt{}) == SCon{c, Ref.scan(x, Ref.Txt{})} : String}: match b: case True{}: ce = Equal.sym(Char, c, '"', eq.char_eq_true(c, '"', e)) @@ -125,10 +153,13 @@ def rt.dq(+c: Char, x: String, ea: {False{} == Char.is_eq(c, '&') : Bool}, case False{}: rt.sq(c, x, ea, Char.is_eq(c, '\''), {==}) -def rt.gt(+c: Char, x: String, ea: {False{} == Char.is_eq(c, '&') : Bool}, - b: Bool, e: {Char.is_eq(c, '>') == b : Bool}) - -> {Ref.scan(Html.one.gt(c, x, b), Ref.Txt{}) - == SCon{c, Ref.scan(x, Ref.Txt{})} : String}: +def rt.gt( + +c: Char, + x: String, + ea: {False{} == Char.is_eq(c, '&') : Bool}, + b: Bool, + e: {Char.is_eq(c, '>') == b : Bool} +) -> {Ref.scan(Html.one.gt(c, x, b), Ref.Txt{}) == SCon{c, Ref.scan(x, Ref.Txt{})} : String}: match b: case True{}: ce = Equal.sym(Char, c, '>', eq.char_eq_true(c, '>', e)) @@ -138,10 +169,13 @@ def rt.gt(+c: Char, x: String, ea: {False{} == Char.is_eq(c, '&') : Bool}, case False{}: rt.dq(c, x, ea, Char.is_eq(c, '"'), {==}) -def rt.lt(+c: Char, x: String, ea: {False{} == Char.is_eq(c, '&') : Bool}, - b: Bool, e: {Char.is_eq(c, '<') == b : Bool}) - -> {Ref.scan(Html.one.lt(c, x, b), Ref.Txt{}) - == SCon{c, Ref.scan(x, Ref.Txt{})} : String}: +def rt.lt( + +c: Char, + x: String, + ea: {False{} == Char.is_eq(c, '&') : Bool}, + b: Bool, + e: {Char.is_eq(c, '<') == b : Bool} +) -> {Ref.scan(Html.one.lt(c, x, b), Ref.Txt{}) == SCon{c, Ref.scan(x, Ref.Txt{})} : String}: match b: case True{}: ce = Equal.sym(Char, c, '<', eq.char_eq_true(c, '<', e)) @@ -151,9 +185,12 @@ def rt.lt(+c: Char, x: String, ea: {False{} == Char.is_eq(c, '&') : Bool}, case False{}: rt.gt(c, x, ea, Char.is_eq(c, '>'), {==}) -def rt.amp(+c: Char, x: String, b: Bool, e: {Char.is_eq(c, '&') == b : Bool}) - -> {Ref.scan(Html.one.amp(c, x, b), Ref.Txt{}) - == SCon{c, Ref.scan(x, Ref.Txt{})} : String}: +def rt.amp( + +c: Char, + x: String, + b: Bool, + e: {Char.is_eq(c, '&') == b : Bool} +) -> {Ref.scan(Html.one.amp(c, x, b), Ref.Txt{}) == SCon{c, Ref.scan(x, Ref.Txt{})} : String}: match b: case True{}: ce = Equal.sym(Char, c, '&', eq.char_eq_true(c, '&', e)) @@ -164,8 +201,9 @@ def rt.amp(+c: Char, x: String, b: Bool, e: {Char.is_eq(c, '&') == b : Bool}) rt.lt(c, x, Equal.sym(Bool, Char.is_eq(c, '&'), False{}, e), Char.is_eq(c, '<'), {==}) -def rt.go(s: String) - -> {Ref.scan(Html.escape.onto(s, ""), Ref.Txt{}) == s : String}: +def rt.go( + s: String +) -> {Ref.scan(Html.escape.onto(s, ""), Ref.Txt{}) == s : String}: match s: case SNil{}: {==} diff --git a/proofs/UnknownStatusHasEmptyReason.bend b/proofs/UnknownStatusHasEmptyReason.bend deleted file mode 100644 index b60d6a5..0000000 --- a/proofs/UnknownStatusHasEmptyReason.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/UnknownStatusHasEmptyReason.bend -import Base -import ../laws/UnknownStatusHasEmptyReason.bend as Laws - -def Laws.reason_unknown_empty(): - {==} diff --git a/proofs/UrlBadPortUsesDefault.bend b/proofs/UrlBadPortUsesDefault.bend index 4865f23..fbf3ebc 100644 --- a/proofs/UrlBadPortUsesDefault.bend +++ b/proofs/UrlBadPortUsesDefault.bend @@ -1,6 +1,8 @@ # proofs of laws/UrlBadPortUsesDefault.bend import Base +import ../src/url.bend as Url import ../laws/UrlBadPortUsesDefault.bend as Laws -def Laws.url_bad_port_uses_default(): +def Laws.port_junk(_host, _port, _rest, scheme, e): + %e : {Url.port.num(_, scheme) == Url.dflt(scheme) : U32} {==} diff --git a/proofs/UrlEmptyPath.bend b/proofs/UrlEmptyPath.bend index 992e95a..61426f5 100644 --- a/proofs/UrlEmptyPath.bend +++ b/proofs/UrlEmptyPath.bend @@ -2,5 +2,5 @@ import Base import ../laws/UrlEmptyPath.bend as Laws -def Laws.url_empty_path(): +def Laws.path_empty(_authority): {==} diff --git a/proofs/UrlFragmentHidesQuery.bend b/proofs/UrlFragmentHidesQuery.bend index 80b8e9b..2571b3a 100644 --- a/proofs/UrlFragmentHidesQuery.bend +++ b/proofs/UrlFragmentHidesQuery.bend @@ -1,6 +1,8 @@ # proofs of laws/UrlFragmentHidesQuery.bend import Base +import ../src/url.bend as Url import ../laws/UrlFragmentHidesQuery.bend as Laws -def Laws.url_fragment_hides_query(): +def Laws.frag_first(_s, hier, _rest, e): + %e : {Url.frag.drop.of(_) == hier : String} {==} diff --git a/proofs/UrlHttpDefaultPort.bend b/proofs/UrlHttpDefaultPort.bend index 1db4626..0bd747d 100644 --- a/proofs/UrlHttpDefaultPort.bend +++ b/proofs/UrlHttpDefaultPort.bend @@ -2,5 +2,5 @@ import Base import ../laws/UrlHttpDefaultPort.bend as Laws -def Laws.url_http_default_port(): +def Laws.port_absent(_host, _scheme): {==} diff --git a/proofs/UrlHttpsDefaultPort.bend b/proofs/UrlHttpsDefaultPort.bend deleted file mode 100644 index ae31dc5..0000000 --- a/proofs/UrlHttpsDefaultPort.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/UrlHttpsDefaultPort.bend -import Base -import ../laws/UrlHttpsDefaultPort.bend as Laws - -def Laws.url_https_default_port(): - {==} diff --git a/proofs/UrlHttpsExplicitPort.bend b/proofs/UrlHttpsExplicitPort.bend index b4c1bfa..8f1a0f9 100644 --- a/proofs/UrlHttpsExplicitPort.bend +++ b/proofs/UrlHttpsExplicitPort.bend @@ -1,6 +1,8 @@ # proofs of laws/UrlHttpsExplicitPort.bend import Base +import ../src/url.bend as Url import ../laws/UrlHttpsExplicitPort.bend as Laws -def Laws.url_https_explicit_port(): +def Laws.port_explicit(_host, _port, _rest, n, scheme, e): + %e : {Url.port.num(_, scheme) == n : U32} {==} diff --git a/proofs/UrlIpv4Host.bend b/proofs/UrlIpv4Host.bend index aa802c8..72acb0b 100644 --- a/proofs/UrlIpv4Host.bend +++ b/proofs/UrlIpv4Host.bend @@ -2,5 +2,5 @@ import Base import ../laws/UrlIpv4Host.bend as Laws -def Laws.url_ipv4_host(): +def Laws.host_before_colon(_host, _rest): {==} diff --git a/proofs/UrlIpv4Port.bend b/proofs/UrlIpv4Port.bend deleted file mode 100644 index a75b59b..0000000 --- a/proofs/UrlIpv4Port.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/UrlIpv4Port.bend -import Base -import ../laws/UrlIpv4Port.bend as Laws - -def Laws.url_ipv4_port(): - {==} diff --git a/proofs/UrlQueryDropsFragment.bend b/proofs/UrlQueryDropsFragment.bend deleted file mode 100644 index f78e9c3..0000000 --- a/proofs/UrlQueryDropsFragment.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/UrlQueryDropsFragment.bend -import Base -import ../laws/UrlQueryDropsFragment.bend as Laws - -def Laws.url_query_drops_fragment(): - {==} diff --git a/proofs/UrlQueryKeepsQuestion.bend b/proofs/UrlQueryKeepsQuestion.bend index 8cd1d2c..55c54d6 100644 --- a/proofs/UrlQueryKeepsQuestion.bend +++ b/proofs/UrlQueryKeepsQuestion.bend @@ -2,5 +2,8 @@ import Base import ../laws/UrlQueryKeepsQuestion.bend as Laws -def Laws.url_query_keeps_question(): +def Laws.query_hier_first(_hier, _rest): + {==} + +def Laws.query_keeps_question(_hier, _rest): {==} diff --git a/proofs/UrlQueryOnEmptyPath.bend b/proofs/UrlQueryOnEmptyPath.bend index 085e98a..09a003c 100644 --- a/proofs/UrlQueryOnEmptyPath.bend +++ b/proofs/UrlQueryOnEmptyPath.bend @@ -1,6 +1,8 @@ # proofs of laws/UrlQueryOnEmptyPath.bend import Base +import ../src/url.bend as Url import ../laws/UrlQueryOnEmptyPath.bend as Laws -def Laws.url_query_on_empty_path(): +def Laws.path_target_query(path, query, e): + %e : {Url.path.target.of(path, query, _) == path ++ "?" ++ query : String} {==} diff --git a/proofs/UrlSchemeLowercased.bend b/proofs/UrlSchemeLowercased.bend deleted file mode 100644 index 8560b5c..0000000 --- a/proofs/UrlSchemeLowercased.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/UrlSchemeLowercased.bend -import Base -import ../laws/UrlSchemeLowercased.bend as Laws - -def Laws.url_scheme_lowercased(): - {==} diff --git a/proofs/UrlTrailingSlash.bend b/proofs/UrlTrailingSlash.bend index e359be4..82372f2 100644 --- a/proofs/UrlTrailingSlash.bend +++ b/proofs/UrlTrailingSlash.bend @@ -2,5 +2,5 @@ import Base import ../laws/UrlTrailingSlash.bend as Laws -def Laws.url_trailing_slash(): +def Laws.path_rejoined(_authority, _segments): {==} diff --git a/proofs/UrlUserinfoLastAt.bend b/proofs/UrlUserinfoLastAt.bend index 8285f96..ffa9b61 100644 --- a/proofs/UrlUserinfoLastAt.bend +++ b/proofs/UrlUserinfoLastAt.bend @@ -1,6 +1,8 @@ # proofs of laws/UrlUserinfoLastAt.bend import Base +import ../src/url.bend as Url import ../laws/UrlUserinfoLastAt.bend as Laws -def Laws.url_userinfo_last_at(): +def Laws.host_after_last_at(_authority, hostport, e): + %e : {Url.auth.last.of(_) == hostport : String} {==} diff --git a/proofs/UrlUserinfoStripped.bend b/proofs/UrlUserinfoStripped.bend deleted file mode 100644 index 0ad4e77..0000000 --- a/proofs/UrlUserinfoStripped.bend +++ /dev/null @@ -1,6 +0,0 @@ -# proofs of laws/UrlUserinfoStripped.bend -import Base -import ../laws/UrlUserinfoStripped.bend as Laws - -def Laws.url_userinfo_stripped(): - {==} diff --git a/proofs/lemmas/BaseEqualities.bend b/proofs/lemmas/BaseEqualities.bend index 2e96cc8..d91e239 100644 --- a/proofs/lemmas/BaseEqualities.bend +++ b/proofs/lemmas/BaseEqualities.bend @@ -55,24 +55,32 @@ def eq.bit.gone(a, -A: Kind(a), e: Empty) -> A: def eq.bit.absurd(a, -A: Kind(a), e: {False{} == True{} : Bool}) -> A: eq.bit.gone(a, A, eq.bit.clash(e)) -def eq.and.left(u: Bool, v: Bool, e: {Bool.and(u, v) == True{} : Bool}) - -> {u == True{} : Bool}: +def eq.and.left( + u: Bool, + v: Bool, + e: {Bool.and(u, v) == True{} : Bool} +) -> {u == True{} : Bool}: match u: case True{}: {==} case False{}: e -def eq.and.right(u: Bool, v: Bool, e: {Bool.and(u, v) == True{} : Bool}) - -> {v == True{} : Bool}: +def eq.and.right( + u: Bool, + v: Bool, + e: {Bool.and(u, v) == True{} : Bool} +) -> {v == True{} : Bool}: match u: case True{}: e case False{}: eq.bit.absurd(&2, {v == True{} : Bool}, e) -def eq.not.true(u: Bool, e: {Bool.not(u) == True{} : Bool}) - -> {u == False{} : Bool}: +def eq.not.true( + u: Bool, + e: {Bool.not(u) == True{} : Bool} +) -> {u == False{} : Bool}: match u: case True{}: eq.bit.absurd(&2, {True{} == False{} : Bool}, e) @@ -86,8 +94,10 @@ def eq.starts_nil(s: String) -> {String.starts_with(s, "") == True{} : Bool}: case SCon{h, t}: {==} -def eq.starts_append(a: String, b: String) - -> {String.starts_with(String.append(a, b), a) == True{} : Bool}: +def eq.starts_append( + a: String, + b: String +) -> {String.starts_with(String.append(a, b), a) == True{} : Bool}: match a: case SNil{}: eq.starts_nil(b) diff --git a/proofs/lemmas/CookieStrings.bend b/proofs/lemmas/CookieStrings.bend new file mode 100644 index 0000000..9abbb87 --- /dev/null +++ b/proofs/lemmas/CookieStrings.bend @@ -0,0 +1,30 @@ +# a string against itself, for the cookie path rules: it starts with itself +# and orders equal to itself +import Base +import ./BaseEqualities.bend as M1 + +law order_self: + for +s: String + {String.order.go(s, s, EQ{}) == EQ{} : Cmp} + +def order_self(s): + match s: + case SNil{}: + {==} + case SCon{Chr{+x}, +t}: + %Equal.sym(Cmp, U32.cmp(x, x), EQ{}, M1.eq.u32_cmp_self(x)) + : {String.order.go(t, t, _) == EQ{} : Cmp} + order_self(t) + +law starts_self: + for +s: String + {String.starts_with.go(s, s) == True{} : Bool} + +def starts_self(s): + match s: + case SNil{}: + {==} + case SCon{+h, +t}: + %Equal.sym(Bool, Char.is_eq(h, h), True{}, M1.eq.char_eq_self(h)) + : {String.starts_with.go.if(t, t, _) == True{} : Bool} + starts_self(t) diff --git a/proofs/lemmas/CorsBool.bend b/proofs/lemmas/CorsBool.bend new file mode 100644 index 0000000..da2b24f --- /dev/null +++ b/proofs/lemmas/CorsBool.bend @@ -0,0 +1,13 @@ +# Boolean facts the CORS proofs use +import Base + +law and_false: + for b: Bool + {Bool.and(b, False{}) == False{} : Bool} + +def and_false(b): + match b: + case False{}: + {==} + case True{}: + {==} diff --git a/proofs/lemmas/HeaderFieldSlots.bend b/proofs/lemmas/HeaderFieldSlots.bend index a95edde..f1f3aa7 100644 --- a/proofs/lemmas/HeaderFieldSlots.bend +++ b/proofs/lemmas/HeaderFieldSlots.bend @@ -4,8 +4,11 @@ import ../../src/http.bend as Http import ./BaseEqualities.bend as M1 # two fields field.same calls the same are the same -def hd.same_sound(+a: Http.Field, +b: Http.Field, - +e: {True{} == Http.field.same(a, b) : Bool}) -> {a == b : Http.Field}: +def hd.same_sound( + +a: Http.Field, + +b: Http.Field, + +e: {True{} == Http.field.same(a, b) : Bool} +) -> {a == b : Http.Field}: match a: case Http.FHost{}: match b: @@ -122,17 +125,20 @@ def hd.same_sound(+a: Http.Field, +b: Http.Field, case Http.FOther{}: {==} +# two header lists, one after the other +def hd.cat(a: List<&2, Http.Header>, b: List<&2, Http.Header>) -> List<&2, Http.Header>: + List.append(&2, Http.Header, a, b) + # one step of of_app: the head kept or not -def hd.of_app.put(+f: Http.Field, +k: Bool, +h: Http.Header, +t: List<&2, - Http.Header>, +b: List<&2, Http.Header>, - +ih: {Http.fields.of(f, List.append(&2, Http.Header, t, b)) - == List.append(&2, Http.Header, Http.fields.of(f, t), - Http.fields.of(f, b)) : List<&2, Http.Header>}) - -> {Http.fields.put(k, h, - Http.fields.of(f, List.append(&2, Http.Header, t, b))) - == List.append(&2, Http.Header, - Http.fields.put(k, h, Http.fields.of(f, t)), - Http.fields.of(f, b)) : List<&2, Http.Header>}: +def hd.of_app.put( + +f: Http.Field, + +k: Bool, + +h: Http.Header, + +t: List<&2, Http.Header>, + +b: List<&2, Http.Header>, + +ih: {Http.fields.of(f, hd.cat(t, b)) == hd.cat(Http.fields.of(f, t), Http.fields.of(f, b)) : List<&2, Http.Header>} +) -> {Http.fields.put(k, h, Http.fields.of(f, hd.cat(t, b))) + == hd.cat(Http.fields.put(k, h, Http.fields.of(f, t)), Http.fields.of(f, b)) : List<&2, Http.Header>}: match k: case True{}: Equal.cong(List<&2, Http.Header>, List<&2, Http.Header>, x => h <> x, @@ -143,10 +149,11 @@ def hd.of_app.put(+f: Http.Field, +k: Bool, +h: Http.Header, +t: List<&2, ih # the fields of a name in an append are the ones in each part -def hd.of_app(+f: Http.Field, +a: List<&2, Http.Header>, +b: List<&2, - Http.Header>) - -> {Http.fields.of(f, List.append(&2, Http.Header, a, b)) - == List.append(&2, Http.Header, Http.fields.of(f, a), +def hd.of_app( + +f: Http.Field, + +a: List<&2, Http.Header>, + +b: List<&2, Http.Header> +) -> {Http.fields.of(f, List.append(&2, Http.Header, a, b)) == List.append(&2, Http.Header, Http.fields.of(f, a), Http.fields.of(f, b)) : List<&2, Http.Header>}: match a: case []: @@ -156,24 +163,28 @@ def hd.of_app(+f: Http.Field, +a: List<&2, Http.Header>, +b: List<&2, hd.of_app(f, t, b)) # of_app, the other way round -def hd.of_app.r(+f: Http.Field, +a: List<&2, Http.Header>, +b: List<&2, - Http.Header>) - -> {List.append(&2, Http.Header, Http.fields.of(f, a), Http.fields.of(f, b)) - == Http.fields.of(f, List.append(&2, Http.Header, a, b)) : List<&2, - Http.Header>}: +def hd.of_app.r( + +f: Http.Field, + +a: List<&2, Http.Header>, + +b: List<&2, Http.Header> +) -> {List.append(&2, Http.Header, Http.fields.of(f, a), Http.fields.of(f, b)) == Http.fields.of(f, List.append(&2, + Http.Header, a, b)) : List<&2, Http.Header>}: Equal.sym(List<&2, Http.Header>, Http.fields.of(f, List.append(&2, Http.Header, a, b)), List.append(&2, Http.Header, Http.fields.of(f, a), Http.fields.of(f, b)), hd.of_app(f, a, b)) # one step of disj -def hd.disj.put(+f: Http.Field, +g: Http.Field, - +efg: {False{} == Http.field.same(f, g) : Bool}, +k: Bool, +h: Http.Header, +def hd.disj.put( + +f: Http.Field, + +g: Http.Field, + +efg: {False{} == Http.field.same(f, g) : Bool}, + +k: Bool, + +h: Http.Header, +t: List<&2, Http.Header>, - +ek: {k == Http.field.same(g, Http.header.field(h)) : Bool}, - +ih: {Http.fields.of(f, Http.fields.of(g, t)) == [] : List<&2, Http.Header>}) - -> {Http.fields.of(f, Http.fields.put(k, h, Http.fields.of(g, t))) - == [] : List<&2, Http.Header>}: + +ek: {k == Http.field.same(g, Http.header.field(h)) : Bool}, + +ih: {Http.fields.of(f, Http.fields.of(g, t)) == [] : List<&2, Http.Header>} +) -> {Http.fields.of(f, Http.fields.put(k, h, Http.fields.of(g, t))) == [] : List<&2, Http.Header>}: match k: case True{}: %Equal.trans(Bool, False{}, Http.field.same(f, g), @@ -187,9 +198,12 @@ def hd.disj.put(+f: Http.Field, +g: Http.Field, ih # the fields of one name among the fields of another are none -def hd.disj(+f: Http.Field, +g: Http.Field, - +efg: {False{} == Http.field.same(f, g) : Bool}, +hs: List<&2, Http.Header>) - -> {Http.fields.of(f, Http.fields.of(g, hs)) == [] : List<&2, Http.Header>}: +def hd.disj( + +f: Http.Field, + +g: Http.Field, + +efg: {False{} == Http.field.same(f, g) : Bool}, + +hs: List<&2, Http.Header> +) -> {Http.fields.of(f, Http.fields.of(g, hs)) == [] : List<&2, Http.Header>}: match hs: case []: {==} @@ -199,12 +213,13 @@ def hd.disj(+f: Http.Field, +g: Http.Field, # a slot holds none of a name when neither the caller's list nor the default # does -def hd.or_gone(+f: Http.Field, +given: List<&2, Http.Header>, +d: List<&2, - Http.Header>, +def hd.or_gone( + +f: Http.Field, + +given: List<&2, Http.Header>, + +d: List<&2, Http.Header>, +eg: {Http.fields.of(f, given) == [] : List<&2, Http.Header>}, - +ed: {Http.fields.of(f, d) == [] : List<&2, Http.Header>}) - -> {[] == Http.fields.of(f, Http.fields.or(given, d)) : List<&2, - Http.Header>}: + +ed: {Http.fields.of(f, d) == [] : List<&2, Http.Header>} +) -> {[] == Http.fields.of(f, Http.fields.or(given, d)) : List<&2, Http.Header>}: match given: case []: Equal.sym(List<&2, Http.Header>, Http.fields.of(f, d), [], ed) @@ -212,10 +227,10 @@ def hd.or_gone(+f: Http.Field, +given: List<&2, Http.Header>, +d: List<&2, Equal.sym(List<&2, Http.Header>, Http.fields.of(f, h <> t), [], eg) # a computed Content-Length is a Content-Length field -def hd.clen_self(+n: Nat, +e: Bool) - -> {Http.clen.field(n, e) - == Http.fields.of(Http.FClen{}, Http.clen.field(n, e)) : List<&2, - Http.Header>}: +def hd.clen_self( + +n: Nat, + +e: Bool +) -> {Http.clen.field(n, e) == Http.fields.of(Http.FClen{}, Http.clen.field(n, e)) : List<&2, Http.Header>}: match e: case True{}: {==} @@ -223,28 +238,28 @@ def hd.clen_self(+n: Nat, +e: Bool) {==} # the fields of a name in a request's fields, slot by slot -def hd.of_fields(+f: Http.Field, +s1: List<&2, Http.Header>, +s2: List<&2, - Http.Header>, +s3: List<&2, Http.Header>, +o: List<&2, Http.Header>, +def hd.of_fields( + +f: Http.Field, + +s1: List<&2, Http.Header>, + +s2: List<&2, Http.Header>, + +s3: List<&2, Http.Header>, + +o: List<&2, Http.Header>, +c: List<&2, Http.Header>, - +r1: List<&2, Http.Header>, +r2: List<&2, Http.Header>, +r3: List<&2, - Http.Header>, +ro: List<&2, Http.Header>, +rc: List<&2, Http.Header>, + +r1: List<&2, Http.Header>, + +r2: List<&2, Http.Header>, + +r3: List<&2, Http.Header>, + +ro: List<&2, Http.Header>, + +rc: List<&2, Http.Header>, +e1: {r1 == Http.fields.of(f, s1) : List<&2, Http.Header>}, - +e2: {r2 == Http.fields.of(f, s2) : List<&2, Http.Header>}, + +e2: {r2 == Http.fields.of(f, s2) : List<&2, Http.Header>}, +e3: {r3 == Http.fields.of(f, s3) : List<&2, Http.Header>}, - +eo: {ro == Http.fields.of(f, o) : List<&2, Http.Header>}, - +ec: {rc == Http.fields.of(f, c) : List<&2, Http.Header>}) - -> {Http.fields.of(f, - List.append(&2, Http.Header, s1, - List.append(&2, Http.Header, s2, - List.append(&2, Http.Header, s3, Http.H{"Connection", "close"} - <> List.append(&2, Http.Header, o, c))))) - == List.append(&2, Http.Header, r1, - List.append(&2, Http.Header, r2, - List.append(&2, Http.Header, r3, - Http.fields.put(Http.field.same(f, - Http.header.field(Http.H{"Connection", "close"})), - Http.H{"Connection", "close"}, - List.append(&2, Http.Header, ro, rc))))) : List<&2, Http.Header>}: + +eo: {ro == Http.fields.of(f, o) : List<&2, Http.Header>}, + +ec: {rc == Http.fields.of(f, c) : List<&2, Http.Header>} +) -> {Http.fields.of(f, List.append(&2, Http.Header, s1, List.append(&2, Http.Header, s2, List.append(&2, Http.Header, + s3, Http.H{"Connection", "close"} <> List.append(&2, Http.Header, o, c))))) == List.append(&2, Http.Header, r1, + List.append(&2, Http.Header, r2, List.append(&2, Http.Header, r3, Http.fields.put(Http.field.same(f, + Http.header.field(Http.H{"Connection", "close"})), Http.H{"Connection", "close"}, List.append(&2, Http.Header, ro, + rc))))) : List<&2, Http.Header>}: %hd.of_app.r(f, s1, List.append(&2, Http.Header, s2, List.append(&2, Http.Header, s3, Http.H{"Connection", "close"} diff --git a/proofs/lemmas/NatOrder.bend b/proofs/lemmas/NatOrder.bend index 73c52f5..3fa6cbb 100644 --- a/proofs/lemmas/NatOrder.bend +++ b/proofs/lemmas/NatOrder.bend @@ -95,3 +95,24 @@ def take_all(s): sub_add(Http.octs.width(Char.to_u32(h)), Http.octs.len(t))), Equal.cong(String, String, x => SCon{h, x}, Http.octs.take(t, Http.octs.len(t)), t, take_all(t)))) + +law cmp_ge_not_lt: + for c: Cmp + {Cmp.is_ge(c) == Bool.not(Cmp.is_lt(c)) : Bool} + +def cmp_ge_not_lt(c): + match c: + case LT{}: + {==} + case EQ{}: + {==} + case GT{}: + {==} + +law ge_not_lt: + for a: Nat + for b: Nat + {Nat.is_ge(a, b) == Bool.not(Nat.is_lt(a, b)) : Bool} + +def ge_not_lt(a, b): + cmp_ge_not_lt(Nat.cmp(a, b)) diff --git a/proofs/lemmas/OctetTakeDrop.bend b/proofs/lemmas/OctetTakeDrop.bend index 19616cc..9eaac2a 100644 --- a/proofs/lemmas/OctetTakeDrop.bend +++ b/proofs/lemmas/OctetTakeDrop.bend @@ -6,8 +6,10 @@ import ../../laws/OneOctetPerChar.bend as L1 # --- octets after a prefix --- # the first |b| characters of b ++ r are b -def take_prefix(b: String, r: String) - -> {String.take(String.append(b, r), String.length(b)) == b : String}: +def take_prefix( + b: String, + r: String +) -> {String.take(String.append(b, r), String.length(b)) == b : String}: match b: case SNil{}: match r: diff --git a/proofs/lemmas/WalksOverAppendedText.bend b/proofs/lemmas/WalksOverAppendedText.bend index 712e38a..28d99ba 100644 --- a/proofs/lemmas/WalksOverAppendedText.bend +++ b/proofs/lemmas/WalksOverAppendedText.bend @@ -789,11 +789,11 @@ def divide_app(s, p, b, e): divide_app.arm(h, t, p, b, String.starts_with(SCon{h, t}, p), {==}, e, e2 => divide_app(t, p, b, e2)) -law lt0_add2: +law ge0_add2: for o: Nat - {Nat.is_lt(0n, Nat.add(o, 2n)) == True{} : Bool} + {Nat.is_ge(0n, Nat.add(o, 2n)) == False{} : Bool} -def lt0_add2(o): +def ge0_add2(o): match o: case 0n: {==} @@ -845,9 +845,7 @@ def walk_done.data.arm(g, after, n, sk, eh, et, ed, ih): match sk: case Http.Short{+o}: +hf = Equal.trans(Bool, Http.octs.has(after, Nat.add(n, 2n)), - Bool.not(Nat.is_lt(0n, Nat.add(o, 2n))), False{}, eh, - Equal.cong(Bool, Bool, x => Bool.not(x), Nat.is_lt(0n, Nat.add(o, 2n)), - True{}, lt0_add2(o))) + Nat.is_ge(0n, Nat.add(o, 2n)), False{}, eh, ge0_add2(o)) %Equal.sym(Bool, Http.octs.has(after, Nat.add(n, 2n)), False{}, hf) : {False{} == Http.chunks.ended.data(after, n, Bool.and(_, String.starts_with(Http.octs.drop(after, n), "\r\n")), diff --git a/src/body.bend b/src/body.bend index abc838e..2f9ef67 100644 --- a/src/body.bend +++ b/src/body.bend @@ -63,6 +63,9 @@ def body.encode(~A: Data, ~to_text: A -> String, value: A) -> Body: Plain{to_text(value)} # BYO decode: body text to a value via the caller's decoder -def body.decode(~A: Data, ~from_text: String -> Maybe<&2, A>, s: String) - -> Maybe<&2, A>: +def body.decode( + ~A: Data, + ~from_text: String -> Maybe<&2, A>, + s: String +) -> Maybe<&2, A>: from_text(s) diff --git a/src/cache.bend b/src/cache.bend index 3f2b904..2f5615b 100644 --- a/src/cache.bend +++ b/src/cache.bend @@ -140,7 +140,7 @@ def cache.note(value: String, expires: String) -> Cc: def cache.max_age(c: Cc) -> Bool: match c: case Cc{no_store, no_cache, public, private, max_age, expires}: - Bool.not(String.eq(max_age, "")) + Bool.not(String.is_empty(max_age)) # freshness from max-age. no-store and no-cache are not fresh. def cache.fresh.go(age: Nat, m: Maybe<&2, Nat>) -> Bool: @@ -159,8 +159,12 @@ def cache.fresh.cache(age: Nat, max_age: String, no_cache: Bool) -> Bool: cache.fresh.go(age, Http.digits.read(max_age)) # no-store is not reused -def cache.fresh.store(age: Nat, no_cache: Bool, max_age: String, no_store: Bool) - -> Bool: +def cache.fresh.store( + age: Nat, + no_cache: Bool, + max_age: String, + no_store: Bool +) -> Bool: match no_store: case True{}: False{} diff --git a/src/client.bend b/src/client.bend index 10fb707..3325d97 100644 --- a/src/client.bend +++ b/src/client.bend @@ -93,21 +93,31 @@ def http.send(ex: Spec.Exchange, tail: Bytes.Bytes) -> IO(Response): IO.pure(Response, http.answer(method, a)) # an exchange for a body of this shape, sent with the body's octets -def http.loc.shaped(method: String, l: Url.Loc, - headers: List<&2, Http.Header>, r: Body.Shape & Bytes.Bytes) - -> IO(Response): +def http.loc.shaped( + method: String, + l: Url.Loc, + headers: List<&2, Http.Header>, + r: Body.Shape & Bytes.Bytes +) -> IO(Response): (shape, tail) = r http.send(Spec.wire.exchange.body(method, l, headers, shape), tail) # a URL that came apart (or not) into an HTTP exchange with this body -def http.loc(method: String, l: Url.Loc, headers: List<&2, Http.Header>, - body: Body.Body) -> IO(Response): +def http.loc( + method: String, + l: Url.Loc, + headers: List<&2, Http.Header>, + body: Body.Body +) -> IO(Response): http.loc.shaped(method, l, headers, Body.body.shape(body)) # an exchange as wirespec.bend wrote it, bounded by a timeout, sent and read # by its own method -def http.send.timed(ms: U32, ex: Spec.Exchange, tail: Bytes.Bytes) - -> IO(Response): +def http.send.timed( + ms: U32, + ex: Spec.Exchange, + tail: Bytes.Bytes +) -> IO(Response): match ex: case Spec.NoUrl{why}: IO.pure(Response, Err{why}) @@ -118,22 +128,34 @@ def http.send.timed(ms: U32, ex: Spec.Exchange, tail: Bytes.Bytes) IO.pure(Response, http.answer(method, a)) # a timed exchange for a body of this shape -def client.timed.shaped(method: String, url: String, - headers: List<&2, Http.Header>, ms: U32, r: Body.Shape & Bytes.Bytes) - -> IO(Response): +def client.timed.shaped( + method: String, + url: String, + headers: List<&2, Http.Header>, + ms: U32, + r: Body.Shape & Bytes.Bytes +) -> IO(Response): (shape, tail) = r http.send.timed(ms, Spec.wire.exchange.body(method, Url.parse(url), headers, shape), tail) # a request with this method, headers and body, bounded by a timeout in # milliseconds -def client.timed(method: String, url: String, headers: List<&2, Http.Header>, - body: Body.Body, ms: U32) -> IO(Response): +def client.timed( + method: String, + url: String, + headers: List<&2, Http.Header>, + body: Body.Body, + ms: U32 +) -> IO(Response): client.timed.shaped(method, url, headers, ms, Body.body.shape(body)) # GET bounded by a timeout in milliseconds -def client.get.timed(url: String, headers: List<&2, Http.Header>, ms: U32) - -> IO(Response): +def client.get.timed( + url: String, + headers: List<&2, Http.Header>, + ms: U32 +) -> IO(Response): client.timed("GET", url, headers, Body.Empty{}, ms) # the next hop after a response (redirect.bend), and the response; a failed @@ -147,8 +169,10 @@ def client.hop(left: Nat, url: String, r: Response) -> Redirect.Hop & Response: Response{status, headers, reason, bytes}) # a response, or the GET its hop asks for -def client.after(p: Redirect.Hop & Response, go: String -> IO(Response)) - -> IO(Response): +def client.after( + p: Redirect.Hop & Response, + go: String -> IO(Response) +) -> IO(Response): (hop, r) = p match hop: case Redirect.Stop{}: @@ -169,8 +193,13 @@ def client.after(p: Redirect.Hop & Response, go: String -> IO(Response)) # state; every decision it acts on is src/redirect.bend's, proved under # laws/ (the redirect guarantees, such as # laws/RedirectsFollowLocation.bend). -def client.follow(+left: Nat, +url: String, +headers: List<&2, Http.Header>, - body: Body.Body, +ms: U32) -> IO(Response): +def client.follow( + +left: Nat, + +url: String, + +headers: List<&2, Http.Header>, + body: Body.Body, + +ms: U32 +) -> IO(Response): match left: case 0n: client.timed("GET", url, headers, body, ms) @@ -181,8 +210,14 @@ def client.follow(+left: Nat, +url: String, +headers: List<&2, Http.Header>, next => client.follow(p, next, headers, Body.Empty{}, ms)) # a request once it is known whether it follows redirects -def client.request.go(go: Bool, method: String, url: String, - headers: List<&2, Http.Header>, body: Body.Body, ms: U32) -> IO(Response): +def client.request.go( + go: Bool, + method: String, + url: String, + headers: List<&2, Http.Header>, + body: Body.Body, + ms: U32 +) -> IO(Response): match go: case True{}: client.follow(Redirect.redirect.max(), url, headers, body, ms) @@ -192,15 +227,24 @@ def client.request.go(go: Bool, method: String, url: String, # a request with a method, headers, body and timeout; it follows redirects # when `follow` is set and the method is GET (redirect.bend # redirect.follows), and answers its first response otherwise -def client.request.opts(+method: String, url: String, - headers: List<&2, Http.Header>, body: Body.Body, ms: U32, follow: Bool) - -> IO(Response): +def client.request.opts( + +method: String, + url: String, + headers: List<&2, Http.Header>, + body: Body.Body, + ms: U32, + follow: Bool +) -> IO(Response): client.request.go(Redirect.redirect.follows(method, follow), method, url, headers, body, ms) # GET with headers and a timeout, following redirects when `follow` is set -def client.get.opts(url: String, headers: List<&2, Http.Header>, ms: U32, - follow: Bool) -> IO(Response): +def client.get.opts( + url: String, + headers: List<&2, Http.Header>, + ms: U32, + follow: Bool +) -> IO(Response): client.request.opts("GET", url, headers, Body.Empty{}, ms, follow) # whether a response is the failure of an exchange that ran out of time @@ -220,18 +264,27 @@ def client.head(url: String, headers: List<&2, Http.Header>) -> IO(Response): http.loc("HEAD", Url.parse(url), headers, Body.Empty{}) # POST -def client.post(url: String, headers: List<&2, Http.Header>, body: Body.Body) - -> IO(Response): +def client.post( + url: String, + headers: List<&2, Http.Header>, + body: Body.Body +) -> IO(Response): http.loc("POST", Url.parse(url), headers, body) # PUT -def client.put(url: String, headers: List<&2, Http.Header>, body: Body.Body) - -> IO(Response): +def client.put( + url: String, + headers: List<&2, Http.Header>, + body: Body.Body +) -> IO(Response): http.loc("PUT", Url.parse(url), headers, body) # DELETE -def client.delete(url: String, headers: List<&2, Http.Header>, body: Body.Body) - -> IO(Response): +def client.delete( + url: String, + headers: List<&2, Http.Header>, + body: Body.Body +) -> IO(Response): http.loc("DELETE", Url.parse(url), headers, body) # OPTIONS diff --git a/src/cookie.bend b/src/cookie.bend index 69bc992..fb99a5a 100644 --- a/src/cookie.bend +++ b/src/cookie.bend @@ -138,8 +138,12 @@ def cookie.flag(c: Cookie, +name: String) -> Cookie: cookie.flag.secure(c, name, String.eq(name, "secure")) # SameSite, or an unrecognized attribute -def cookie.named.site(c: Cookie, _name: String, value: String, hit: Bool) - -> Cookie: +def cookie.named.site( + c: Cookie, + _name: String, + value: String, + hit: Bool +) -> Cookie: match hit: case True{}: cookie.site_set(c, cookie.site(value)) @@ -147,8 +151,12 @@ def cookie.named.site(c: Cookie, _name: String, value: String, hit: Bool) c # Path -def cookie.named.path(c: Cookie, +name: String, +value: String, hit: Bool) - -> Cookie: +def cookie.named.path( + c: Cookie, + +name: String, + +value: String, + hit: Bool +) -> Cookie: match hit: case True{}: cookie.dir(c, value) @@ -156,8 +164,12 @@ def cookie.named.path(c: Cookie, +name: String, +value: String, hit: Bool) cookie.named.site(c, name, value, String.eq(name, "samesite")) # Domain, stored lowercase -def cookie.named.domain(c: Cookie, +name: String, +value: String, hit: Bool) - -> Cookie: +def cookie.named.domain( + c: Cookie, + +name: String, + +value: String, + hit: Bool +) -> Cookie: match hit: case True{}: cookie.domain(c, String.to_lower(value)) @@ -165,8 +177,12 @@ def cookie.named.domain(c: Cookie, +name: String, +value: String, hit: Bool) cookie.named.path(c, name, value, String.eq(name, "path")) # Max-Age -def cookie.named.age(c: Cookie, +name: String, +value: String, hit: Bool) - -> Cookie: +def cookie.named.age( + c: Cookie, + +name: String, + +value: String, + hit: Bool +) -> Cookie: match hit: case True{}: cookie.age_ok(c, value, Http.digits.read(value)) @@ -174,8 +190,12 @@ def cookie.named.age(c: Cookie, +name: String, +value: String, hit: Bool) cookie.named.domain(c, name, value, String.eq(name, "domain")) # Expires, stored as the HTTP-date text -def cookie.named.expires(c: Cookie, +name: String, +value: String, hit: Bool) - -> Cookie: +def cookie.named.expires( + c: Cookie, + +name: String, + +value: String, + hit: Bool +) -> Cookie: match hit: case True{}: cookie.expires(c, value) @@ -207,8 +227,12 @@ def cookie.fold(ps: List<&2, String>, c: Cookie) -> Cookie: cookie.fold(t, cookie.apply(c, String.trim(h))) # reject an empty name (RFC 6265 §4.1.1) -def cookie.from.name(+name: String, value: String, attrs: List<&2, String>, - empty: Bool) -> Maybe<&2, Cookie>: +def cookie.from.name( + +name: String, + value: String, + attrs: List<&2, String>, + empty: Bool +) -> Maybe<&2, Cookie>: match empty: case True{}: None{} @@ -216,14 +240,17 @@ def cookie.from.name(+name: String, value: String, attrs: List<&2, String>, Some{cookie.fold(attrs, cookie.new(name, value))} # the name=value pair, then the attribute list -def cookie.from(_pair: String, attrs: List<&2, String>, cut: Http.Cut) - -> Maybe<&2, Cookie>: +def cookie.from( + _pair: String, + attrs: List<&2, String>, + cut: Http.Cut +) -> Maybe<&2, Cookie>: match cut: case Http.NoCut{}: None{} case Http.Cut{before, after}: +name = String.trim(before) - cookie.from.name(name, String.trim(after), attrs, String.eq(name, "")) + cookie.from.name(name, String.trim(after), attrs, String.is_empty(name)) # Set-Cookie split on `;` def cookie.parse.parts(ps: List<&2, String>) -> Maybe<&2, Cookie>: @@ -248,7 +275,7 @@ def cookie.opt.of(prefix: String, value: String, empty: Bool) -> String: # an optional attribute clause def cookie.opt(prefix: String, +value: String) -> String: - cookie.opt.of(prefix, value, String.eq(value, "")) + cookie.opt.of(prefix, value, String.is_empty(value)) # `; Domain=…` only when a Domain attribute was set def cookie.domain_text(domain: String, host_only: Bool) -> String: @@ -285,8 +312,12 @@ def cookie.set(c: Cookie) -> Http.Header: Http.H{"Set-Cookie", cookie.line(c)} # keep name=value when the name is not empty -def cookie.pairs.keep(name: String, value: String, empty: Bool, - rest: Unit -> List<&2, String>) -> List<&2, String>: +def cookie.pairs.keep( + name: String, + value: String, + empty: Bool, + rest: Unit -> List<&2, String> +) -> List<&2, String>: match empty: case True{}: rest(Unit{}) @@ -294,12 +325,14 @@ def cookie.pairs.keep(name: String, value: String, empty: Bool, (name ++ "=" ++ value) <> rest(Unit{}) # one cookie as a request pair, dropped when the name is empty -def cookie.pairs.one(c: Cookie, rest: Unit -> List<&2, String>) - -> List<&2, String>: +def cookie.pairs.one( + c: Cookie, + rest: Unit -> List<&2, String> +) -> List<&2, String>: match c: case Cookie{+name, value, expires, max_age, domain, path, secure, http_only, same_site, host_only}: - cookie.pairs.keep(name, value, String.eq(name, ""), rest) + cookie.pairs.keep(name, value, String.is_empty(name), rest) # name=value pieces, empty names removed def cookie.pairs(cs: List<&2, Cookie>) -> List<&2, String>: @@ -383,7 +416,7 @@ def cookie.fill_path.of(path: String, req: String, empty: Bool) -> String: # an absent Path becomes default-path def cookie.fill_path(+path: String, req: String) -> String: - cookie.fill_path.of(path, req, String.eq(path, "")) + cookie.fill_path.of(path, req, String.is_empty(path)) # store the response host on a host-only cookie and fill default-path def cookie.receive(host: String, req_path: String, c: Cookie) -> Cookie: @@ -396,8 +429,12 @@ def cookie.receive(host: String, req_path: String, c: Cookie) -> Cookie: host_only} # a dot continues the scan, a digit keeps it, anything else stops -def cookie.ipv4.step(dot: Bool, digit: Bool, if_dot: Unit -> Bool, - if_digit: Unit -> Bool) -> Bool: +def cookie.ipv4.step( + dot: Bool, + digit: Bool, + if_dot: Unit -> Bool, + if_digit: Unit -> Bool +) -> Bool: match dot digit: case True{} _: if_dot(Unit{}) @@ -494,8 +531,13 @@ def cookie.send.path(tls: Bool, secure: Bool, ok: Bool) -> Bool: cookie.send.secure(tls, secure) # domain-match, then path-match -def cookie.send.domain(req: String, tls: Bool, secure: Bool, cpath: String, - ok: Bool) -> Bool: +def cookie.send.domain( + req: String, + tls: Bool, + secure: Bool, + cpath: String, + ok: Bool +) -> Bool: match ok: case False{}: False{} @@ -523,8 +565,11 @@ def cookie.alive(max_age: String, age: Nat) -> Bool: cookie.alive.of(age, Http.digits.read(max_age)) # cons when the cookie matches the request -def cookie.select.cons(ok: Bool, c: Cookie, rest: Unit -> List<&2, Cookie>) - -> List<&2, Cookie>: +def cookie.select.cons( + ok: Bool, + c: Cookie, + rest: Unit -> List<&2, Cookie> +) -> List<&2, Cookie>: match ok: case False{}: rest(Unit{}) @@ -532,8 +577,12 @@ def cookie.select.cons(ok: Bool, c: Cookie, rest: Unit -> List<&2, Cookie>) c <> rest(Unit{}) # cookies that would be sent (domain, path, secure) -def cookie.select(cs: List<&2, Cookie>, +host: String, +req_path: String, - +tls: Bool) -> List<&2, Cookie>: +def cookie.select( + cs: List<&2, Cookie>, + +host: String, + +req_path: String, + +tls: Bool +) -> List<&2, Cookie>: match cs: case []: [] diff --git a/src/cors.bend b/src/cors.bend index 05ada25..c919906 100644 --- a/src/cors.bend +++ b/src/cors.bend @@ -72,8 +72,11 @@ def cors.acao.star(origin: String, star: Bool) -> String: origin # credentials always reflect the origin (Fetch: `*` cannot be used) -def cors.acao.cred(+os: List<&2, String>, origin: String, credentials: Bool) - -> String: +def cors.acao.cred( + +os: List<&2, String>, + origin: String, + credentials: Bool +) -> String: match credentials: case True{}: origin @@ -81,8 +84,12 @@ def cors.acao.cred(+os: List<&2, String>, origin: String, credentials: Bool) cors.acao.star(origin, cors.star(os)) # empty when the origin is not allowed -def cors.acao.ok(+os: List<&2, String>, credentials: Bool, origin: String, - ok: Bool) -> String: +def cors.acao.ok( + +os: List<&2, String>, + credentials: Bool, + origin: String, + ok: Bool +) -> String: match ok: case False{}: "" @@ -95,7 +102,7 @@ def cors.acao(+os: List<&2, String>, credentials: Bool, +origin: String) -> Stri # true when ACAO is a specific origin and Vary: Origin should be set def cors.vary(+acao: String) -> Bool: - Bool.and(Bool.not(String.eq(acao, "*")), Bool.not(String.eq(acao, ""))) + Bool.and(Bool.not(String.eq(acao, "*")), Bool.not(String.is_empty(acao))) # every requested header name is allowed. Empty means none were requested. def cors.names.step(ok: Bool, rest: Unit -> Bool) -> Bool: @@ -114,8 +121,11 @@ def cors.names(ps: List<&2, String>, +allow: List<&2, String>) -> Bool: cors.names.step(cors.hit_ci(String.trim(h), allow), _u => cors.names(t, allow)) # an empty request-header list asks for nothing -def cors.headers_empty(+requested: String, +allow: List<&2, String>, empty: Bool) - -> Bool: +def cors.headers_empty( + +requested: String, + +allow: List<&2, String>, + empty: Bool +) -> Bool: match empty: case True{}: True{} @@ -124,15 +134,18 @@ def cors.headers_empty(+requested: String, +allow: List<&2, String>, empty: Bool # Access-Control-Request-Headers, comma-separated def cors.headers_ok(+requested: String, +allow: List<&2, String>) -> Bool: - cors.headers_empty(requested, allow, String.eq(requested, "")) + cors.headers_empty(requested, allow, String.is_empty(requested)) # join with ", " def cors.join(xs: List<&2, String>) -> String: String.join(xs, ", ") # append Vary when the origin is reflected -def cors.vary_on(hs: List<&2, Http.Header>, _acao: String, vary: Bool) - -> List<&2, Http.Header>: +def cors.vary_on( + hs: List<&2, Http.Header>, + _acao: String, + vary: Bool +) -> List<&2, Http.Header>: match vary: case False{}: hs @@ -140,8 +153,10 @@ def cors.vary_on(hs: List<&2, Http.Header>, _acao: String, vary: Bool) Http.H{"Vary", "Origin"} <> hs # append credentials when they are allowed -def cors.cred_on(hs: List<&2, Http.Header>, credentials: Bool) - -> List<&2, Http.Header>: +def cors.cred_on( + hs: List<&2, Http.Header>, + credentials: Bool +) -> List<&2, Http.Header>: match credentials: case False{}: hs @@ -149,9 +164,13 @@ def cors.cred_on(hs: List<&2, Http.Header>, credentials: Bool) Http.H{"Access-Control-Allow-Credentials", "true"} <> hs # preflight response headers -def cors.preflight_hs(+acao: String, methods: List<&2, String>, - headers: List<&2, String>, credentials: Bool, max_age: String) - -> List<&2, Http.Header>: +def cors.preflight_hs( + +acao: String, + methods: List<&2, String>, + headers: List<&2, String>, + credentials: Bool, + max_age: String +) -> List<&2, Http.Header>: cors.cred_on(cors.vary_on([ Http.H{"Access-Control-Allow-Origin", acao}, Http.H{"Access-Control-Allow-Methods", cors.join(methods)}, @@ -160,9 +179,15 @@ def cors.preflight_hs(+acao: String, methods: List<&2, String>, ], acao, cors.vary(acao)), credentials) # 400 when a requested header is not allowed; otherwise 200 -def cors.preflight.headers(acao: String, methods: List<&2, String>, - headers: List<&2, String>, credentials: Bool, max_age: String, - _req: String, ok: Bool) -> Http.Reply: +def cors.preflight.headers( + acao: String, + methods: List<&2, String>, + headers: List<&2, String>, + credentials: Bool, + max_age: String, + _req: String, + ok: Bool +) -> Http.Reply: match ok: case False{}: Http.Reply{400, [], ""} @@ -171,9 +196,16 @@ def cors.preflight.headers(acao: String, methods: List<&2, String>, max_age), ""} # 400 when the method is not allowed -def cors.preflight.method(acao: String, methods: List<&2, String>, - +headers: List<&2, String>, credentials: Bool, max_age: String, - +req_headers: String, _method: String, ok: Bool) -> Http.Reply: +def cors.preflight.method( + acao: String, + methods: List<&2, String>, + +headers: List<&2, String>, + credentials: Bool, + max_age: String, + +req_headers: String, + _method: String, + ok: Bool +) -> Http.Reply: match ok: case False{}: Http.Reply{400, [], ""} @@ -182,9 +214,16 @@ def cors.preflight.method(acao: String, methods: List<&2, String>, req_headers, cors.headers_ok(req_headers, headers)) # skip the method check when the origin was refused -def cors.preflight.denied(acao: String, +methods: List<&2, String>, - headers: List<&2, String>, credentials: Bool, max_age: String, - req_headers: String, +method: String, denied: Bool) -> Http.Reply: +def cors.preflight.denied( + acao: String, + +methods: List<&2, String>, + headers: List<&2, String>, + credentials: Bool, + max_age: String, + req_headers: String, + +method: String, + denied: Bool +) -> Http.Reply: match denied: case True{}: Http.Reply{400, [], ""} @@ -193,17 +232,24 @@ def cors.preflight.denied(acao: String, +methods: List<&2, String>, req_headers, method, cors.hit(method, methods)) # OPTIONS preflight (Fetch CORS). Refused origins and methods are 400. -def cors.preflight(cfg: Cfg, origin: String, method: String, req_headers: String) - -> Http.Reply: +def cors.preflight( + cfg: Cfg, + origin: String, + method: String, + req_headers: String +) -> Http.Reply: match cfg: case Cfg{+origins, methods, headers, +credentials, max_age, expose}: +acao = cors.acao(origins, credentials, origin) cors.preflight.denied(acao, methods, headers, credentials, max_age, - req_headers, method, String.eq(acao, "")) + req_headers, method, String.is_empty(acao)) # Access-Control-Expose-Headers when the list is not empty -def cors.expose_of(hs: List<&2, Http.Header>, expose: List<&2, String>, - empty: Bool) -> List<&2, Http.Header>: +def cors.expose_of( + hs: List<&2, Http.Header>, + expose: List<&2, String>, + empty: Bool +) -> List<&2, Http.Header>: match empty: case True{}: hs @@ -211,20 +257,28 @@ def cors.expose_of(hs: List<&2, Http.Header>, expose: List<&2, String>, Http.H{"Access-Control-Expose-Headers", cors.join(expose)} <> hs # Access-Control-Expose-Headers when the list is not empty -def cors.expose_on(hs: List<&2, Http.Header>, +expose: List<&2, String>) - -> List<&2, Http.Header>: +def cors.expose_on( + hs: List<&2, Http.Header>, + +expose: List<&2, String> +) -> List<&2, Http.Header>: cors.expose_of(hs, expose, List.is_empty(&2, String, expose)) # simple-response CORS headers (ACAO, optional credentials, expose, vary) -def cors.simple_hs(+acao: String, credentials: Bool, expose: List<&2, String>) - -> List<&2, Http.Header>: +def cors.simple_hs( + +acao: String, + credentials: Bool, + expose: List<&2, String> +) -> List<&2, Http.Header>: cors.cred_on(cors.vary_on(cors.expose_on([ Http.H{"Access-Control-Allow-Origin", acao} ], expose), acao, cors.vary(acao)), credentials) # leave a reply alone when there is nothing to add -def cors.simple.skip(add: Bool, reply: Http.Reply, hs: List<&2, Http.Header>) - -> Http.Reply: +def cors.simple.skip( + add: Bool, + reply: Http.Reply, + hs: List<&2, Http.Header> +) -> Http.Reply: match add reply: case False{} r: r @@ -234,8 +288,13 @@ def cors.simple.skip(add: Bool, reply: Http.Reply, hs: List<&2, Http.Header>) Http.Reply{status, List.append(&2, Http.Header, hs, headers), body} # append CORS headers when the origin is allowed -def cors.simple.add(reply: Http.Reply, acao: String, credentials: Bool, - expose: List<&2, String>, add: Bool) -> Http.Reply: +def cors.simple.add( + reply: Http.Reply, + acao: String, + credentials: Bool, + expose: List<&2, String>, + add: Bool +) -> Http.Reply: cors.simple.skip(add, reply, cors.simple_hs(acao, credentials, expose)) # a non-preflight response. A missing or refused origin is unchanged. @@ -244,7 +303,7 @@ def cors.simple(cfg: Cfg, origin: String, reply: Http.Reply) -> Http.Reply: case Cfg{+origins, methods, headers, +credentials, max_age, expose}: +acao = cors.acao(origins, credentials, origin) cors.simple.add(reply, acao, credentials, expose, - Bool.not(String.eq(acao, ""))) + Bool.not(String.is_empty(acao))) # Origin request header def cors.origin(origin: String) -> Http.Header: @@ -260,7 +319,7 @@ def cors.request_headers(names: String) -> Http.Header: # OPTIONS with Access-Control-Request-Method is a preflight def cors.is_preflight.method(method: String, asked: String) -> Bool: - Bool.and(String.eq(method, "OPTIONS"), Bool.not(String.eq(asked, ""))) + Bool.and(String.eq(method, "OPTIONS"), Bool.not(String.is_empty(asked))) # whether this request is a CORS preflight def cors.is_preflight(req: Http.Request) -> Bool: @@ -290,8 +349,12 @@ def cors.simple_req(cfg: Cfg, req: Http.Request, reply: Http.Reply) -> Http.Repl cors.simple(cfg, Http.headers.find(headers, "origin"), reply) # preflight, or CORS headers on the handler reply -def cors.route(cfg: Cfg, req: Http.Request, +reply: Http.Reply, pre: Bool) - -> Http.Reply: +def cors.route( + cfg: Cfg, + req: Http.Request, + +reply: Http.Reply, + pre: Bool +) -> Http.Reply: match pre: case True{}: cors.preflight_req(cfg, req) diff --git a/src/echo.bend b/src/echo.bend index 8a6f73a..4dc1033 100644 --- a/src/echo.bend +++ b/src/echo.bend @@ -14,8 +14,12 @@ def wsp(+c: Char) -> Bool: # one character of the leading strip: dropped, and the strip goes on, when # it is WSP -def wsp.lead.if(t: String, +h: Char, space: Bool, rest: Unit -> String) - -> String: +def wsp.lead.if( + t: String, + +h: Char, + space: Bool, + rest: Unit -> String +) -> String: match space: case True{}: rest(Unit{}) @@ -61,8 +65,14 @@ def pair(line: String) -> Maybe<&2, Qs.Kv()>: # one stored cookie, once it is known whether it has the new one's name: # that one takes the new value in its place, any other is kept and the rest # of the store looked at -def put.at(key: String, old: String, value: String, t: List<&2, Qs.Kv()>, - hit: Bool, rest: Unit -> List<&2, Qs.Kv()>) -> List<&2, Qs.Kv()>: +def put.at( + key: String, + old: String, + value: String, + t: List<&2, Qs.Kv()>, + hit: Bool, + rest: Unit -> List<&2, Qs.Kv()> +) -> List<&2, Qs.Kv()>: match hit: case True{}: (key, value) <> t @@ -72,8 +82,11 @@ def put.at(key: String, old: String, value: String, t: List<&2, Qs.Kv()>, # a cookie put in a store: a stored one of the same name (compared exactly) # keeps its place and takes the new value (§5.3 step 11.3 keeps its # creation-time, which orders it, §5.4 step 2), else it goes after the others -def put(jar: List<&2, Qs.Kv()>, +name: String, +value: String) - -> List<&2, Qs.Kv()>: +def put( + jar: List<&2, Qs.Kv()>, + +name: String, + +value: String +) -> List<&2, Qs.Kv()>: match jar: case []: [(name, value)] @@ -90,8 +103,10 @@ def add(jar: List<&2, Qs.Kv()>, m: Maybe<&2, Qs.Kv()>) -> List<&2, Qs.Kv()>: put(jar, name, value) # a store after Set-Cookie field values, in the order they came -def store(lines: List<&2, String>, jar: List<&2, Qs.Kv()>) - -> List<&2, Qs.Kv()>: +def store( + lines: List<&2, String>, + jar: List<&2, Qs.Kv()> +) -> List<&2, Qs.Kv()>: match lines: case []: jar @@ -123,8 +138,11 @@ def echo(lines: List<&2, String>) -> String: line(store(lines, [])) # one header field: its value in front of the rest when it is Set-Cookie -def values.put(value: String, rest: List<&2, String>, hit: Bool) - -> List<&2, String>: +def values.put( + value: String, + rest: List<&2, String>, + hit: Bool +) -> List<&2, String>: match hit: case True{}: value <> rest diff --git a/src/form.bend b/src/form.bend index 6a59ae9..52d6072 100644 --- a/src/form.bend +++ b/src/form.bend @@ -45,8 +45,12 @@ def form.field(name: String, value: String) -> Upload: UField{name, value} # a file part: its field name, its filename, its content type and its bytes -def form.file(name: String, filename: String, ctype: String, - bytes: Bytes.Bytes) -> Upload: +def form.file( + name: String, + filename: String, + ctype: String, + bytes: Bytes.Bytes +) -> Upload: UFile{name, filename, ctype, bytes} # --- octets --- @@ -291,24 +295,32 @@ def form.found(r: Bytes.Bytes & Maybe<&2, U32>) -> Bytes.Bytes & Bool: # a file part once its bytes are searched: the part the plan sees, onto the # rest, and its bytes kept in order -def form.split.file(name: String, filename: String, ctype: String, - r: Bytes.Bytes & Bool, rest: List<&2, Part> & List<&1, Bytes.Bytes>) - -> List<&2, Part> & List<&1, Bytes.Bytes>: +def form.split.file( + name: String, + filename: String, + ctype: String, + r: Bytes.Bytes & Bool, + rest: List<&2, Part> & List<&1, Bytes.Bytes> +) -> List<&2, Part> & List<&1, Bytes.Bytes>: (bs, hit) = r (ps, fs) = rest (File{name, filename, ctype, hit} <> ps, bs <> fs) # a field part onto the rest -def form.split.field(name: String, value: String, - rest: List<&2, Part> & List<&1, Bytes.Bytes>) - -> List<&2, Part> & List<&1, Bytes.Bytes>: +def form.split.field( + name: String, + value: String, + rest: List<&2, Part> & List<&1, Bytes.Bytes> +) -> List<&2, Part> & List<&1, Bytes.Bytes>: (ps, fs) = rest (Field{name, value} <> ps, fs) # the parts as the plan sees them, and the files' bytes in order; `d` is # the delimiter's octets, one character each -def form.split(+d: String, us: List<&1, Upload>) - -> List<&2, Part> & List<&1, Bytes.Bytes>: +def form.split( + +d: String, + us: List<&1, Upload> +) -> List<&2, Part> & List<&1, Bytes.Bytes>: match us: case []: ([], []) @@ -321,8 +333,10 @@ def form.split(+d: String, us: List<&1, Upload>) form.found(Bytes.find(bytes, d)), form.split(d, t)) # the body's runs as packed octets, each file's bytes in its place -def form.runs(segs: List<&2, Seg>, fs: List<&1, Bytes.Bytes>) - -> List<&1, Bytes.Bytes>: +def form.runs( + segs: List<&2, Seg>, + fs: List<&1, Bytes.Bytes> +) -> List<&1, Bytes.Bytes>: match segs: case []: [] diff --git a/src/http.bend b/src/http.bend index c6c1157..3b816fc 100644 --- a/src/http.bend +++ b/src/http.bend @@ -43,8 +43,13 @@ def divide.push(h: Char, r: Cut) -> Cut: Cut{SCon{h, before}, after} # one step of the walk; rest is a thunk so Bool.pick does not force recursion -def divide.step(here: Bool, h: Char, t: String, n: Nat, - rest: Unit -> Cut) -> Cut: +def divide.step( + here: Bool, + h: Char, + t: String, + n: Nat, + rest: Unit -> Cut +) -> Cut: match here: case True{}: Cut{"", String.drop(SCon{h, t}, n)} @@ -173,8 +178,12 @@ def octs.take(s: String, +n: Nat) -> String: octs.take.step(Nat.is_lt(n, w), h, _u => octs.take(t, Nat.sub(n, w))) # one step of the drop -def octs.drop.step(short: Bool, h: Char, t: String, - rest: Unit -> String) -> String: +def octs.drop.step( + short: Bool, + h: Char, + t: String, + rest: Unit -> String +) -> String: match short: case True{}: SCon{h, t} @@ -240,7 +249,7 @@ def octs.has.step(short: Bool, rest: Unit -> Bool) -> Bool: def octs.has(s: String, +n: Nat) -> Bool: match s: case SNil{}: - Bool.not(Nat.is_lt(0n, n)) + Nat.is_ge(0n, n) case SCon{+h, t}: +w = octs.width(Char.to_u32(h)) octs.has.step(Nat.is_lt(n, w), _u => octs.has(t, Nat.sub(n, w))) @@ -331,8 +340,10 @@ def chunk.next(z: Size, +after: String) -> Next: chunk.next.data(after, n, chunks.ready(after, n)) # apply one scan step -def chunks.scan.step(step: Next, rest: Cut -> Maybe<&2, String>) - -> Maybe<&2, String>: +def chunks.scan.step( + step: Next, + rest: Cut -> Maybe<&2, String> +) -> Maybe<&2, String>: match step: case Stop{}: None{} @@ -352,8 +363,12 @@ def chunks.scan(fuel: Nat, c: Cut) -> Maybe<&2, String>: chunks.scan.step(chunks.next(before, after), cut => chunks.scan(f, cut)) # a zero chunk ends the body; anything after it is a trailer (RFC 9112 §7.1) -def chunks.more(+n: Nat, +after: String, rest: Unit -> String, zero: Bool) - -> String: +def chunks.more( + +n: Nat, + +after: String, + rest: Unit -> String, + zero: Bool +) -> String: match zero: case True{}: "" @@ -404,8 +419,11 @@ def head.value(h: String, name: String) -> String: String.trim(String.drop(h, Nat.add(String.length(name), 1n))) # cons a value when the line is the header asked for -def head.values.cons(hit: Bool, value: String, rest: Unit -> List<&2, String>) - -> List<&2, String>: +def head.values.cons( + hit: Bool, + value: String, + rest: Unit -> List<&2, String> +) -> List<&2, String>: match hit: case False{}: rest(Unit{}) @@ -598,8 +616,11 @@ def header.field(h: Header) -> Field: field.name(name) # keep a header in front of the rest, or not -def fields.put(keep: Bool, h: Header, rest: List<&2, Header>) - -> List<&2, Header>: +def fields.put( + keep: Bool, + h: Header, + rest: List<&2, Header> +) -> List<&2, Header>: match keep: case True{}: h <> rest @@ -615,8 +636,10 @@ def fields.of(+f: Field, hs: List<&2, Header>) -> List<&2, Header>: fields.put(field.same(f, header.field(h)), h, fields.of(f, t)) # the caller's fields of a name, or the default when it gave none -def fields.or(given: List<&2, Header>, dflt: List<&2, Header>) - -> List<&2, Header>: +def fields.or( + given: List<&2, Header>, + dflt: List<&2, Header> +) -> List<&2, Header>: match given: case []: dflt @@ -629,8 +652,11 @@ def fields.or(given: List<&2, Header>, dflt: List<&2, Header>) # A caller's Connection or Content-Length is not sent: Connection: close lets # the connection end frame the body when no Content-Length / chunked framing # applies (RFC 9112 §9.6 / §6.3), and the body's length is computed. -def request.fields.n(host: String, +hs: List<&2, Header>, +n: Nat) - -> List<&2, Header>: +def request.fields.n( + host: String, + +hs: List<&2, Header>, + +n: Nat +) -> List<&2, Header>: List.append(&2, Header, fields.or(fields.of(FHost{}, hs), [H{"Host", host}]), List.append(&2, Header, fields.or(fields.of(FAgent{}, hs), [H{"User-Agent", "ezhttp"}]), @@ -641,14 +667,22 @@ def request.fields.n(host: String, +hs: List<&2, Header>, +n: Nat) clen.field(n, Nat.is_eq(n, 0n)))))) # a request's header fields for a text body: the fields for its UTF-8 octets -def request.fields(host: String, +hs: List<&2, Header>, +body: String) - -> List<&2, Header>: +def request.fields( + host: String, + +hs: List<&2, Header>, + +body: String +) -> List<&2, Header>: request.fields.n(host, hs, utf8.len(body)) # a request-line and headers (RFC 9112 §3, §5). Absolute-path request-target # (RFC 9112 §3.2.1); the fields are request.fields'. -def request(method: String, host: String, path: String, - headers: List<&2, Header>, +body: String) -> String: +def request( + method: String, + host: String, + path: String, + headers: List<&2, Header>, + +body: String +) -> String: method ++ " " ++ path ++ " HTTP/1.1\r\n" ++ headers.lines(request.fields(host, headers, body)) ++ "\r\n" @@ -677,21 +711,40 @@ def authority(secure: Bool, host: String, +port: U32) -> String: authority.of(host, port, U32.is_eq(port, port.dflt(secure))) # the request a client sends to host and port, over TLS when secure -def request.at(method: String, secure: Bool, host: String, port: U32, - path: String, headers: List<&2, Header>, body: String) -> String: +def request.at( + method: String, + secure: Bool, + host: String, + port: U32, + path: String, + headers: List<&2, Header>, + body: String +) -> String: request(method, authority(secure, host, port), path, headers, body) # the request text for a body of n octets that is sent after it as its own # octets: the request line, the fields for n octets, and the blank line -def request.head(method: String, host: String, path: String, - headers: List<&2, Header>, +n: Nat) -> String: +def request.head( + method: String, + host: String, + path: String, + headers: List<&2, Header>, + +n: Nat +) -> String: method ++ " " ++ path ++ " HTTP/1.1\r\n" ++ headers.lines(request.fields.n(host, headers, n)) ++ "\r\n" # the request text a client sends to host and port ahead of n octets -def request.head.at(method: String, secure: Bool, host: String, port: U32, - path: String, headers: List<&2, Header>, n: Nat) -> String: +def request.head.at( + method: String, + secure: Bool, + host: String, + port: U32, + path: String, + headers: List<&2, Header>, + n: Nat +) -> String: request.head(method, authority(secure, host, port), path, headers, n) # GET with optional headers @@ -703,18 +756,30 @@ def head_req(host: String, path: String, headers: List<&2, Header>) -> String: request("HEAD", host, path, headers, "") # POST with body and optional headers -def post_req(host: String, path: String, headers: List<&2, Header>, - body: String) -> String: +def post_req( + host: String, + path: String, + headers: List<&2, Header>, + body: String +) -> String: request("POST", host, path, headers, body) # PUT with body and optional headers (RFC 9110 §9.3.4) -def put_req(host: String, path: String, headers: List<&2, Header>, - body: String) -> String: +def put_req( + host: String, + path: String, + headers: List<&2, Header>, + body: String +) -> String: request("PUT", host, path, headers, body) # DELETE with body and optional headers (RFC 9110 §9.3.5) -def delete_req(host: String, path: String, headers: List<&2, Header>, - body: String) -> String: +def delete_req( + host: String, + path: String, + headers: List<&2, Header>, + body: String +) -> String: request("DELETE", host, path, headers, body) # OPTIONS with optional headers (RFC 9110 §9.3.7). No request body. @@ -775,8 +840,13 @@ type Frame is Data: Closed{} # a body against the length its head promised -def parse.short(status: U32, headers: List<&2, Header>, n: Nat, body: String, - short: Bool) -> Reply: +def parse.short( + status: U32, + headers: List<&2, Header>, + n: Nat, + body: String, + short: Bool +) -> Reply: match short: case True{}: Torn{"the response body stopped before its Content-Length"} @@ -784,13 +854,21 @@ def parse.short(status: U32, headers: List<&2, Header>, n: Nat, body: String, Reply{status, headers, octs.take(body, n)} # a body framed by Content-Length (RFC 9110 §8.6 / RFC 9112 §6.3) -def parse.clen(status: U32, headers: List<&2, Header>, +n: Nat, +body: String) - -> Reply: +def parse.clen( + status: U32, + headers: List<&2, Header>, + +n: Nat, + +body: String +) -> Reply: parse.short(status, headers, n, body, Nat.is_lt(octs.len(body), n)) # Content-Length when present; else the rest of the connection is the body -def parse.len(status: U32, headers: List<&2, Header>, m: Maybe<&2, Nat>, - body: String) -> Reply: +def parse.len( + status: U32, + headers: List<&2, Header>, + m: Maybe<&2, Nat>, + body: String +) -> Reply: match m: case None{}: Reply{status, headers, body} @@ -830,8 +908,12 @@ def clen.any(vs: List<&2, String>) -> Bool: True{} # a chunked body, or why the chunk framing was rejected -def parse.chunked(status: U32, headers: List<&2, Header>, body: String, - bad: Maybe<&2, String>) -> Reply: +def parse.chunked( + status: U32, + headers: List<&2, Header>, + body: String, + bad: Maybe<&2, String> +) -> Reply: match bad: case None{}: Reply{status, headers, dechunk(body)} @@ -868,8 +950,12 @@ def plan.len(status: U32, headers: List<&2, Header>, m: Maybe<&2, Nat>) -> Plan: Planned{status, headers, Sized{n}} # chunked framing, or Content-Length, or the rest of the connection -def plan.te(status: U32, headers: List<&2, Header>, +lens: List<&2, String>, - chunked: Bool) -> Plan: +def plan.te( + status: U32, + headers: List<&2, Header>, + +lens: List<&2, String>, + chunked: Bool +) -> Plan: match chunked: case False{}: plan.len(status, headers, digits.read(first(lens))) @@ -877,8 +963,13 @@ def plan.te(status: U32, headers: List<&2, Header>, +lens: List<&2, String>, plan.clash(status, headers, clen.any(lens)) # disagreeing Content-Length values are torn before framing -def plan.agree(status: U32, headers: List<&2, Header>, te: String, - +lens: List<&2, String>, ok: Bool) -> Plan: +def plan.agree( + status: U32, + headers: List<&2, Header>, + te: String, + +lens: List<&2, String>, + ok: Bool +) -> Plan: match ok: case False{}: Unplanned{"Content-Length values disagree"} @@ -897,8 +988,12 @@ def head.plan(m: Maybe<&2, U32>, +ls: List<&2, String>) -> Plan: clen.agree(lens)) # a body under its framing, as the text parse reads it -def plan.body(status: U32, headers: List<&2, Header>, f: Frame, +body: String) - -> Reply: +def plan.body( + status: U32, + headers: List<&2, Header>, + f: Frame, + +body: String +) -> Reply: match f: case Bare{}: Reply{status, headers, ""} @@ -918,8 +1013,11 @@ def plan.text(p: Plan, +body: String) -> Reply: plan.body(status, headers, f, body) # a head whose status line has been read (RFC 9112 §4) -def parse.status(m: Maybe<&2, U32>, +ls: List<&2, String>, body: String) - -> Reply: +def parse.status( + m: Maybe<&2, U32>, + +ls: List<&2, String>, + body: String +) -> Reply: plan.text(head.plan(m, ls), body) # the status code a head's first line names, if it names one (RFC 9112 §4) @@ -999,8 +1097,12 @@ def reason(+code: U32) -> String: # the head of a reply whose body is n octets, onto what follows it # (laws/ReplyHeadFramesBody.bend) -def respond.head.onto(+status: U32, headers: List<&2, Header>, +n: Nat, - rest: String) -> String: +def respond.head.onto( + +status: U32, + headers: List<&2, Header>, + +n: Nat, + rest: String +) -> String: "HTTP/1.1 " ++ U32.show(status) ++ " " ++ reason(status) ++ "\r\n" ++ "Connection: close\r\n" ++ headers.lines(headers) @@ -1076,8 +1178,12 @@ def chunk.end() -> String: "0\r\n\r\n" # drop a 204/304 body; any other status keeps it -def respond.of.body(+status: U32, headers: List<&2, Header>, body: String, - drop: Bool) -> String: +def respond.of.body( + +status: U32, + headers: List<&2, Header>, + body: String, + drop: Bool +) -> String: match drop: case True{}: respond(status, headers, "") @@ -1115,8 +1221,14 @@ def method.of(req: Request) -> String: method # request body against Content-Length -def ask.short(method: String, target: String, headers: List<&2, Header>, - n: Nat, body: String, short: Bool) -> Request: +def ask.short( + method: String, + target: String, + headers: List<&2, Header>, + n: Nat, + body: String, + short: Bool +) -> Request: match short: case True{}: Bad{"the request body stopped before its Content-Length"} @@ -1124,13 +1236,23 @@ def ask.short(method: String, target: String, headers: List<&2, Header>, Request{method, target, headers, octs.take(body, n)} # a request body framed by Content-Length (RFC 9110 §8.6 / RFC 9112 §6.3) -def ask.clen(method: String, target: String, headers: List<&2, Header>, - +n: Nat, +body: String) -> Request: +def ask.clen( + method: String, + target: String, + headers: List<&2, Header>, + +n: Nat, + +body: String +) -> Request: ask.short(method, target, headers, n, body, Nat.is_lt(octs.len(body), n)) # Content-Length when present; else the rest of the connection is the body -def ask.len(method: String, target: String, headers: List<&2, Header>, - m: Maybe<&2, Nat>, body: String) -> Request: +def ask.len( + method: String, + target: String, + headers: List<&2, Header>, + m: Maybe<&2, Nat>, + body: String +) -> Request: match m: case None{}: Request{method, target, headers, body} @@ -1138,8 +1260,13 @@ def ask.len(method: String, target: String, headers: List<&2, Header>, ask.clen(method, target, headers, n, body) # a chunked request body, or why the chunk framing was rejected -def ask.chunked(method: String, target: String, headers: List<&2, Header>, - body: String, bad: Maybe<&2, String>) -> Request: +def ask.chunked( + method: String, + target: String, + headers: List<&2, Header>, + body: String, + bad: Maybe<&2, String> +) -> Request: match bad: case None{}: Request{method, target, headers, dechunk(body)} @@ -1147,14 +1274,23 @@ def ask.chunked(method: String, target: String, headers: List<&2, Header>, Bad{why} # scan chunk sizes, then decode when they are hex and closed by 0 -def ask.chunks(method: String, target: String, headers: List<&2, Header>, - +body: String) -> Request: +def ask.chunks( + method: String, + target: String, + headers: List<&2, Header>, + +body: String +) -> Request: ask.chunked(method, target, headers, body, chunks.scan(String.length(body), divide(body, "\r\n"))) # Transfer-Encoding together with Content-Length is a bad request -def ask.te.clash(method: String, target: String, headers: List<&2, Header>, - body: String, present: Bool) -> Request: +def ask.te.clash( + method: String, + target: String, + headers: List<&2, Header>, + body: String, + present: Bool +) -> Request: match present: case True{}: Bad{"Content-Length and Transfer-Encoding conflict"} @@ -1162,8 +1298,14 @@ def ask.te.clash(method: String, target: String, headers: List<&2, Header>, ask.chunks(method, target, headers, body) # chunked framing, or Content-Length, or the rest of the connection -def ask.te(method: String, target: String, headers: List<&2, Header>, - +lens: List<&2, String>, +body: String, chunked: Bool) -> Request: +def ask.te( + method: String, + target: String, + headers: List<&2, Header>, + +lens: List<&2, String>, + +body: String, + chunked: Bool +) -> Request: match chunked: case False{}: ask.len(method, target, headers, digits.read(first(lens)), body) @@ -1171,8 +1313,15 @@ def ask.te(method: String, target: String, headers: List<&2, Header>, ask.te.clash(method, target, headers, body, clen.any(lens)) # disagreeing Content-Length values are bad before framing -def ask.agree(method: String, target: String, headers: List<&2, Header>, - te: String, +lens: List<&2, String>, body: String, ok: Bool) -> Request: +def ask.agree( + method: String, + target: String, + headers: List<&2, Header>, + te: String, + +lens: List<&2, String>, + body: String, + ok: Bool +) -> Request: match ok: case False{}: Bad{"Content-Length values disagree"} @@ -1181,13 +1330,24 @@ def ask.agree(method: String, target: String, headers: List<&2, Header>, String.contains(String.to_lower(te), "chunked")) # the headers that decide request framing (RFC 9112 §6.3) -def ask.frame(method: String, target: String, headers: List<&2, Header>, - te: String, +lens: List<&2, String>, body: String) -> Request: +def ask.frame( + method: String, + target: String, + headers: List<&2, Header>, + te: String, + +lens: List<&2, String>, + body: String +) -> Request: ask.agree(method, target, headers, te, lens, body, clen.agree(lens)) # origin-form, or a bad request when the target is not an absolute-path -def ask.origin(method: String, target: String, +ls: List<&2, String>, - body: String, ok: Bool) -> Request: +def ask.origin( + method: String, + target: String, + +ls: List<&2, String>, + body: String, + ok: Bool +) -> Request: match ok: case False{}: Bad{"the request-target is not in origin-form"} @@ -1197,14 +1357,21 @@ def ask.origin(method: String, target: String, +ls: List<&2, String>, head.values(ls, "content-length"), body) # request-line: method SP request-target SP HTTP-version (RFC 9112 §3) -def ask.line(+method: String, +target: String, +ls: List<&2, String>, - body: String) -> Request: +def ask.line( + +method: String, + +target: String, + +ls: List<&2, String>, + body: String +) -> Request: ask.origin(method, target, ls, body, target.form(method, target, target.origin(target))) # three fields of the request-line, or torn -def ask.parts(ps: List<&2, String>, +ls: List<&2, String>, body: String) - -> Request: +def ask.parts( + ps: List<&2, String>, + +ls: List<&2, String>, + body: String +) -> Request: match ps: case []: Bad{"the request has no request line"} @@ -1301,8 +1468,12 @@ def chunks.trailer(+after: String) -> Bool: Bool.or(String.starts_with(after, "\r\n"), String.contains(after, "\r\n\r\n")) # a chunk that has all arrived: on to the next chunk header, else not yet -def chunks.ended.data(+after: String, +n: Nat, ready: Bool, - rest: Cut -> Bool) -> Bool: +def chunks.ended.data( + +after: String, + +n: Nat, + ready: Bool, + rest: Cut -> Bool +) -> Bool: match ready: case False{}: False{} @@ -1310,8 +1481,12 @@ def chunks.ended.data(+after: String, +n: Nat, ready: Bool, rest(divide(octs.drop(after, Nat.add(n, 2n)), "\r\n")) # a chunk of size n: the last one when n is 0 -def chunks.ended.size(+after: String, +n: Nat, zero: Bool, - rest: Cut -> Bool) -> Bool: +def chunks.ended.size( + +after: String, + +n: Nat, + zero: Bool, + rest: Cut -> Bool +) -> Bool: match zero: case True{}: chunks.trailer(after) @@ -1319,8 +1494,12 @@ def chunks.ended.size(+after: String, +n: Nat, zero: Bool, chunks.ended.data(after, n, chunks.ready(after, n), rest) # a chunk header: a size that is not hex ends the read (the parse rejects it) -def chunks.ended.hex(+before: String, +after: String, ok: Bool, - rest: Cut -> Bool) -> Bool: +def chunks.ended.hex( + +before: String, + +after: String, + ok: Bool, + rest: Cut -> Bool +) -> Bool: match ok: case False{}: True{} @@ -1350,7 +1529,7 @@ def whole.of(f: Frame, +body: String) -> Bool: case Bare{}: True{} case Sized{n}: - Bool.not(Nat.is_lt(octs.len(body), n)) + Nat.is_ge(octs.len(body), n) case Chunked{}: chunks.ended(String.length(body), divide(body, "\r\n")) case Closed{}: @@ -1358,8 +1537,13 @@ def whole.of(f: Frame, +body: String) -> Bool: # a head that is interim: whole when what follows is; else whole under the # framing it gives -def whole.step(asked: Bool, +ls: List<&2, String>, +after: String, - interim: Bool, rest: Cut -> Bool) -> Bool: +def whole.step( + asked: Bool, + +ls: List<&2, String>, + +after: String, + interim: Bool, + rest: Cut -> Bool +) -> Bool: match interim: case True{}: rest(divide(after, "\r\n\r\n")) @@ -1407,8 +1591,11 @@ def head.bare(m: Maybe<&2, U32>, ls: List<&2, String>) -> Plan: Planned{n, head.list(ls), Bare{}} # a final head's plan once it is known whether it has a body -def head.final.of(bare: Bool, +m: Maybe<&2, U32>, +ls: List<&2, String>) - -> Plan: +def head.final.of( + bare: Bool, + +m: Maybe<&2, U32>, + +ls: List<&2, String> +) -> Plan: match bare: case True{}: head.bare(m, ls) @@ -1438,8 +1625,12 @@ def parse.to.bare(m: Maybe<&2, U32>, ls: List<&2, String>) -> Reply: Reply{n, head.list(ls), ""} # the final head: with no body, or framed as parse frames it -def parse.to.final(m: Maybe<&2, U32>, +ls: List<&2, String>, after: String, - bare: Bool) -> Reply: +def parse.to.final( + m: Maybe<&2, U32>, + +ls: List<&2, String>, + after: String, + bare: Bool +) -> Reply: match bare: case True{}: parse.to.bare(m, ls) @@ -1447,8 +1638,14 @@ def parse.to.final(m: Maybe<&2, U32>, +ls: List<&2, String>, after: String, parse.status(m, ls, after) # an interim head is skipped, any other is the final one -def parse.to.step(head: Bool, +ls: List<&2, String>, +m: Maybe<&2, U32>, - +after: String, skip: Bool, rest: Cut -> Reply) -> Reply: +def parse.to.step( + head: Bool, + +ls: List<&2, String>, + +m: Maybe<&2, U32>, + +after: String, + skip: Bool, + rest: Cut -> Reply +) -> Reply: match skip: case True{}: rest(divide(after, "\r\n\r\n")) @@ -1497,8 +1694,13 @@ type Skip is Data: Over{left: Nat, rest: String} # one step of the skip: a character wider than what is left stops it -def octs.skip.step(short: Bool, +n: Nat, h: Char, t: String, - rest: Unit -> Skip) -> Skip: +def octs.skip.step( + short: Bool, + +n: Nat, + h: Char, + t: String, + rest: Unit -> Skip +) -> Skip: match short: case True{}: Over{n, SCon{h, t}} @@ -1526,8 +1728,13 @@ type Walk is Data: # a chunk's data skipped: whether its CRLF has arrived, and on to the next # chunk header when it has -def walk.crlf(g: Nat, +left: Nat, +rest: String, ready: Bool, - go: String -> Walk) -> Walk: +def walk.crlf( + g: Nat, + +left: Nat, + +rest: String, + ready: Bool, + go: String -> Walk +) -> Walk: match ready: case True{}: go(octs.drop(rest, Nat.add(left, 2n))) @@ -1552,8 +1759,14 @@ def walk.trail(g: Nat, rest: String, ended: Bool) -> Walk: Hold{1n+g, rest} # a chunk of size n: the last one when n is 0 -def walk.size(+g: Nat, rest: String, +after: String, +n: Nat, zero: Bool, - go: String -> Walk) -> Walk: +def walk.size( + +g: Nat, + rest: String, + +after: String, + +n: Nat, + zero: Bool, + go: String -> Walk +) -> Walk: match zero: case True{}: walk.trail(g, rest, chunks.trailer(after)) @@ -1561,8 +1774,14 @@ def walk.size(+g: Nat, rest: String, +after: String, +n: Nat, zero: Bool, walk.data(g, octs.skip(after, n), go) # a chunk header: a size that is not hex ends the walk (the parse rejects it) -def walk.hex(+g: Nat, rest: String, +before: String, +after: String, ok: Bool, - go: String -> Walk) -> Walk: +def walk.hex( + +g: Nat, + rest: String, + +before: String, + +after: String, + ok: Bool, + go: String -> Walk +) -> Walk: match ok: case False{}: Ended{} @@ -1637,8 +1856,13 @@ def hear.body(f: Frame, +after: String) -> Hear: Never{} # an interim head: on to the next; a final one: its body -def hear.step(asked: Bool, +ls: List<&2, String>, +after: String, - interim: Bool, go: String -> Hear) -> Hear: +def hear.step( + asked: Bool, + +ls: List<&2, String>, + +after: String, + interim: Bool, + go: String -> Hear +) -> Hear: match interim: case True{}: go(after) @@ -1648,8 +1872,13 @@ def hear.step(asked: Bool, +ls: List<&2, String>, +after: String, after) # a head that has ended, or not yet -def hear.at(+g: Nat, +asked: Bool, raw: String, c: Cut, go: String -> Hear) - -> Hear: +def hear.at( + +g: Nat, + +asked: Bool, + raw: String, + c: Cut, + go: String -> Hear +) -> Hear: match c: case NoCut{}: Heads{1n+g, asked, raw} @@ -1681,7 +1910,7 @@ def hear.done(h: Hear) -> Bool: case Never{}: False{} case Count{n, have}: - Bool.not(Nat.is_lt(have, n)) + Nat.is_ge(have, n) case Walking{w}: walk.done(w) @@ -1708,7 +1937,7 @@ def walk.counts(w: Walk, +m: Nat) -> Bool: case Hold{fuel, rest}: False{} case Owed{fuel, owed}: - Bool.not(Nat.is_lt(owed, m)) + Nat.is_ge(owed, m) case Tail{fuel, left, rest}: False{} diff --git a/src/packed.bend b/src/packed.bend index ba4e59f..5420e07 100644 --- a/src/packed.bend +++ b/src/packed.bend @@ -73,16 +73,24 @@ def packed.copy(b: Bytes.Bytes, +at: U32, +n: U32) -> Bytes.Bytes: # --- a chunked body (RFC 9112 §7.1), as chunk.size decides --- # a chunk's octets copied out, then on to the chunk-size line after its CRLF -def packed.chunk.take(r: Bytes.Bytes & Bytes.Bytes, +next: U32, +def packed.chunk.take( + r: Bytes.Bytes & Bytes.Bytes, + +next: U32, acc: List<&1, Bytes.Bytes>, - go: Bytes.Bytes -> U32 -> List<&1, Bytes.Bytes> -> Parts) -> Parts: + go: Bytes.Bytes -> U32 -> List<&1, Bytes.Bytes> -> Parts +) -> Parts: (b, part) = r go(b)(next)(part <> acc) # a chunk of k octets from d, ready when its CRLF follows them -def packed.chunk.ready.is(b: Bytes.Bytes, +d: U32, +k: U32, - acc: List<&1, Bytes.Bytes>, ready: Bool, - go: Bytes.Bytes -> U32 -> List<&1, Bytes.Bytes> -> Parts) -> Parts: +def packed.chunk.ready.is( + b: Bytes.Bytes, + +d: U32, + +k: U32, + acc: List<&1, Bytes.Bytes>, + ready: Bool, + go: Bytes.Bytes -> U32 -> List<&1, Bytes.Bytes> -> Parts +) -> Parts: match ready: case False{}: Bad{Http.chunk.short()} @@ -90,17 +98,26 @@ def packed.chunk.ready.is(b: Bytes.Bytes, +d: U32, +k: U32, packed.chunk.take(Bytes.slice(b, d, k), (d + k + 2 : U32), acc, go) # a chunk of k octets from d whose CRLF has been looked for (chunks.ready) -def packed.chunk.ready(r: Bytes.Bytes & String, +d: U32, +k: U32, +def packed.chunk.ready( + r: Bytes.Bytes & String, + +d: U32, + +k: U32, acc: List<&1, Bytes.Bytes>, - go: Bytes.Bytes -> U32 -> List<&1, Bytes.Bytes> -> Parts) -> Parts: + go: Bytes.Bytes -> U32 -> List<&1, Bytes.Bytes> -> Parts +) -> Parts: (b, crlf) = r packed.chunk.ready.is(b, d, k, acc, String.eq(crlf, "\r\n"), go) # a chunk of n octets from d: its octets must all be there, and a CRLF after # them -def packed.chunk.data(b: Bytes.Bytes, +d: U32, +n: Nat, - acc: List<&1, Bytes.Bytes>, fits: Bool, - go: Bytes.Bytes -> U32 -> List<&1, Bytes.Bytes> -> Parts) -> Parts: +def packed.chunk.data( + b: Bytes.Bytes, + +d: U32, + +n: Nat, + acc: List<&1, Bytes.Bytes>, + fits: Bool, + go: Bytes.Bytes -> U32 -> List<&1, Bytes.Bytes> -> Parts +) -> Parts: match fits: case False{}: Bad{Http.chunk.short()} @@ -109,9 +126,14 @@ def packed.chunk.data(b: Bytes.Bytes, +d: U32, +n: Nat, packed.chunk.ready(packed.text(b, (d + k : U32), 2), d, k, acc, go) # what a chunk-size line says, acted on with the octets after it -def packed.chunk.size(b: Bytes.Bytes, +d: U32, +len: U32, - acc: List<&1, Bytes.Bytes>, z: Http.Size, - go: Bytes.Bytes -> U32 -> List<&1, Bytes.Bytes> -> Parts) -> Parts: +def packed.chunk.size( + b: Bytes.Bytes, + +d: U32, + +len: U32, + acc: List<&1, Bytes.Bytes>, + z: Http.Size, + go: Bytes.Bytes -> U32 -> List<&1, Bytes.Bytes> -> Parts +) -> Parts: match z: case Http.SizeBad{why}: Bad{why} @@ -119,19 +141,27 @@ def packed.chunk.size(b: Bytes.Bytes, +d: U32, +len: U32, Parts{acc} case Http.SizeData{+n}: packed.chunk.data(b, d, n, acc, - Bool.not(Nat.is_lt(U32.to_nat((len - d : U32)), Nat.add(n, 2n))), go) + Nat.is_ge(U32.to_nat((len - d : U32)), Nat.add(n, 2n)), go) # a chunk-size line read, its octets after its CRLF -def packed.chunk.line(r: Bytes.Bytes & String, +d: U32, +len: U32, +def packed.chunk.line( + r: Bytes.Bytes & String, + +d: U32, + +len: U32, acc: List<&1, Bytes.Bytes>, - go: Bytes.Bytes -> U32 -> List<&1, Bytes.Bytes> -> Parts) -> Parts: + go: Bytes.Bytes -> U32 -> List<&1, Bytes.Bytes> -> Parts +) -> Parts: (b, line) = r packed.chunk.size(b, d, len, acc, Http.chunk.size(line), go) # a chunk-size line that ends at i, or none ends: the body ends there -def packed.chunk.at(r: Bytes.Bytes & Maybe<&2, U32>, +p: U32, - +len: U32, acc: List<&1, Bytes.Bytes>, - go: Bytes.Bytes -> U32 -> List<&1, Bytes.Bytes> -> Parts) -> Parts: +def packed.chunk.at( + r: Bytes.Bytes & Maybe<&2, U32>, + +p: U32, + +len: U32, + acc: List<&1, Bytes.Bytes>, + go: Bytes.Bytes -> U32 -> List<&1, Bytes.Bytes> -> Parts +) -> Parts: (b, at) = r match at: case None{}: @@ -141,8 +171,13 @@ def packed.chunk.at(r: Bytes.Bytes & Maybe<&2, U32>, +p: U32, len, acc, go) # the chunks from the chunk-size line at p, at most `fuel` of them -def packed.chunks(fuel: Nat, b: Bytes.Bytes, +p: U32, +len: U32, - acc: List<&1, Bytes.Bytes>) -> Parts: +def packed.chunks( + fuel: Nat, + b: Bytes.Bytes, + +p: U32, + +len: U32, + acc: List<&1, Bytes.Bytes> +) -> Parts: match fuel: case 0n: Bad{"the chunked body is truncated"} @@ -151,8 +186,12 @@ def packed.chunks(fuel: Nat, b: Bytes.Bytes, +p: U32, +len: U32, b2 => q => a2 => packed.chunks(f, b2, q, len, a2)) # a chunked body's octets in order, or why it was torn -def packed.chunked(st: U32, hs: List<&2, Http.Header>, reason: String, - r: Parts) -> Got: +def packed.chunked( + st: U32, + hs: List<&2, Http.Header>, + reason: String, + r: Parts +) -> Got: match r: case Bad{why}: Torn{why} @@ -162,8 +201,15 @@ def packed.chunked(st: U32, hs: List<&2, Http.Header>, reason: String, # --- the body under its framing (RFC 9112 §6.3) --- # a body framed by Content-Length: torn when fewer octets arrived -def packed.sized(st: U32, hs: List<&2, Http.Header>, reason: String, - b: Bytes.Bytes, +q: U32, +n: Nat, short: Bool) -> Got: +def packed.sized( + st: U32, + hs: List<&2, Http.Header>, + reason: String, + b: Bytes.Bytes, + +q: U32, + +n: Nat, + short: Bool +) -> Got: match short: case True{}: Torn{"the response body stopped before its Content-Length"} @@ -171,8 +217,15 @@ def packed.sized(st: U32, hs: List<&2, Http.Header>, reason: String, Got{st, hs, reason, packed.copy(b, q, U32.from_nat(n))} # the octets after the final head, as its framing says -def packed.body(st: U32, hs: List<&2, Http.Header>, reason: String, - f: Http.Frame, b: Bytes.Bytes, +q: U32, +len: U32) -> Got: +def packed.body( + st: U32, + hs: List<&2, Http.Header>, + reason: String, + f: Http.Frame, + b: Bytes.Bytes, + +q: U32, + +len: U32 +) -> Got: match f: case Http.Bare{}: Got{st, hs, reason, Bytes.new(0)} @@ -186,8 +239,13 @@ def packed.body(st: U32, hs: List<&2, Http.Header>, reason: String, Got{st, hs, reason, packed.copy(b, q, (len - q : U32))} # the final head's plan carried out on the octets after it -def packed.final(p: Http.Plan, reason: String, b: Bytes.Bytes, +q: U32, - +len: U32) -> Got: +def packed.final( + p: Http.Plan, + reason: String, + b: Bytes.Bytes, + +q: U32, + +len: U32 +) -> Got: match p: case Http.Unplanned{why}: Torn{why} @@ -197,8 +255,15 @@ def packed.final(p: Http.Plan, reason: String, b: Bytes.Bytes, +q: U32, # --- the heads (RFC 9112 §2.1, RFC 9110 §15.2) --- # an interim head is skipped, any other is the final one -def packed.step(+asked: Bool, b: Bytes.Bytes, +q: U32, +len: U32, - +ls: List<&2, String>, skip: Bool, rest: Bytes.Bytes -> U32 -> Got) -> Got: +def packed.step( + +asked: Bool, + b: Bytes.Bytes, + +q: U32, + +len: U32, + +ls: List<&2, String>, + skip: Bool, + rest: Bytes.Bytes -> U32 -> Got +) -> Got: match skip: case True{}: rest(b)(q) @@ -207,16 +272,26 @@ def packed.step(+asked: Bool, b: Bytes.Bytes, +q: U32, +len: U32, b, q, len) # a head read as text, and the octets after its blank line from q -def packed.head.text(+asked: Bool, r: Bytes.Bytes & String, +q: U32, - +len: U32, rest: Bytes.Bytes -> U32 -> Got) -> Got: +def packed.head.text( + +asked: Bool, + r: Bytes.Bytes & String, + +q: U32, + +len: U32, + rest: Bytes.Bytes -> U32 -> Got +) -> Got: (b, before) = r +ls = String.lines(before) packed.step(asked, b, q, len, ls, Http.interim.skip.of(Http.status.of(ls), U32.is_lt(q, len)), rest) # a head that ends at i, or none ends -def packed.head(+asked: Bool, r: Bytes.Bytes & Maybe<&2, U32>, +p: U32, - +len: U32, rest: Bytes.Bytes -> U32 -> Got) -> Got: +def packed.head( + +asked: Bool, + r: Bytes.Bytes & Maybe<&2, U32>, + +p: U32, + +len: U32, + rest: Bytes.Bytes -> U32 -> Got +) -> Got: (b, at) = r match at: case None{}: @@ -226,8 +301,13 @@ def packed.head(+asked: Bool, r: Bytes.Bytes & Maybe<&2, U32>, +p: U32, len, rest) # the heads in turn from p, at most `fuel` of them -def packed.heads(fuel: Nat, +asked: Bool, b: Bytes.Bytes, +p: U32, +len: U32) - -> Got: +def packed.heads( + fuel: Nat, + +asked: Bool, + b: Bytes.Bytes, + +p: U32, + +len: U32 +) -> Got: match fuel: case 0n: Torn{"the response head has no blank line after it"} diff --git a/src/qs.bend b/src/qs.bend index 7e8b338..6e1911f 100644 --- a/src/qs.bend +++ b/src/qs.bend @@ -38,8 +38,12 @@ def tok.byte(plus: Bool, +c: Char) -> U32: Bool.pick(U32, Bool.and(plus, Char.is_eq(c, '+')), 32, Char.to_u32(c)) # a plain ASCII character: `%` opens an escape, any other is its byte -def tok.ascii(plus: Bool, +c: Char, k: Esc -> List<&2, Tok>, pct: Bool) - -> List<&2, Tok>: +def tok.ascii( + plus: Bool, + +c: Char, + k: Esc -> List<&2, Tok>, + pct: Bool +) -> List<&2, Tok>: match pct: case True{}: k(Pct{}) @@ -47,8 +51,12 @@ def tok.ascii(plus: Bool, +c: Char, k: Esc -> List<&2, Tok>, pct: Bool) B{tok.byte(plus, c)} <> k(Plain{}) # a plain character once it is known whether it is outside ASCII -def tok.wide(plus: Bool, +c: Char, k: Esc -> List<&2, Tok>, wide: Bool) - -> List<&2, Tok>: +def tok.wide( + plus: Bool, + +c: Char, + k: Esc -> List<&2, Tok>, + wide: Bool +) -> List<&2, Tok>: match wide: case True{}: W{c} <> k(Plain{}) @@ -61,8 +69,12 @@ def tok.plain(plus: Bool, +c: Char, k: Esc -> List<&2, Tok>) -> List<&2, Tok>: # a character after `%`: a hex digit is kept, anything else leaves the `%` # as written -def tok.pct(plus: Bool, +c: Char, k: Esc -> List<&2, Tok>, hex: Bool) - -> List<&2, Tok>: +def tok.pct( + plus: Bool, + +c: Char, + k: Esc -> List<&2, Tok>, + hex: Bool +) -> List<&2, Tok>: match hex: case True{}: k(Pct1{c}) @@ -71,8 +83,13 @@ def tok.pct(plus: Bool, +c: Char, k: Esc -> List<&2, Tok>, hex: Bool) # a character after `%` and a hex digit: a second hex digit makes the byte # they name, anything else leaves `%` and the digit as written -def tok.pct1(plus: Bool, +d: Char, +c: Char, k: Esc -> List<&2, Tok>, - hex: Bool) -> List<&2, Tok>: +def tok.pct1( + plus: Bool, + +d: Char, + +c: Char, + k: Esc -> List<&2, Tok>, + hex: Bool +) -> List<&2, Tok>: match hex: case True{}: B{U32.add(U32.mul(Http.hex.val(d), 16), Http.hex.val(c))} <> k(Plain{}) @@ -80,8 +97,12 @@ def tok.pct1(plus: Bool, +d: Char, +c: Char, k: Esc -> List<&2, Tok>, B{37} <> (B{Char.to_u32(d)} <> tok.plain(plus, c, k)) # one character where the decoding stands -def tok.step(plus: Bool, st: Esc, +c: Char, k: Esc -> List<&2, Tok>) - -> List<&2, Tok>: +def tok.step( + plus: Bool, + st: Esc, + +c: Char, + k: Esc -> List<&2, Tok> +) -> List<&2, Tok>: match st: case Plain{}: tok.plain(plus, c, k) @@ -245,8 +266,13 @@ def utf.more(+cp: U32, left: Nat, +b: U32, k: Utf -> String) -> String: # a byte inside a sequence: it continues it when it fits, else the sequence # so far is one U+FFFD and the byte is read again between characters -def utf.byte(+cp: U32, left: Nat, +b: U32, k: Utf -> String, fits: Bool) - -> String: +def utf.byte( + +cp: U32, + left: Nat, + +b: U32, + k: Utf -> String, + fits: Bool +) -> String: match fits: case True{}: utf.more(cp, left, b, k) @@ -254,8 +280,14 @@ def utf.byte(+cp: U32, left: Nat, +b: U32, k: Utf -> String, fits: Bool) SCon{fffd(), utf.lead(b, k, lead(b))} # a piece inside a sequence: a wide character ends it unfinished -def utf.need(+cp: U32, left: Nat, +lo: U32, +hi: U32, t: Tok, - k: Utf -> String) -> String: +def utf.need( + +cp: U32, + left: Nat, + +lo: U32, + +hi: U32, + t: Tok, + k: Utf -> String +) -> String: match t: case W{c}: SCon{fffd(), SCon{c, k(Idle{})}} @@ -348,8 +380,12 @@ def cut.push(+c: Char, m: Maybe<&2, Kv()>) -> Maybe<&2, Kv()>: Some{(SCon{c, before}, after)} # one character of the cut: the first `=` ends the text before it -def cut.at(+c: Char, t: String, eq: Bool, rest: Unit -> Maybe<&2, Kv()>) - -> Maybe<&2, Kv()>: +def cut.at( + +c: Char, + t: String, + eq: Bool, + rest: Unit -> Maybe<&2, Kv()> +) -> Maybe<&2, Kv()>: match eq: case True{}: Some{("", t)} @@ -379,8 +415,11 @@ def field(+piece: String) -> Kv(): field.of(cut(piece), piece) # one piece in front of the rest's fields, skipped when empty -def fields.put(+piece: String, rest: List<&2, Kv()>, empty: Bool) - -> List<&2, Kv()>: +def fields.put( + +piece: String, + rest: List<&2, Kv()>, + empty: Bool +) -> List<&2, Kv()>: match empty: case True{}: rest @@ -401,8 +440,11 @@ def parse(text: String) -> List<&2, Kv()>: fields(String.split(text, '&')) # the value a later pair gives, else this pair's when it is named -def get.pick(later: Maybe<&2, String>, value: String, hit: Bool) - -> Maybe<&2, String>: +def get.pick( + later: Maybe<&2, String>, + value: String, + hit: Bool +) -> Maybe<&2, String>: match later hit: case Some{x} _: Some{x} diff --git a/src/redirect.bend b/src/redirect.bend index 48eee7c..ec37113 100644 --- a/src/redirect.bend +++ b/src/redirect.bend @@ -55,8 +55,13 @@ def redirect.dots.end(last: Bool, out: List<&2, String>) -> List<&2, String>: out # a segment that is not `.`: `..` drops the last kept, any other is kept -def redirect.dots.up(up: Bool, last: Bool, s: String, out: List<&2, String>, - rest: List<&2, String> -> List<&2, String>) -> List<&2, String>: +def redirect.dots.up( + up: Bool, + last: Bool, + s: String, + out: List<&2, String>, + rest: List<&2, String> -> List<&2, String> +) -> List<&2, String>: match up: case True{}: rest(redirect.dots.end(last, redirect.pop(out))) @@ -64,9 +69,14 @@ def redirect.dots.up(up: Bool, last: Bool, s: String, out: List<&2, String>, rest(s <> out) # one segment: `.` is dropped, `..` drops the last kept, any other is kept -def redirect.dots.one(dot: Bool, up: Bool, last: Bool, s: String, - out: List<&2, String>, rest: List<&2, String> -> List<&2, String>) - -> List<&2, String>: +def redirect.dots.one( + dot: Bool, + up: Bool, + last: Bool, + s: String, + out: List<&2, String>, + rest: List<&2, String> -> List<&2, String> +) -> List<&2, String>: match dot: case True{}: rest(redirect.dots.end(last, out)) @@ -75,8 +85,10 @@ def redirect.dots.one(dot: Bool, up: Bool, last: Bool, s: String, # a path's segments with dot segments removed, `out` holding those kept so # far, last first -def redirect.dots(ss: List<&2, String>, out: List<&2, String>) - -> List<&2, String>: +def redirect.dots( + ss: List<&2, String>, + out: List<&2, String> +) -> List<&2, String>: match ss: case []: List.reverse(&2, String, out) @@ -229,8 +241,14 @@ def redirect.sort(+loc: String) -> Sort: # --- the target --- # a Location of a known sort against the current URL's parts -def redirect.against(scheme: String, host: String, port: U32, path: String, - +loc: String, k: Sort) -> Maybe<&2, String>: +def redirect.against( + scheme: String, + host: String, + port: U32, + path: String, + +loc: String, + k: Sort +) -> Maybe<&2, String>: match k: case Net{}: Some{scheme ++ ":" ++ loc} @@ -255,8 +273,11 @@ def redirect.at(l: Url.Loc, +loc: String) -> Maybe<&2, String>: redirect.against(scheme, host, port, path, loc, redirect.sort(loc)) # a Location once it is known whether it is an absolute URL -def redirect.target.of(url: String, +loc: String, absolute: Bool) - -> Maybe<&2, String>: +def redirect.target.of( + url: String, + +loc: String, + absolute: Bool +) -> Maybe<&2, String>: match absolute: case True{}: Some{loc} @@ -294,8 +315,12 @@ def redirect.next(left: Nat, url: String, +status: U32, +loc: String) -> Hop: redirect.on(url, loc, redirect.is(status)) # the next hop after a response's status and headers -def redirect.plan(left: Nat, url: String, +status: U32, - headers: List<&2, Http.Header>) -> Hop: +def redirect.plan( + left: Nat, + url: String, + +status: U32, + headers: List<&2, Http.Header> +) -> Hop: redirect.next(left, url, status, Http.headers.find(headers, "location")) # whether a request with this method follows redirects when asked to: only a diff --git a/src/server.bend b/src/server.bend index 8e1c711..d736bb6 100644 --- a/src/server.bend +++ b/src/server.bend @@ -90,8 +90,9 @@ def server.listen(host: String, port: U32) -> IO(Listener): IO.try(Listener, TCP.listen(host, port)) # accept one connection, waiting at most server.wait() ms -def server.accept.un(r: Listener & Result<&1, &1, U32 & String, Socket>) - -> IO(Listener & Step.Accept): +def server.accept.un( + r: Listener & Result<&1, &1, U32 & String, Socket> +) -> IO(Listener & Step.Accept): (lst, res) = r IO.pure(Listener & Step.Accept, (lst, Step.step.accepted(Socket, res))) @@ -108,14 +109,18 @@ def server.lose(sock: Socket, line: String) -> IO(Unit): # the request once it has all arrived (or the peer closed, or the receives # ran out): its pieces put together and parsed -def server.read.done(sock: Socket, ps: List<&2, String>) - -> IO(Socket & Step.Got): +def server.read.done( + sock: Socket, + ps: List<&2, String> +) -> IO(Socket & Step.Got): IO.pure(Socket & Step.Got, (sock, Step.Kept{Http.ask(Spec.wire.join(ps))})) # what the request needs, kept once its head has ended -def server.read.needs(m: Maybe<&2, Nat>, ps: List<&2, String>) - -> Maybe<&2, Nat>: +def server.read.needs( + m: Maybe<&2, Nat>, + ps: List<&2, String> +) -> Maybe<&2, Nat>: match m: case None{}: Step.step.need(Spec.wire.join(ps)) @@ -128,14 +133,17 @@ def server.read.whole(m: Maybe<&2, Nat>, +have: Nat) -> Bool: case None{}: False{} case Some{n}: - Bool.not(Nat.is_lt(have, n)) + Nat.is_ge(have, n) # octets that arrived: stop when the request is whole, else read again -def server.read.more(sock: Socket, +ps: List<&2, String>, +have: Nat, - +need: Maybe<&2, Nat>, whole: Bool, - rest: Socket -> List<&2, String> -> Nat -> Maybe<&2, Nat> - -> IO(Socket & Step.Got)) - -> IO(Socket & Step.Got): +def server.read.more( + sock: Socket, + +ps: List<&2, String>, + +have: Nat, + +need: Maybe<&2, Nat>, + whole: Bool, + rest: Socket -> List<&2, String> -> Nat -> Maybe<&2, Nat> -> IO(Socket & Step.Got) +) -> IO(Socket & Step.Got): match whole: case True{}: server.read.done(sock, ps) @@ -143,20 +151,26 @@ def server.read.more(sock: Socket, +ps: List<&2, String>, +have: Nat, rest(sock)(ps)(have)(need) # octets added to the pieces: is the request now whole? -def server.read.add(sock: Socket, +ps: List<&2, String>, +have: Nat, +def server.read.add( + sock: Socket, + +ps: List<&2, String>, + +have: Nat, need: Maybe<&2, Nat>, - rest: Socket -> List<&2, String> -> Nat -> Maybe<&2, Nat> - -> IO(Socket & Step.Got)) - -> IO(Socket & Step.Got): + rest: Socket -> List<&2, String> -> Nat -> Maybe<&2, Nat> -> IO(Socket & Step.Got) +) -> IO(Socket & Step.Got): +need2 = server.read.needs(need, ps) server.read.more(sock, ps, have, need2, server.read.whole(need2, have), rest) # octets that arrived, or none once the peer has closed -def server.read.text(sock: Socket, +ps: List<&2, String>, +have: Nat, - need: Maybe<&2, Nat>, +text: String, closed: Bool, - rest: Socket -> List<&2, String> -> Nat -> Maybe<&2, Nat> - -> IO(Socket & Step.Got)) - -> IO(Socket & Step.Got): +def server.read.text( + sock: Socket, + +ps: List<&2, String>, + +have: Nat, + need: Maybe<&2, Nat>, + +text: String, + closed: Bool, + rest: Socket -> List<&2, String> -> Nat -> Maybe<&2, Nat> -> IO(Socket & Step.Got) +) -> IO(Socket & Step.Got): match closed: case True{}: server.read.done(sock, ps) @@ -166,11 +180,13 @@ def server.read.text(sock: Socket, +ps: List<&2, String>, +have: Nat, # a receive's answer: a failure loses the connection, no octets is the peer # closing, octets go onto the pieces -def server.read.got(+ps: List<&2, String>, +have: Nat, need: Maybe<&2, Nat>, +def server.read.got( + +ps: List<&2, String>, + +have: Nat, + need: Maybe<&2, Nat>, r: Socket & Result<&1, &1, U32 & String, String>, - rest: Socket -> List<&2, String> -> Nat -> Maybe<&2, Nat> - -> IO(Socket & Step.Got)) - -> IO(Socket & Step.Got): + rest: Socket -> List<&2, String> -> Nat -> Maybe<&2, Nat> -> IO(Socket & Step.Got) +) -> IO(Socket & Step.Got): (sock, res) = r match res: case Fail{(code, why)}: @@ -181,8 +197,13 @@ def server.read.got(+ps: List<&2, String>, +have: Nat, need: Maybe<&2, Nat>, # receive until the head has ended and its Content-Length has arrived, the # peer closes, or the receives run out -def server.read.go(fuel: Nat, sock: Socket, +ps: List<&2, String>, +have: Nat, - +need: Maybe<&2, Nat>) -> IO(Socket & Step.Got): +def server.read.go( + fuel: Nat, + sock: Socket, + +ps: List<&2, String>, + +have: Nat, + +need: Maybe<&2, Nat> +) -> IO(Socket & Step.Got): match fuel: case 0n: server.read.done(sock, ps) @@ -200,8 +221,9 @@ def server.read(sock: Socket) -> IO(Socket & Step.Got): # --- writing a reply --- # after a send: the socket, or the line of a lost connection -def server.sent.un(r: Socket & Result<&1, &1, U32 & String, Unit>) - -> IO(Socket & Step.Got): +def server.sent.un( + r: Socket & Result<&1, &1, U32 & String, Unit> +) -> IO(Socket & Step.Got): (sock, res) = r IO.pure(Socket & Step.Got, (sock, Step.step.got(Unit, "write", res))) @@ -225,8 +247,10 @@ def server.close(r: Socket & Step.Got) -> IO(Unit): Socket.close(sock) # after a send in the middle: go on, or lose the connection -def server.then(r: Socket & Step.Got, more: Socket -> IO(Unit)) - -> IO(Unit): +def server.then( + r: Socket & Step.Got, + more: Socket -> IO(Unit) +) -> IO(Unit): (sock, got) = r match got: case Step.Dropped{line}: @@ -244,8 +268,13 @@ def server.answer(sock: Socket, method: String, reply: Http.Reply) -> IO(Unit): # an octets reply once its length is known: its head, then its octets unless # it is bare (laws/ReplyHeadFramesBody.bend, # laws/BareRepliesWriteHeadOnly.bend) -def server.octets.go(sock: Socket, +status: U32, headers: List<&2, Http.Header>, - r: Bytes.Bytes & U32, bare: Bool) -> IO(Unit): +def server.octets.go( + sock: Socket, + +status: U32, + headers: List<&2, Http.Header>, + r: Bytes.Bytes & U32, + bare: Bool +) -> IO(Unit): (b, +n) = r match bare: case True{}: @@ -260,11 +289,15 @@ def server.octets.go(sock: Socket, +status: U32, headers: List<&2, Http.Header>, # the most chunks one streamed reply writes def server.chunks() -> Nat: - U32.to_nat(4294967295) + 4294967295n # one chunk the channel gave: framed and sent, or skipped when empty -def server.chunk.put(sock: Socket, c: Http.Chunk, b: Bytes.Bytes, - more: Socket -> IO(Unit)) -> IO(Unit): +def server.chunk.put( + sock: Socket, + c: Http.Chunk, + b: Bytes.Bytes, + more: Socket -> IO(Unit) +) -> IO(Unit): match c: case Http.NoChunk{}: more(sock) @@ -275,14 +308,20 @@ def server.chunk.put(sock: Socket, c: Http.Chunk, b: Bytes.Bytes, r => server.then(r, more)) # a chunk with its length known -def server.chunk.sized(sock: Socket, r: Bytes.Bytes & U32, - more: Socket -> IO(Unit)) -> IO(Unit): +def server.chunk.sized( + sock: Socket, + r: Bytes.Bytes & U32, + more: Socket -> IO(Unit) +) -> IO(Unit): (b, +n) = r server.chunk.put(sock, Http.chunk.frame(n), b, more) # what the channel gave: a chunk, or its close, which ends the body -def server.chunk.got(sock: Socket, m: Maybe<&1, Bytes.Bytes>, - more: Socket -> IO(Unit)) -> IO(Unit): +def server.chunk.got( + sock: Socket, + m: Maybe<&1, Bytes.Bytes>, + more: Socket -> IO(Unit) +) -> IO(Unit): match m: case None{}: IO.bind(Socket & Step.Got, Unit, @@ -291,8 +330,11 @@ def server.chunk.got(sock: Socket, m: Maybe<&1, Bytes.Bytes>, server.chunk.sized(sock, Bytes.length(b), more) # every chunk the channel gives, until it is closed -def server.stream.go(fuel: Nat, sock: Socket, +ch: Chan(Bytes.Bytes)) - -> IO(Unit): +def server.stream.go( + fuel: Nat, + sock: Socket, + +ch: Chan(Bytes.Bytes) +) -> IO(Unit): match fuel: case 0n: IO.bind(Socket & Step.Got, Unit, @@ -302,8 +344,11 @@ def server.stream.go(fuel: Nat, sock: Socket, +ch: Chan(Bytes.Bytes)) m => server.chunk.got(sock, m, s => server.stream.go(f, s, ch))) # a streamed reply after its head: its chunks, or nothing when it is bare -def server.stream.body(sock: Socket, +ch: Chan(Bytes.Bytes), bare: Bool) - -> IO(Unit): +def server.stream.body( + sock: Socket, + +ch: Chan(Bytes.Bytes), + bare: Bool +) -> IO(Unit): match bare: case True{}: IO.bind(Unit, Unit, Chan.close(Bytes.Bytes, ch), _u => Socket.close(sock)) @@ -339,8 +384,15 @@ def server.req(req: Http.Request, +octets: String) -> Req: # answer now, or call the handler: step.bend decides which # (laws/BadRequestAnswers400.bend, laws/HandlerGetsRequestText.bend, # laws/WithServesGetOctetsAndContext.bend) -def server.step(~C: Data, ~handle: C -> Req -> IO(Answer), +ctx: C, - sock: Socket, +method: String, +octets: String, step: Step.Step) -> IO(Unit): +def server.step( + ~C: Data, + ~handle: C -> Req -> IO(Answer), + +ctx: C, + sock: Socket, + +method: String, + +octets: String, + step: Step.Step +) -> IO(Unit): match step: case Step.Answer{reply}: server.answer(sock, method, reply) @@ -349,8 +401,12 @@ def server.step(~C: Data, ~handle: C -> Req -> IO(Answer), +ctx: C, a => server.reply(sock, method, a)) # after the read: a lost connection, or a request to step -def server.conn.got(~C: Data, ~handle: C -> Req -> IO(Answer), +ctx: C, - r: Socket & Step.Got) -> IO(Unit): +def server.conn.got( + ~C: Data, + ~handle: C -> Req -> IO(Answer), + +ctx: C, + r: Socket & Step.Got +) -> IO(Unit): (sock, got) = r match got: case Step.Dropped{line}: @@ -361,8 +417,12 @@ def server.conn.got(~C: Data, ~handle: C -> Req -> IO(Answer), +ctx: C, Step.step.octets(raw), Step.step.of(req)) # one connection: read, decide, maybe handle, write, close -def server.conn(~C: Data, ~handle: C -> Req -> IO(Answer), +ctx: C, - sock: Socket) -> IO(Unit): +def server.conn( + ~C: Data, + ~handle: C -> Req -> IO(Answer), + +ctx: C, + sock: Socket +) -> IO(Unit): IO.bind(Socket & Step.Got, Unit, server.read(sock), r => server.conn.got(~C, handle, ctx, r)) @@ -396,20 +456,29 @@ def server.done(+done: Chan(Unit), tracked: Bool) -> IO(Unit): IO.pure(Unit, Unit{}) # a connection's fork: serve it, give its slot back, and say it is done -def server.fork.body(~C: Data, ~handle: C -> Req -> IO(Answer), +ctx: C, - sock: Socket, +slots: Chan(Unit), +limited: Bool, +done: Chan(Unit), - +tracked: Bool) -> IO(Unit): +def server.fork.body( + ~C: Data, + ~handle: C -> Req -> IO(Answer), + +ctx: C, + sock: Socket, + +pool: Step.Pool +) -> IO(Unit): + Step.Pool{slots, limited, done, tracked} = pool IO.bind(Unit, Unit, server.conn(~C, handle, ctx, sock), _u => IO.bind(Unit, Unit, server.slot.give(slots, limited), _v => server.done(done, tracked))) # serve an accepted connection on its own fork, a slot taken first -def server.fork(~C: Data, ~handle: C -> Req -> IO(Answer), +ctx: C, - sock: Socket, +slots: Chan(Unit), +limited: Bool, +done: Chan(Unit), - +tracked: Bool) -> IO(Unit): +def server.fork( + ~C: Data, + ~handle: C -> Req -> IO(Answer), + +ctx: C, + sock: Socket, + +pool: Step.Pool +) -> IO(Unit): + Step.Pool{slots, limited, done, tracked} = pool IO.bind(Unit, Unit, server.slot.take(slots, limited), - _u => IO.spawn(Unit, - server.fork.body(~C, handle, ctx, sock, slots, limited, done, tracked))) + _u => IO.spawn(Unit, server.fork.body(~C, handle, ctx, sock, pool))) # wait for n forks to say they are done def server.join(n: Nat, +done: Chan(Unit)) -> IO(Unit): @@ -423,15 +492,20 @@ def server.join(n: Nat, +done: Chan(Unit)) -> IO(Unit): # what an accept brought, for the loop: `took` serves a connection and goes # on with one connection fewer, `idle` accepts again, `missed` logs, pauses # and goes on with one fewer (a failed accept counts toward the limit) -def server.loop.got(~C: Data, ~handle: C -> Req -> IO(Answer), +ctx: C, - +slots: Chan(Unit), +limited: Bool, +done: Chan(Unit), +tracked: Bool, - r: Listener & Step.Accept, took: Listener -> IO(Unit), - idle: Listener -> IO(Unit), missed: Listener -> IO(Unit)) -> IO(Unit): +def server.loop.got( + ~C: Data, + ~handle: C -> Req -> IO(Answer), + +ctx: C, + +pool: Step.Pool, + r: Listener & Step.Accept, + took: Listener -> IO(Unit), + idle: Listener -> IO(Unit), + missed: Listener -> IO(Unit) +) -> IO(Unit): (lst, got) = r match got: case Step.Took{sock}: - IO.bind(Unit, Unit, - server.fork(~C, handle, ctx, sock, slots, limited, done, tracked), + IO.bind(Unit, Unit, server.fork(~C, handle, ctx, sock, pool), _u => took(lst)) case Step.Idle{}: idle(lst) @@ -440,25 +514,34 @@ def server.loop.got(~C: Data, ~handle: C -> Req -> IO(Answer), +ctx: C, IO.bind(Unit, Unit, IO.sleep(server.pause()), _v => missed(lst))) # the limited accept loop: `fuel` connections left, `idles` idle accepts in -# a row left, `forks` forked so far -def server.loop.go(~C: Data, ~handle: C -> Req -> IO(Answer), +ctx: C, - fuel: Nat, idles: Nat, +forks: Nat, +slots: Chan(Unit), +limited: Bool, - +done: Chan(Unit), listener: Listener) -> IO(Unit): +# a row left, `forks` forked so far; its pool is tracked, so the loop joins +# its forks on `done` before it returns +def server.loop.go( + ~C: Data, + ~handle: C -> Req -> IO(Answer), + +ctx: C, + fuel: Nat, + idles: Nat, + +forks: Nat, + +pool: Step.Pool, + listener: Listener +) -> IO(Unit): match fuel idles: case 0n _: - IO.bind(Unit, Unit, Listener.close(listener), _u => server.join(forks, done)) + IO.bind(Unit, Unit, Listener.close(listener), + _u => server.join(forks, Step.step.pool.done(pool))) case 1n+_f 0n: - IO.bind(Unit, Unit, Listener.close(listener), _u => server.join(forks, done)) + IO.bind(Unit, Unit, Listener.close(listener), + _u => server.join(forks, Step.step.pool.done(pool))) case 1n+f0 1n+i: +f = f0 IO.bind(Listener & Step.Accept, Unit, server.accept(listener), - r => server.loop.got(~C, handle, ctx, slots, limited, done, True{}, r, - l => server.loop.go(~C, handle, ctx, f, server.idles(), 1n+forks, slots, - limited, done, l), - l => server.loop.go(~C, handle, ctx, 1n+f, i, forks, slots, limited, - done, l), - l => server.loop.go(~C, handle, ctx, f, server.idles(), forks, slots, - limited, done, l))) + r => server.loop.got(~C, handle, ctx, pool, r, + l => server.loop.go(~C, handle, ctx, f, server.idles(), 1n+forks, + pool, l), + l => server.loop.go(~C, handle, ctx, 1n+f, i, forks, pool, l), + l => server.loop.go(~C, handle, ctx, f, server.idles(), forks, pool, + l))) # the slots a concurrency limit allows (max 0: no limit) def server.slots(+max: U32) -> IO(Chan(Unit)): @@ -467,47 +550,75 @@ def server.slots(+max: U32) -> IO(Chan(Unit)): # listen and serve up to `limit` connections, each on its own fork, at most # `max` at once (0: no limit), with a context value for the handler; returns # once every fork is done (trusted above) -def server.serve_io_with(~C: Data, ~handle: C -> Req -> IO(Answer), +ctx: C, - host: String, port: U32, limit: U32, +max: U32) -> IO(Unit): +def server.serve_io_with( + ~C: Data, + ~handle: C -> Req -> IO(Answer), + +ctx: C, + host: String, + port: U32, + limit: U32, + +max: U32 +) -> IO(Unit): do IO: lst : Listener <- server.listen(host, port) +slots : Chan(Unit) <- server.slots(max) +done : Chan(Unit) <- Chan.new(Unit, 1024) - server.loop.go(~C, handle, ctx, U32.to_nat(limit), server.idles(), 0n, slots, - Bool.not(U32.is_eq(max, 0)), done, lst) + server.loop.go(~C, handle, ctx, U32.to_nat(limit), server.idles(), 0n, + Step.step.pool(slots, max, done, True{}), lst) # a pure handler as an IO one -def server.lift.with(~C: Data, ~handle: C -> Req -> Answer, +ctx: C, req: Req) - -> IO(Answer): +def server.lift.with( + ~C: Data, + ~handle: C -> Req -> Answer, + +ctx: C, + req: Req +) -> IO(Answer): IO.pure(Answer, handle(ctx)(req)) # listen and serve with a pure handler and a context value -def server.serve_with(~C: Data, ~handle: C -> Req -> Answer, +ctx: C, - host: String, port: U32, limit: U32, max: U32) -> IO(Unit): +def server.serve_with( + ~C: Data, + ~handle: C -> Req -> Answer, + +ctx: C, + host: String, + port: U32, + limit: U32, + max: U32 +) -> IO(Unit): server.serve_io_with(~C, ~(c => r => server.lift.with(~C, handle, c, r)), ctx, host, port, limit, max) -# the accept loop with no limit: it runs until the process is stopped -@unsafe def server.forever.go(~C: Data, ~handle: C -> Req -> IO(Answer), - +ctx: C, +slots: Chan(Unit), +limited: Bool, +done: Chan(Unit), - listener: Listener) -> IO(Unit): +# the accept loop with no limit: it runs until the process is stopped; its +# pool is untracked, so its forks never say they are done +@unsafe def server.forever.go( + ~C: Data, + ~handle: C -> Req -> IO(Answer), + +ctx: C, + +pool: Step.Pool, + listener: Listener +) -> IO(Unit): IO.bind(Listener & Step.Accept, Unit, server.accept(listener), - r => server.loop.got(~C, handle, ctx, slots, limited, done, False{}, r, - l => server.forever.go(~C, handle, ctx, slots, limited, done, l), - l => server.forever.go(~C, handle, ctx, slots, limited, done, l), - l => server.forever.go(~C, handle, ctx, slots, limited, done, l))) + r => server.loop.got(~C, handle, ctx, pool, r, + l => server.forever.go(~C, handle, ctx, pool, l), + l => server.forever.go(~C, handle, ctx, pool, l), + l => server.forever.go(~C, handle, ctx, pool, l))) # listen and serve with an IO handler and a context value until the process # is stopped, at most `max` connections at once (0: no limit) -@unsafe def server.serve_forever_with(~C: Data, - ~handle: C -> Req -> IO(Answer), +ctx: C, host: String, port: U32, +max: U32) - -> IO(Unit): +@unsafe def server.serve_forever_with( + ~C: Data, + ~handle: C -> Req -> IO(Answer), + +ctx: C, + host: String, + port: U32, + +max: U32 +) -> IO(Unit): do IO: lst : Listener <- server.listen(host, port) +slots : Chan(Unit) <- server.slots(max) +done : Chan(Unit) <- Chan.new(Unit, 1) - server.forever.go(~C, handle, ctx, slots, Bool.not(U32.is_eq(max, 0)), done, - lst) + server.forever.go(~C, handle, ctx, + Step.step.pool(slots, max, done, False{}), lst) # --- the text handlers (no context) --- @@ -525,42 +636,62 @@ def server.text(reply: Http.Reply) -> IO(Answer): IO.pure(Answer, TextReply{status, headers, body}) # a plain IO handler as a `_with` one -def server.wrap.io(~handle: Http.Request -> IO(Http.Reply), r: Req) - -> IO(Answer): +def server.wrap.io( + ~handle: Http.Request -> IO(Http.Reply), + r: Req +) -> IO(Answer): IO.bind(Http.Reply, Answer, handle(server.plain(r)), server.text) # listen and serve up to `limit` connections with an IO handler -def server.serve_io(~handle: Http.Request -> IO(Http.Reply), host: String, - port: U32, limit: U32) -> IO(Unit): +def server.serve_io( + ~handle: Http.Request -> IO(Http.Reply), + host: String, + port: U32, + limit: U32 +) -> IO(Unit): server.serve_io_with(~Unit, ~(_u => r => server.wrap.io(handle, r)), Unit{}, host, port, limit, 0) # a pure handler as an IO one -def server.lift(~handle: Http.Request -> Http.Reply, req: Http.Request) - -> IO(Http.Reply): +def server.lift( + ~handle: Http.Request -> Http.Reply, + req: Http.Request +) -> IO(Http.Reply): IO.pure(Http.Reply, handle(req)) # listen and serve up to `limit` connections -def server.serve(~handle: Http.Request -> Http.Reply, host: String, port: U32, - limit: U32) -> IO(Unit): +def server.serve( + ~handle: Http.Request -> Http.Reply, + host: String, + port: U32, + limit: U32 +) -> IO(Unit): server.serve_io(~(req => server.lift(handle, req)), host, port, limit) # serve exactly one connection then stop -def server.once(~handle: Http.Request -> Http.Reply, host: String, port: U32) - -> IO(Unit): +def server.once( + ~handle: Http.Request -> Http.Reply, + host: String, + port: U32 +) -> IO(Unit): server.serve(handle, host, port, 1) # listen and serve with an IO handler until the process is stopped -@unsafe def server.serve_forever(~handle: Http.Request -> IO(Http.Reply), - host: String, port: U32) -> IO(Unit): +@unsafe def server.serve_forever( + ~handle: Http.Request -> IO(Http.Reply), + host: String, + port: U32 +) -> IO(Unit): server.serve_forever_with(~Unit, ~(_u => r => server.wrap.io(handle, r)), Unit{}, host, port, 0) # --- CORS (cors.bend), for pure handlers --- # turn a bad request into 400; otherwise call the handler -def server.dispatch(~handle: Http.Request -> Http.Reply, req: Http.Request) - -> Http.Reply: +def server.dispatch( + ~handle: Http.Request -> Http.Reply, + req: Http.Request +) -> Http.Reply: match req: case Http.Bad{why}: Http.Reply{400, [], why} @@ -568,13 +699,18 @@ def server.dispatch(~handle: Http.Request -> Http.Reply, req: Http.Request) handle(Http.Request{method, target, headers, body}) # apply HEAD body stripping once the method token is known -def server.reply.built(~handle: Http.Request -> Http.Reply, method: String, - req: Http.Request) -> Http.Reply: +def server.reply.built( + ~handle: Http.Request -> Http.Reply, + method: String, + req: Http.Request +) -> Http.Reply: Http.reply.for(method, server.dispatch(handle, req)) # HEAD responses are written with an empty body (RFC 9110 §9.3.2) -def server.reply.text(~handle: Http.Request -> Http.Reply, req: Http.Request) - -> Http.Reply: +def server.reply.text( + ~handle: Http.Request -> Http.Reply, + req: Http.Request +) -> Http.Reply: match req: case Http.Bad{why}: server.dispatch(handle, Http.Bad{why}) @@ -589,4 +725,3 @@ def server.cors_reply( +req: Http.Request ) -> Http.Reply: Cors.cors.on(cfg, req, server.reply.text(handle, req)) - diff --git a/src/step.bend b/src/step.bend index 94df1c9..3bf4b2e 100644 --- a/src/step.bend +++ b/src/step.bend @@ -53,8 +53,9 @@ def step.got( Kept{value} # a failed send loses the connection too; the bytes it did not send are dropped -def step.sent(res: Result<&1, &1, (U32 & String) & List<&2, U32>, Unit>) - -> Got: +def step.sent( + res: Result<&1, &1, (U32 & String) & List<&2, U32>, Unit> +) -> Got: match res: case Fail{((code, why), left)}: Dropped{step.line("write", why)} @@ -86,6 +87,32 @@ type Accept<-A: Type> is Type: Idle{} Missed{line: String} +# what the accept loops hand each fork: the slots a concurrency limit +# allows and whether there is one (`limited`), and the channel a fork says +# it is done on and whether a loop waits for it (`tracked`) +type Pool is Data: + Pool{slots: Chan(Unit), limited: Bool, done: Chan(Unit), tracked: Bool} + +# the pool of a serve of at most `max` connections at once: limited unless +# `max` is 0, its forks joined on `done` (laws/MaxZeroIsNoLimit.bend) +def step.pool( + slots: Chan(Unit), + +max: U32, + done: Chan(Unit), + tracked: Bool +) -> Pool: + Pool{slots, U32.is_ne(max, 0), done, tracked} + +# whether a pool's forks take a slot +def step.pool.limited(pool: Pool) -> Bool: + Pool{slots, limited, done, tracked} = pool + limited + +# the channel a pool's forks say they are done on +def step.pool.done(pool: Pool) -> Chan(Unit): + Pool{slots, limited, done, tracked} = pool + done + # a failed accept once it is known whether its deadline passed def step.missed(-A: Type, +why: String, late: Bool) -> Accept: match late: @@ -95,8 +122,10 @@ def step.missed(-A: Type, +why: String, late: Bool) -> Accept: Missed{step.line("accept", why)} # an accept's outcome: ETIMEDOUT (110) is a deadline that passed -def step.accepted(-A: Type, res: Result<&1, &1, U32 & String, A>) - -> Accept: +def step.accepted( + -A: Type, + res: Result<&1, &1, U32 & String, A> +) -> Accept: match res: case Fail{(+code, why)}: step.missed(A, why, U32.is_eq(code, 110)) diff --git a/src/unescape.bend b/src/unescape.bend index a5652af..1b45f01 100644 --- a/src/unescape.bend +++ b/src/unescape.bend @@ -136,8 +136,11 @@ def best.len(m: Maybe<&2, Ents.Ref>) -> Nat: String.length(name) # the better of the best so far and a name the text starts with: the longer -def best.take(best: Maybe<&2, Ents.Ref>, +r: Ents.Ref, longer: Bool) - -> Maybe<&2, Ents.Ref>: +def best.take( + best: Maybe<&2, Ents.Ref>, + +r: Ents.Ref, + longer: Bool +) -> Maybe<&2, Ents.Ref>: match longer: case True{}: Some{r} @@ -145,8 +148,12 @@ def best.take(best: Maybe<&2, Ents.Ref>, +r: Ents.Ref, longer: Bool) best # a name the text starts with or not -def best.hit(+best: Maybe<&2, Ents.Ref>, +r: Ents.Ref, +name: String, - hit: Bool) -> Maybe<&2, Ents.Ref>: +def best.hit( + +best: Maybe<&2, Ents.Ref>, + +r: Ents.Ref, + +name: String, + hit: Bool +) -> Maybe<&2, Ents.Ref>: match hit: case True{}: best.take(best, r, Nat.is_lt(best.len(best), String.length(name))) @@ -154,15 +161,21 @@ def best.hit(+best: Maybe<&2, Ents.Ref>, +r: Ents.Ref, +name: String, best # one table row against the best so far -def best.step(+best: Maybe<&2, Ents.Ref>, +r: Ents.Ref, +s: String) - -> Maybe<&2, Ents.Ref>: +def best.step( + +best: Maybe<&2, Ents.Ref>, + +r: Ents.Ref, + +s: String +) -> Maybe<&2, Ents.Ref>: match r: case Ents.Ref{+name, first, second}: best.hit(best, r, name, String.starts_with(s, name)) # the longest name in the rows that the text starts with -def best(rs: List<&2, Ents.Ref>, +s: String, +sofar: Maybe<&2, Ents.Ref>) - -> Maybe<&2, Ents.Ref>: +def best( + rs: List<&2, Ents.Ref>, + +s: String, + +sofar: Maybe<&2, Ents.Ref> +) -> Maybe<&2, Ents.Ref>: match rs: case []: sofar @@ -246,8 +259,13 @@ def hash(+c: Char, k: Scan -> String, +d: U32) -> String: hash.dec(c, k, d, U32.is_lt(d, 16)) # after `&#x`, once it is known whether the character is a hex digit -def hash.hex.of(+x: Char, +c: Char, k: Scan -> String, +d: U32, digit: Bool) - -> String: +def hash.hex.of( + +x: Char, + +c: Char, + k: Scan -> String, + +d: U32, + digit: Bool +) -> String: match digit: case True{}: k(Num{True{}, d}) @@ -268,8 +286,14 @@ def num.end(+n: U32, +c: Char, k: Scan -> String, semi: Bool) -> String: code(n) ++ text(c, k) # inside a number: a digit grows it -def num(+hex: Bool, +n: U32, +c: Char, k: Scan -> String, +d: U32, - digit: Bool) -> String: +def num( + +hex: Bool, + +n: U32, + +c: Char, + k: Scan -> String, + +d: U32, + digit: Bool +) -> String: match digit: case True{}: k(Num{hex, grow(hex, n, d)}) @@ -282,8 +306,13 @@ def name.end(+s: String, +c: Char, k: Scan -> String) -> String: # inside a name, a character that is not `;`: a name character joins it # while it has fewer than 32 -def name.more(+s: String, len: Nat, +c: Char, k: Scan -> String, join: Bool) - -> String: +def name.more( + +s: String, + len: Nat, + +c: Char, + k: Scan -> String, + join: Bool +) -> String: match join: case True{}: k(Name{s ++ SCon{c, ""}, 1n+len}) @@ -291,8 +320,13 @@ def name.more(+s: String, len: Nat, +c: Char, k: Scan -> String, join: Bool) name.end(s, c, k) # inside a name: `;` ends the reference with it -def name(+s: String, +len: Nat, +c: Char, k: Scan -> String, semi: Bool) - -> String: +def name( + +s: String, + +len: Nat, + +c: Char, + k: Scan -> String, + semi: Bool +) -> String: match semi: case True{}: named(s ++ ";") ++ k(Txt{}) diff --git a/src/url.bend b/src/url.bend index 7fe496a..e6d2c6e 100644 --- a/src/url.bend +++ b/src/url.bend @@ -113,7 +113,7 @@ def path.target.of(path: String, query: String, empty: Bool) -> String: # absolute-path ["?" query] (RFC 3986 §3.4, RFC 9112 §3.2.1) def path.target(path: String, +query: String) -> String: - path.target.of(path, query, String.eq(query, "")) + path.target.of(path, query, String.is_empty(query)) # a url whose authority is now split on its colon def parse.auth(+scheme: String, +au: List<&2, String>, path: String) -> Loc: diff --git a/src/wire.bend b/src/wire.bend index 01d615f..4240c13 100644 --- a/src/wire.bend +++ b/src/wire.bend @@ -72,8 +72,11 @@ def wire.close(secure: Bool, s: Socket) -> IO(Unit): Socket.close(s) # the next octets a socket has received, packed four to a word -def wire.recv(secure: Bool, s: Socket, ms: U32) - -> IO(Socket & Result<&1, &1, U32 & String, U32 & Array>): +def wire.recv( + secure: Bool, + s: Socket, + ms: U32 +) -> IO(Socket & Result<&1, &1, U32 & String, U32 & Array>): match secure: case True{}: W.tls.recv.words(s, wire.max(), ms) @@ -81,14 +84,20 @@ def wire.recv(secure: Bool, s: Socket, ms: U32) W.recv.words(s, wire.max(), ms) # a send.words.deadline answer without its count of octets accepted -def wire.sent(r: Socket & (U32 & Result<&1, &1, U32 & String, Unit>)) - -> IO(Socket & Result<&1, &1, U32 & String, Unit>): +def wire.sent( + r: Socket & (U32 & Result<&1, &1, U32 & String, Unit>) +) -> IO(Socket & Result<&1, &1, U32 & String, Unit>): (s, (n, res)) = r IO.pure(Socket & Result<&1, &1, U32 & String, Unit>, (s, res)) # send octets, the plain send bounded by the deadline -def wire.send(secure: Bool, s: Socket, +len: U32, buf: Array, ms: U32) - -> IO(Socket & Result<&1, &1, U32 & String, Unit>): +def wire.send( + secure: Bool, + s: Socket, + +len: U32, + buf: Array, + ms: U32 +) -> IO(Socket & Result<&1, &1, U32 & String, Unit>): match secure: case True{}: W.tls.send.words(s, len, buf) @@ -98,8 +107,12 @@ def wire.send(secure: Bool, s: Socket, +len: U32, buf: Array, ms: U32) W.send.words.deadline(s, len, buf, ms), wire.sent) # the TLS handshake with the host, when the exchange is secure -def wire.shake(secure: Bool, s: Socket, host: String, ms: U32) - -> IO(Socket & Result<&1, &1, U32 & String, Unit>): +def wire.shake( + secure: Bool, + s: Socket, + host: String, + ms: U32 +) -> IO(Socket & Result<&1, &1, U32 & String, Unit>): match secure: case True{}: W.tls.connect(s, host, ms) @@ -121,8 +134,13 @@ def wire.failed(+secure: Bool, s: Socket, answer: String) -> IO(Answer): _u => IO.pure(Answer, Failed{answer})) # a judged read: read again, or close and answer what was received -def wire.loop.on(+secure: Bool, s: Socket, r: Spec.Read, acc: Bytes.Bytes, - more: Socket -> Http.Hear -> Bytes.Bytes -> IO(Answer)) -> IO(Answer): +def wire.loop.on( + +secure: Bool, + s: Socket, + r: Spec.Read, + acc: Bytes.Bytes, + more: Socket -> Http.Hear -> Bytes.Bytes -> IO(Answer) +) -> IO(Answer): match r: case Spec.Again{h}: more(s)(h)(acc) @@ -132,24 +150,40 @@ def wire.loop.on(+secure: Bool, s: Socket, r: Spec.Read, acc: Bytes.Bytes, # a receive judged by a copy of it as text, dropped after the judging; the # octets themselves are appended packed -def wire.loop.copied(+secure: Bool, s: Socket, h: Http.Hear, - r: Bytes.Bytes & Bytes.Bytes, acc: Bytes.Bytes, - more: Socket -> Http.Hear -> Bytes.Bytes -> IO(Answer)) -> IO(Answer): +def wire.loop.copied( + +secure: Bool, + s: Socket, + h: Http.Hear, + r: Bytes.Bytes & Bytes.Bytes, + acc: Bytes.Bytes, + more: Socket -> Http.Hear -> Bytes.Bytes -> IO(Answer) +) -> IO(Answer): (kept, copy) = r wire.loop.on(secure, s, Spec.wire.read.next(h, Bytes.to_string(copy)), Bytes.append(acc, kept), more) # a read judged by its text, when its count alone does not decide it -def wire.loop.text(+secure: Bool, s: Socket, h: Http.Hear, piece: Bytes.Bytes, - acc: Bytes.Bytes, more: Socket -> Http.Hear -> Bytes.Bytes -> IO(Answer)) - -> IO(Answer): +def wire.loop.text( + +secure: Bool, + s: Socket, + h: Http.Hear, + piece: Bytes.Bytes, + acc: Bytes.Bytes, + more: Socket -> Http.Hear -> Bytes.Bytes -> IO(Answer) +) -> IO(Answer): wire.loop.copied(secure, s, h, Bytes.slice(piece, 0, 4294967295), acc, more) # a read judged by its count when that decides it # (laws/ReadsJudgedByCount.bend) -def wire.loop.judge(+secure: Bool, s: Socket, h: Http.Hear, piece: Bytes.Bytes, - acc: Bytes.Bytes, counted: Maybe<&2, Spec.Read>, - more: Socket -> Http.Hear -> Bytes.Bytes -> IO(Answer)) -> IO(Answer): +def wire.loop.judge( + +secure: Bool, + s: Socket, + h: Http.Hear, + piece: Bytes.Bytes, + acc: Bytes.Bytes, + counted: Maybe<&2, Spec.Read>, + more: Socket -> Http.Hear -> Bytes.Bytes -> IO(Answer) +) -> IO(Answer): match counted: case Some{r}: wire.loop.on(secure, s, r, Bytes.append(acc, piece), more) @@ -157,10 +191,16 @@ def wire.loop.judge(+secure: Bool, s: Socket, h: Http.Hear, piece: Bytes.Bytes, wire.loop.text(secure, s, h, piece, acc, more) # a receive's outcome: a failure is the answer -def wire.loop.un(+secure: Bool, +host: String, +port: U32, +ms: U32, - +h: Http.Hear, acc: Bytes.Bytes, +def wire.loop.un( + +secure: Bool, + +host: String, + +port: U32, + +ms: U32, + +h: Http.Hear, + acc: Bytes.Bytes, r: Socket & Result<&1, &1, U32 & String, U32 & Array>, - more: Socket -> Http.Hear -> Bytes.Bytes -> IO(Answer)) -> IO(Answer): + more: Socket -> Http.Hear -> Bytes.Bytes -> IO(Answer) +) -> IO(Answer): (s, res) = r match res: case Fail{(n, why)}: @@ -172,8 +212,16 @@ def wire.loop.un(+secure: Bool, +host: String, +port: U32, +ms: U32, # receive until wirespec.bend says the answer is whole, the octets appended # to what came before -def wire.loop(fuel: Nat, +secure: Bool, s: Socket, +host: String, +port: U32, - +ms: U32, h: Http.Hear, acc: Bytes.Bytes) -> IO(Answer): +def wire.loop( + fuel: Nat, + +secure: Bool, + s: Socket, + +host: String, + +port: U32, + +ms: U32, + h: Http.Hear, + acc: Bytes.Bytes +) -> IO(Answer): match fuel: case 0n: wire.failed(secure, s, Spec.wire.spent()) @@ -186,9 +234,14 @@ def wire.loop(fuel: Nat, +secure: Bool, s: Socket, +host: String, +port: U32, # --- one exchange --- # after the send: read the answer, or the send's failure -def wire.after.send(+secure: Bool, +host: String, +port: U32, +ms: U32, - +method: String, r: Socket & Result<&1, &1, U32 & String, Unit>) - -> IO(Answer): +def wire.after.send( + +secure: Bool, + +host: String, + +port: U32, + +ms: U32, + +method: String, + r: Socket & Result<&1, &1, U32 & String, Unit> +) -> IO(Answer): (s, res) = r match res: case Fail{(n, why)}: @@ -199,8 +252,15 @@ def wire.after.send(+secure: Bool, +host: String, +port: U32, +ms: U32, Bytes.new(0)) # send the octets an exchange carries, then read its answer -def wire.put(+secure: Bool, s: Socket, +host: String, +port: U32, +ms: U32, - +method: String, payload: Bytes.Bytes) -> IO(Answer): +def wire.put( + +secure: Bool, + s: Socket, + +host: String, + +port: U32, + +ms: U32, + +method: String, + payload: Bytes.Bytes +) -> IO(Answer): Bytes.Bytes{+len, buf} = payload IO.bind(Socket & Result<&1, &1, U32 & String, Unit>, Answer, wire.send(secure, s, len, buf, ms), @@ -208,9 +268,15 @@ def wire.put(+secure: Bool, s: Socket, +host: String, +port: U32, +ms: U32, # after the handshake: send, or the handshake's failure (the socket closed # plainly, as no TLS session was made) -def wire.after.shake(+secure: Bool, +host: String, +port: U32, +ms: U32, - +method: String, payload: Bytes.Bytes, - r: Socket & Result<&1, &1, U32 & String, Unit>) -> IO(Answer): +def wire.after.shake( + +secure: Bool, + +host: String, + +port: U32, + +ms: U32, + +method: String, + payload: Bytes.Bytes, + r: Socket & Result<&1, &1, U32 & String, Unit> +) -> IO(Answer): (s, res) = r match res: case Fail{(n, why)}: @@ -221,9 +287,15 @@ def wire.after.shake(+secure: Bool, +host: String, +port: U32, +ms: U32, wire.put(secure, s, host, port, ms, method, payload) # after the connect: the handshake, or the connect's failure -def wire.after.connect(+secure: Bool, +host: String, +port: U32, +ms: U32, - +method: String, payload: Bytes.Bytes, - r: Result<&1, &1, U32 & String, Socket>) -> IO(Answer): +def wire.after.connect( + +secure: Bool, + +host: String, + +port: U32, + +ms: U32, + +method: String, + payload: Bytes.Bytes, + r: Result<&1, &1, U32 & String, Socket> +) -> IO(Answer): match r: case Fail{(n, why)}: IO.pure(Answer, @@ -234,9 +306,10 @@ def wire.after.connect(+secure: Bool, +host: String, +port: U32, +ms: U32, r2 => wire.after.shake(secure, host, port, ms, method, payload, r2)) # a connect that failed tries the next address; one that worked is kept -def wire.dial.next(r: Result<&1, &1, U32 & String, Socket>, - more: Unit -> IO(Result<&1, &1, U32 & String, Socket>)) - -> IO(Result<&1, &1, U32 & String, Socket>): +def wire.dial.next( + r: Result<&1, &1, U32 & String, Socket>, + more: Unit -> IO(Result<&1, &1, U32 & String, Socket>) +) -> IO(Result<&1, &1, U32 & String, Socket>): match r: case Done{s}: IO.pure(Result<&1, &1, U32 & String, Socket>, Done{s}) @@ -245,8 +318,12 @@ def wire.dial.next(r: Result<&1, &1, U32 & String, Socket>, # connect to each address in turn until one connects; the last one's # failure when none does -def wire.dial(rest: List<&2, String>, +first: String, +port: U32, +ms: U32) - -> IO(Result<&1, &1, U32 & String, Socket>): +def wire.dial( + rest: List<&2, String>, + +first: String, + +port: U32, + +ms: U32 +) -> IO(Result<&1, &1, U32 & String, Socket>): match rest: case []: W.connect(first, port, ms) @@ -258,9 +335,15 @@ def wire.dial(rest: List<&2, String>, +first: String, +port: U32, +ms: U32) # after the resolve: connect, or the resolve's failure (no address at all is # ENOENT, as bend-kit-dns reports a name with none) -def wire.after.resolve(+secure: Bool, +host: String, +port: U32, +ms: U32, - +method: String, payload: Bytes.Bytes, - r: Result<&1, &1, U32 & String, List<&2, String>>) -> IO(Answer): +def wire.after.resolve( + +secure: Bool, + +host: String, + +port: U32, + +ms: U32, + +method: String, + payload: Bytes.Bytes, + r: Result<&1, &1, U32 & String, List<&2, String>> +) -> IO(Answer): match r: case Fail{(n, why)}: IO.pure(Answer, @@ -274,8 +357,9 @@ def wire.after.resolve(+secure: Bool, +host: String, +port: U32, +ms: U32, c => wire.after.connect(secure, host, port, ms, method, payload, c)) # the OS resolver's addresses, NUL-separated, as a list -def wire.looked(r: Result<&1, &1, U32 & String, String>) - -> IO(Result<&1, &1, U32 & String, List<&2, String>>): +def wire.looked( + r: Result<&1, &1, U32 & String, String> +) -> IO(Result<&1, &1, U32 & String, List<&2, String>>): match r: case Fail{e}: IO.pure(Result<&1, &1, U32 & String, List<&2, String>>, Fail{e}) @@ -285,8 +369,10 @@ def wire.looked(r: Result<&1, &1, U32 & String, String>) # a host's addresses: a numeric address or localhost as it is, else the OS # resolver's answer -def wire.resolve(+host: String, literal: List<&2, String>) - -> IO(Result<&1, &1, U32 & String, List<&2, String>>): +def wire.resolve( + +host: String, + literal: List<&2, String> +) -> IO(Result<&1, &1, U32 & String, List<&2, String>>): match literal: case []: IO.bind(Result<&1, &1, U32 & String, String>, @@ -296,8 +382,14 @@ def wire.resolve(+host: String, literal: List<&2, String>) IO.pure(Result<&1, &1, U32 & String, List<&2, String>>, Done{ip <> t}) # the exchange once its octets are packed -def wire.run.with(+secure: Bool, +ms: U32, +host: String, +port: U32, - +method: String, payload: Bytes.Bytes) -> IO(Answer): +def wire.run.with( + +secure: Bool, + +ms: U32, + +host: String, + +port: U32, + +method: String, + payload: Bytes.Bytes +) -> IO(Answer): IO.bind(Result<&1, &1, U32 & String, List<&2, String>>, Answer, wire.resolve(host, Dns.resolve.literal.all(host)), r => wire.after.resolve(secure, host, port, ms, method, payload, r)) @@ -305,18 +397,38 @@ def wire.run.with(+secure: Bool, +ms: U32, +host: String, +port: U32, # a request with this method, sent to a host as wirespec.bend says, with # its tail of octets after it, every call bounded by the deadline; its whole # answer -def wire.run(+secure: Bool, +ms: U32, +host: String, +port: U32, - +method: String, req: String, tail: Bytes.Bytes) -> IO(Answer): +def wire.run( + +secure: Bool, + +ms: U32, + +host: String, + +port: U32, + +method: String, + req: String, + tail: Bytes.Bytes +) -> IO(Answer): wire.run.with(secure, ms, host, port, method, Bytes.append(Bytes.from_string(Spec.wire.payload(req)), tail)) # a request sent to a host, its tail of octets after it, and its whole answer # read back, with the default deadline -def wire.talk(secure: Bool, host: String, port: U32, method: String, - req: String, tail: Bytes.Bytes) -> IO(Answer): +def wire.talk( + secure: Bool, + host: String, + port: U32, + method: String, + req: String, + tail: Bytes.Bytes +) -> IO(Answer): wire.run(secure, Spec.wire.ms.of(None{}), host, port, method, req, tail) # the same exchange, bounded by a timeout in milliseconds -def wire.talk.timed(secure: Bool, ms: U32, host: String, port: U32, - method: String, req: String, tail: Bytes.Bytes) -> IO(Answer): +def wire.talk.timed( + secure: Bool, + ms: U32, + host: String, + port: U32, + method: String, + req: String, + tail: Bytes.Bytes +) -> IO(Answer): wire.run(secure, Spec.wire.ms.of(Some{ms}), host, port, method, req, tail) diff --git a/src/wirespec.bend b/src/wirespec.bend index d4ccf6c..3877f9d 100644 --- a/src/wirespec.bend +++ b/src/wirespec.bend @@ -12,7 +12,6 @@ import ./http.bend as Http import ./url.bend as Url import ./body.bend as Body import ./pct.bend as Pct -import ./qs.bend as Qs # --- the deadline --- @@ -81,9 +80,15 @@ type Exchange is Data: Exchange{secure: Bool, host: String, port: U32, method: String, req: String} # the exchange once it is known whether the scheme wants TLS -def wire.exchange.at(+method: String, +secure: Bool, +host: String, - +port: U32, path: String, headers: List<&2, Http.Header>, body: String) - -> Exchange: +def wire.exchange.at( + +method: String, + +secure: Bool, + +host: String, + +port: U32, + path: String, + headers: List<&2, Http.Header>, + body: String +) -> Exchange: Exchange{secure, host, port, method, Http.request.at(method, secure, host, port, path, headers, body)} @@ -96,8 +101,12 @@ def wire.exchange.method(ex: Exchange) -> Maybe<&2, String>: Some{method} # a request with this method, headers and body to a URL that came apart -def wire.exchange(method: String, l: Url.Loc, headers: List<&2, Http.Header>, - body: String) -> Exchange: +def wire.exchange( + method: String, + l: Url.Loc, + headers: List<&2, Http.Header>, + body: String +) -> Exchange: match l: case Url.Bad{why}: NoUrl{why} @@ -107,8 +116,12 @@ def wire.exchange(method: String, l: Url.Loc, headers: List<&2, Http.Header>, # a request with n octets of body to a URL that came apart: the request text # ends at the blank line, and the octets go after it -def wire.exchange.octets(+method: String, l: Url.Loc, - headers: List<&2, Http.Header>, n: Nat) -> Exchange: +def wire.exchange.octets( + +method: String, + l: Url.Loc, + headers: List<&2, Http.Header>, + n: Nat +) -> Exchange: match l: case Url.Bad{why}: NoUrl{why} @@ -120,8 +133,12 @@ def wire.exchange.octets(+method: String, l: Url.Loc, # a request with a body of this shape to a URL that came apart: text inside # the request text as UTF-8, octets after it # (laws/OctetBodiesSentUnchanged.bend) -def wire.exchange.body(method: String, l: Url.Loc, - headers: List<&2, Http.Header>, b: Body.Shape) -> Exchange: +def wire.exchange.body( + method: String, + l: Url.Loc, + headers: List<&2, Http.Header>, + b: Body.Shape +) -> Exchange: match b: case Body.ShapeText{text}: wire.exchange(method, l, headers, text) @@ -231,8 +248,11 @@ def wire.read.counted(+h: Http.Hear, +m: Nat, counts: Bool) -> Maybe<&2, Read>: None{} # a read of m octets: none is the close -def wire.read.count.at(+h: Http.Hear, +m: Nat, closed: Bool) - -> Maybe<&2, Read>: +def wire.read.count.at( + +h: Http.Hear, + +m: Nat, + closed: Bool +) -> Maybe<&2, Read>: match closed: case True{}: Some{Heard{}} @@ -346,8 +366,13 @@ def wire.fail.resolve(host: String, +n: U32, none: Bool) -> String: "6\ncould not resolve " ++ host ++ ": " ++ wire.cause(n) # a call that ran out of time, by its phase -def wire.fail.late(p: Phase, host: String, +port: U32, +ms: U32, +n: U32) - -> String: +def wire.fail.late( + p: Phase, + host: String, + +port: U32, + +ms: U32, + +n: U32 +) -> String: match p: case Resolve{}: wire.fail.resolve(host, n, U32.is_eq(n, 2)) @@ -364,8 +389,13 @@ def wire.fail.late(p: Phase, host: String, +port: U32, +ms: U32, +n: U32) "28\n" ++ host ++ " sent nothing for " ++ U32.show(ms) ++ " ms" # a call that failed for another reason, by its phase -def wire.fail.other(p: Phase, host: String, +port: U32, +n: U32, why: String) - -> String: +def wire.fail.other( + p: Phase, + host: String, + +port: U32, + +n: U32, + why: String +) -> String: match p: case Resolve{}: wire.fail.resolve(host, n, U32.is_eq(n, 2)) @@ -381,8 +411,15 @@ def wire.fail.other(p: Phase, host: String, +port: U32, +n: U32, why: String) "56\nthe answer from " ++ host ++ " was cut short: " ++ wire.cause(n) # a failure once it is known whether it ran out of time -def wire.fail.of(p: Phase, host: String, +port: U32, +ms: U32, +n: U32, - why: String, late: Bool) -> String: +def wire.fail.of( + p: Phase, + host: String, + +port: U32, + +ms: U32, + +n: U32, + why: String, + late: Bool +) -> String: match late: case True{}: wire.fail.late(p, host, port, ms, n) @@ -405,6 +442,12 @@ def wire.fail.of(p: Phase, host: String, +port: U32, +ms: U32, +n: U32, # (laws/FailuresReportedByPhase.bend, laws/ErrnoNamesAreLinux.bend), and # that the reason reaches `Client.Err` unchanged # (laws/TimeoutsReadAsTimedOut.bend, laws/InterimResponsesSkipped.bend). -def wire.fail(p: Phase, host: String, +port: U32, +ms: U32, +n: U32, - why: String) -> String: +def wire.fail( + p: Phase, + host: String, + +port: U32, + +ms: U32, + +n: U32, + why: String +) -> String: wire.fail.of(p, host, port, ms, n, why, U32.is_eq(n, wire.etimedout()))