Skip to content

strengthen contracts on response-code and response-seconds - #61

Merged
jeapostrophe merged 2 commits into
racket:masterfrom
LiberalArtist:response-contract
Apr 4, 2019
Merged

jeapostrophe merged 2 commits into
racket:masterfrom
LiberalArtist:response-contract

Conversation

@LiberalArtist

Copy link
Copy Markdown
Contributor

Previously, both accepted number?, which was too permissive.

This commit adds response-code/c, which is defined as
(integer-in 100 999) per RFC 2616 §6.1.1 ("The Status-Code
element is a 3-digit integer ...").

The contract for response-seconds is real?, which is the
range of seconds->date (which is used internally to generate the
Last-Modified header).

Previously, both accepted `number?`, which was too permissive.

This commit adds `response-code/c`, which is defined as
`(integer-in 100 999)` per [RFC 2616 §6.1.1][1] ("The Status-Code
element is a 3-digit integer ...").

The contract for `response-seconds` is `real?`, which is the
range of `seconds->date` (which is used internally to generate the
`Last-Modified` header).

[1]: https://tools.ietf.org/html/rfc2616#section-6.1.1
@LiberalArtist

LiberalArtist commented Apr 4, 2019 •

Copy link
Copy Markdown
Contributor Author

This pull request also bumps the version number for web-server-lib to 1.3, which probably should have been done before.

LiberalArtist added a commit to LiberalArtist/typed-racket that referenced this pull request Apr 4, 2019
- Weaken the types of `response-output` and
  the `#:output` argument to `response/output`
  from `Void` to `Any`, corresponding to
  <racket/web-server@a93685>
  and v1.2 of the `web-server-lib`.

  The return type should really be `AnyValues`
  to match the contract `any`,
  but Typed Racket can't generate a contract for `AnyValues`.

- Update the types for cookie-related functions
  to reflect the re-implementation based on `net/cookies/server`
  from <racket/web-server@7974d4d>.
  This commit adds only as much of `typed/net/cookies/server`
  and `typed/net/cookies/common` as needed for `typed/web-server/http`.

- Document that `net/cookie` is deprecated.

- Update the types for `valid-id-cookie?` and `request-id-cookie`
  to support the `#:shelf-life` argument added in
  <racket/web-server@626ad02>.

- Add the value `temporarily/same-method` with
  the type `Redirection-Status`, corresponding
  to <racket/web-server@4601f4>.

- Correct the types of `response-seconds` and the
  corresponding arguments to `response/full`,
  `response/output`, and `response/xexpr`
  to use `Real`.
  While this corresponds to
  <racket/web-server#61>,
  using response values containing complex numbers
  would cause runtime errors even before this:
  the `response-seconds` is passed to `seconds->date`.
@bold{is not guaranteed to be an integer.}

@history[#:changed "1.3"
"Weakened result contract to allow any number."]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand the rationale behind 4cfb68e (I couldn't find a PR 15447), but that is what it did.

@jeapostrophe

Copy link
Copy Markdown
Contributor

Thank you, this is great

@jeapostrophe
jeapostrophe merged commit 53ce64f into racket:master Apr 4, 2019
LiberalArtist added a commit to LiberalArtist/typed-racket that referenced this pull request Apr 4, 2019
- Weaken the types of `response-output` and
  the `#:output` argument to `response/output`
  from `Void` to `Any`, corresponding to
  <racket/web-server@a93685>
  and v1.2 of the `web-server-lib`.

  The return type should really be `AnyValues`
  to match the contract `any`,
  but Typed Racket can't generate a contract for `AnyValues`.

- Update the types for cookie-related functions
  to reflect the re-implementation based on `net/cookies/server`
  from <racket/web-server@7974d4d>.
  This commit adds only as much of `typed/net/cookies/server`
  and `typed/net/cookies/common` as needed for `typed/web-server/http`.

- Document that `net/cookie` is deprecated.

- Update the types for `valid-id-cookie?` and `request-id-cookie`
  to support the `#:shelf-life` argument added in
  <racket/web-server@626ad02>.

- Add the value `temporarily/same-method` with
  the type `Redirection-Status`, corresponding
  to <racket/web-server@4601f4>.

- Correct the types of `response-seconds` and the
  corresponding arguments to `response/full`,
  `response/output`, and `response/xexpr`
  to use `Real`.
  While this corresponds to
  <racket/web-server#61>,
  using response values containing complex numbers
  would cause runtime errors even before this:
  the `response-seconds` is passed to `seconds->date`.
LiberalArtist added a commit to LiberalArtist/typed-racket that referenced this pull request Apr 4, 2019
- Weaken the types of `response-output` and
  the `#:output` argument to `response/output`
  from `Void` to `Any`, corresponding to
  <racket/web-server@a93685>
  and v1.2 of the `web-server-lib`.

  The return type should really be `AnyValues`
  to match the contract `any`,
  but Typed Racket can't generate a contract for `AnyValues`.

- Update the types for cookie-related functions
  to reflect the re-implementation based on `net/cookies/server`
  from <racket/web-server@7974d4d>.
  This commit adds only as much of `typed/net/cookies/server`
  and `typed/net/cookies/common` as needed for `typed/web-server/http`.

- Document that `net/cookie` is deprecated.

- Update the types for `valid-id-cookie?` and `request-id-cookie`
  to support the `#:shelf-life` argument added in
  <racket/web-server@626ad02>.

- Add the value `temporarily/same-method` with
  the type `Redirection-Status`, corresponding
  to <racket/web-server@4601f4>.

- Correct the types of `response-seconds` and the
  corresponding arguments to `response/full`,
  `response/output`, and `response/xexpr`
  to use `Real`.
  While this corresponds to
  <racket/web-server#61>,
  using response values containing complex numbers
  would cause runtime errors even before this:
  the `response-seconds` is passed to `seconds->date`.
samth pushed a commit to racket/typed-racket that referenced this pull request Apr 10, 2019
- Weaken the types of `response-output` and
  the `#:output` argument to `response/output`
  from `Void` to `Any`, corresponding to
  <racket/web-server@a93685>
  and v1.2 of the `web-server-lib`.

  The return type should really be `AnyValues`
  to match the contract `any`,
  but Typed Racket can't generate a contract for `AnyValues`.

- Update the types for cookie-related functions
  to reflect the re-implementation based on `net/cookies/server`
  from <racket/web-server@7974d4d>.
  This commit adds only as much of `typed/net/cookies/server`
  and `typed/net/cookies/common` as needed for `typed/web-server/http`.

- Document that `net/cookie` is deprecated.

- Update the types for `valid-id-cookie?` and `request-id-cookie`
  to support the `#:shelf-life` argument added in
  <racket/web-server@626ad02>.

- Add the value `temporarily/same-method` with
  the type `Redirection-Status`, corresponding
  to <racket/web-server@4601f4>.

- Correct the types of `response-seconds` and the
  corresponding arguments to `response/full`,
  `response/output`, and `response/xexpr`
  to use `Real`.
  While this corresponds to
  <racket/web-server#61>,
  using response values containing complex numbers
  would cause runtime errors even before this:
  the `response-seconds` is passed to `seconds->date`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants