Skip to content

typed/web-server/http: update types (typed-racket-more v1.10) - #817

Merged
samth merged 1 commit into
racket:masterfrom
LiberalArtist:http-response
Apr 10, 2019
Merged

samth merged 1 commit into
racket:masterfrom
LiberalArtist:http-response

Conversation

@LiberalArtist

Copy link
Copy Markdown
Contributor
  • 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
    strengthen contracts on response-code and response-seconds 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

Copy link
Copy Markdown
Contributor Author

Note: This should build against any version of the web-server-lib package since racket/web-server@4601f4, but I didn't increment the package version number when I made the cookie-related changes or added temporarily/same-method. In racket/web-server#61 I finally increment the version to 1.3, so that is the earliest #:version the typed-racket-more package can test for to be sure of getting all of the relevant changes.

@jeapostrophe

Copy link
Copy Markdown
Contributor

LGTM

;; For backwards compatability:
;; these bindings are not exported by web-server/http,
;; but they were exported by previous versions of
;; web-server/http based on net/cookie.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not relevant to this PR, but was this a backwards-incompatible change to web-server/http in the past?

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.

If you mean the exported names: no. Line 86 should have said ;; typed/web-server/http based on net/cookie. (I will submit a correction shortly.) The names cookie?, cookie-name?, cookie-value?, and valid-domain? are not and never were provided by untyped web-server/http: they were only provided by typed/web-server/http.

If you mean about the underlying change: this was discussed at racket/web-server#20. IIRC the conclusion was basically that web-server/http had tried very hard to avoid making promises about its internal representation of cookies (e.g. it did not provide cookie?). So we took pains to keep the web-server/http API compatible (e.g. parsing dates provided as strings …), but ultimately wanted to track the underlying change in the web.

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.

The fact that typed/web-server/http previously provided a different opaque Cookie type than typed/net/cookie (the deprecated one) seems to be consistent with that rationale.

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.

@samth One difference I just thought of is that previously, the predicates could be used for occurrence typing (e.g. cookie-name? for Cookie-Name). The actual representation hasn't changed (they were and are still Strings, with slightly different well-formedness checks), but that might make some programs now fail to typecheck. I can add little wrappers to attach a String proposition.

@samth samth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is great. I particularly appreciate the comments.

@samth

samth commented Apr 4, 2019

Copy link
Copy Markdown
Member

Comment thread typed-racket-doc/info.rkt Resolved
- 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

Copy link
Copy Markdown
Contributor Author

@samth I've fixed the build failure you linked to. This new failure should just be because racket/web-server#61 hasn't gone into the snapshot yet: https://travis-ci.org/racket/typed-racket/jobs/515881390#L630-L635

@LiberalArtist

Copy link
Copy Markdown
Contributor Author

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.

3 participants