lean4-htt/tests/lean/run/async_http_string_quoting.lean
Sofia Rodrigues 551086c854
feat: add core HTTP data types (#12126)
This PR introduces the core HTTP data types: `Request`, `Response`,
`Status`, `Version`, and `Method`. Currently, URIs are represented as
`String` and headers as `HashMap String (Array String)`. These are
placeholders, future PRs will replace them with strict implementations.

This contains the same code as #10478, divided into separate pieces to
facilitate easier review.

The pieces of this feature are:
- Core data structures: #12126
- Headers: #12127
- URI:  #12128
- Body: #12144
- H1: #12146
- Server: #12151
- Client:

---------

Co-authored-by: Rob23oba <152706811+Rob23oba@users.noreply.github.com>
2026-03-04 14:32:29 +00:00

85 lines
3.8 KiB
Text

import Std.Internal.Http.Internal.String
import Std.Internal.Http.Internal.Char
open Std.Http.Internal
private def c (n : Nat) : Char := Char.ofNat n
#guard Std.Http.Internal.Char.qdtext (c 0x08) = false
#guard Std.Http.Internal.Char.qdtext (c 0x09) = true
#guard Std.Http.Internal.Char.qdtext (c 0x0a) = false
#guard Std.Http.Internal.Char.qdtext (c 0x1f) = false
#guard Std.Http.Internal.Char.qdtext (c 0x20) = true
#guard Std.Http.Internal.Char.qdtext (c 0x21) = true
#guard Std.Http.Internal.Char.qdtext (c 0x22) = false
#guard Std.Http.Internal.Char.qdtext (c 0x23) = true
#guard Std.Http.Internal.Char.qdtext (c 0x5b) = true
#guard Std.Http.Internal.Char.qdtext (c 0x5c) = false
#guard Std.Http.Internal.Char.qdtext (c 0x5d) = true
#guard Std.Http.Internal.Char.qdtext (c 0x7e) = true
#guard Std.Http.Internal.Char.qdtext (c 0x7f) = false
#guard Std.Http.Internal.Char.quotedPairChar (c 0x08) = false
#guard Std.Http.Internal.Char.quotedPairChar (c 0x09) = true
#guard Std.Http.Internal.Char.quotedPairChar (c 0x1f) = false
#guard Std.Http.Internal.Char.quotedPairChar (c 0x20) = true
#guard Std.Http.Internal.Char.quotedPairChar (c 0x21) = true
#guard Std.Http.Internal.Char.quotedPairChar (c 0x22) = true
#guard Std.Http.Internal.Char.quotedPairChar (c 0x5c) = true
#guard Std.Http.Internal.Char.quotedPairChar (c 0x7e) = true
#guard Std.Http.Internal.Char.quotedPairChar (c 0x7f) = false
#guard Std.Http.Internal.Char.quotedStringChar (c 0x09) = true
#guard Std.Http.Internal.Char.quotedStringChar (c 0x20) = true
#guard Std.Http.Internal.Char.quotedStringChar (c 0x22) = true
#guard Std.Http.Internal.Char.quotedStringChar (c 0x5c) = true
#guard Std.Http.Internal.Char.quotedStringChar (c 0x0a) = false
#guard Std.Http.Internal.Char.quotedStringChar (c 0x0d) = false
#guard Std.Http.Internal.Char.quotedStringChar (c 0x7f) = false
#guard quoteHttpString? "token" = some "token"
#guard quoteHttpString? "a\t " = some "\"a\t \""
#guard quoteHttpString? "atabpo\n\t " = none
#guard quoteHttpString? "" = some "\"\""
#guard quoteHttpString? "\"" = some "\"\\\"\""
#guard quoteHttpString? "\\" = some "\"\\\\\""
#guard quoteHttpString? "\"\\\"" = some "\"\\\"\\\\\\\"\""
#guard quoteHttpString? "abc\rdef" = none
#guard quoteHttpString? "abc\ndef" = none
#guard quoteHttpString? "abc\u0000def" = none
#guard unquoteHttpString? "\"token\"" = some "token"
#guard unquoteHttpString? "\"a\\\\\\\"b\"" = some "a\\\"b"
#guard unquoteHttpString? "\"line1\nline2\"" = none
#guard unquoteHttpString? "\"\"" = some ""
#guard unquoteHttpString? "\"\\\\\"" = some "\\"
#guard unquoteHttpString? "\"\\\"\"" = some "\""
#guard unquoteHttpString? "\"a\\tb\"" = some "atb"
#guard unquoteHttpString? "\"a\tb\"" = some "a\tb"
#guard unquoteHttpString? "token" = some "token"
#guard unquoteHttpString? "\"" = none
#guard unquoteHttpString? "\"abc" = none
#guard unquoteHttpString? "\"abc\\\"" = none
#guard unquoteHttpString? "\"abc\\\n\"" = none
#guard unquoteHttpString? "\"abc\r\"" = none
private def isQuotedString (s : String) : Bool :=
s.startsWith '"' && (unquoteHttpString? s).isSome
#guard isQuotedString "\"abc\"" = true
#guard isQuotedString "\"ab\\\\\\\"c\"" = true
#guard isQuotedString "\"ab\nc\"" = false
#guard isQuotedString "\"\"" = true
#guard isQuotedString "\"\\\"\"" = true
#guard isQuotedString "\"\\\\\"" = true
#guard isQuotedString "abc" = false
#guard isQuotedString "\"" = false
#guard isQuotedString "\"abc" = false
#guard isQuotedString "\"abc\\\"" = false
#guard unquoteHttpString? (quoteHttpString! "abc\t ") = some "abc\t "
#guard unquoteHttpString? (quoteHttpString! "a\\\"b") = some "a\\\"b"
#guard unquoteHttpString? (quoteHttpString! "") = some ""
#guard unquoteHttpString? (quoteHttpString! "\"") = some "\""
#guard unquoteHttpString? (quoteHttpString! "\\") = some "\\"
#guard unquoteHttpString? (quoteHttpString! " !#$%&'()*+,-./:;<=>?@[\\]^_`{|}~") = some " !#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"