zio-http icon indicating copy to clipboard operation
zio-http copied to clipboard

Improve headers inputs in zio.http.api to operate on structured data

Open jdegoes opened this issue 3 years ago • 8 comments

Is your feature request related to a problem? Please describe.

The header inputs, which one can construct using zio.http.api.In, and which are defined in /src/main/scala/zio/http/api/HeaderInputs, currently produce (/accept) a String value, which is unstructured.

Unstructured data is more difficult to work with and may lead to protocol errors if the user does not happen to generate or parse exactly the right header value structure.

Describe the solution you'd like

In order to provide a safer and more useful way to interact with header values, we can change the definitions to accept/produce structured values. For example, instead of In.accept returning type In[String], it could return type In[MimeType], for some sealed trait MimeType. This can be done by utilizing the In#transform method, and by implementing a pair of highly-optimized conversion functions: one to convert the string to a specialized, type-safe data type, and the other, to convert the type-safe data type to a string.

The In data type is located in src/main/scala/zio/http/api/In. The new type-safe data types for header values should be located in zio.http.model (maybe in the headers subpackage?).

Given the scope of this work, each person who wants to work on this should pick one of the following headers to work on, claim that in the comments below, and submit a pull request for that specific header. When completed, the box may be checked.

  • [ ] accept
  • [x] acceptCharset
  • [x] acceptEncoding
  • [ ] acceptLanguage
  • [ ] acceptRanges
  • [ ] acceptPatch
  • [ ] accessControlAllowCredentials
  • [ ] accessControlAllowHeaders
  • [ ] accessControlAllowMethods
  • [ ] accessControlAllowOrigin
  • [ ] accessControlExposeHeaders
  • [ ] accessControlMaxAge
  • [ ] accessControlRequestHeaders
  • [ ] accessControlRequestMethod
  • [x] age
  • [ ] allow
  • [ ] authorization
  • [x] cacheControl
  • [ ] connection
  • [ ] contentBase
  • [ ] contentEncoding
  • [ ] contentLanguage
  • [x] contentLength
  • [ ] contentLocation
  • [ ] contentTransferEncoding
  • [ ] contentDisposition
  • [ ] contentMd5
  • [ ] contentRange
  • [ ] contentSecurityPolicy
  • [ ] contentType
  • [ ] cookie
  • [ ] date
  • [ ] dnt
  • [ ] etag
  • [ ] expect
  • [ ] expires
  • [ ] from
  • [ ] host
  • [ ] ifMatch
  • [ ] ifModifiedSince
  • [ ] ifNoneMatch
  • [ ] ifRange
  • [ ] ifUnmodifiedSince
  • [ ] lastModified
  • [ ] location
  • [ ] maxForwards
  • [ ] origin
  • [ ] pragma
  • [ ] proxyAuthenticate
  • [ ] proxyAuthorization
  • [ ] range
  • [ ] referer
  • [ ] retryAfter
  • [ ] secWebSocketLocation
  • [ ] secWebSocketOrigin
  • [ ] secWebSocketProtocol
  • [ ] secWebSocketVersion
  • [ ] secWebSocketKey
  • [ ] secWebSocketAccept
  • [ ] secWebSocketExtensions
  • [ ] server
  • [ ] setCookie
  • [ ] te
  • [ ] trailer
  • [ ] transferEncoding
  • [ ] upgrade
  • [ ] upgradeInsecureRequests
  • [ ] userAgent
  • [ ] vary
  • [ ] via
  • [ ] warning
  • [ ] webSocketLocation
  • [ ] webSocketOrigin
  • [ ] webSocketProtocol
  • [ ] wwwAuthenticate
  • [ ] xFrameOptions
  • [ ] xRequestedWith

Describe alternatives you've considered

None.

Additional context

jdegoes avatar Sep 19 '22 20:09 jdegoes

Added https://github.com/zio/zio-http/pull/1551 for acceptCharset

tobia80 avatar Sep 22 '22 17:09 tobia80

Added #1552 for CacheControl

devsprint avatar Sep 23 '22 10:09 devsprint

Created #1576 for Origin.

jakubjanecek avatar Sep 27 '22 14:09 jakubjanecek

Created #1581 for Accept.

jakubjanecek avatar Sep 27 '22 19:09 jakubjanecek

Added #1593 for Allow

ccerbusca avatar Sep 29 '22 10:09 ccerbusca

Added https://github.com/zio/zio-http/pull/1632 for Connection

wpoosanguansit avatar Oct 06 '22 14:10 wpoosanguansit

Added #1630 for Accept-Language

ccerbusca avatar Oct 14 '22 15:10 ccerbusca

Added https://github.com/zio/zio-http/pull/1640 for Host

geoffjohn11 avatar Oct 14 '22 21:10 geoffjohn11

Added https://github.com/zio/zio-http/pull/1644 for Expires

wpoosanguansit avatar Oct 16 '22 11:10 wpoosanguansit

Added https://github.com/zio/zio-http/pull/1645 for AccessControlMaxAge

wpoosanguansit avatar Oct 16 '22 12:10 wpoosanguansit

Added https://github.com/zio/zio-http/pull/1648 for Content-Encoding

wpoosanguansit avatar Oct 17 '22 03:10 wpoosanguansit

Is anyone looking into Server header?

geoffjohn11 avatar Oct 19 '22 11:10 geoffjohn11

Added https://github.com/zio/zio-http/pull/1674 for server header

geoffjohn11 avatar Oct 21 '22 16:10 geoffjohn11

I'm working on Authorization header. I'll submit a PR soon.

jakubjanecek avatar Oct 24 '22 20:10 jakubjanecek

Any individual item above will count for a ticket in the ZIO Hackathon 2022, for those of you participating.

jdegoes avatar Oct 25 '22 13:10 jdegoes

I'd like to work on accessControlAllowMethods

cyb3rn3t1c1an avatar Oct 27 '22 16:10 cyb3rn3t1c1an

I can take retryAfter

lemony312 avatar Oct 27 '22 18:10 lemony312

Working on location

walesho avatar Oct 27 '22 21:10 walesho

I'd like to work on warning

sf17490 avatar Oct 27 '22 21:10 sf17490

i can take transferEncoding

arumus avatar Oct 27 '22 23:10 arumus

I'll work on acceptRanges, ifRange and expect

cyb3rn3t1c1an avatar Oct 28 '22 00:10 cyb3rn3t1c1an

I am working on all content related stuff for #1703

987Nabil avatar Oct 28 '22 00:10 987Nabil

acceptControlAllowCrdentials #1803

devsprint avatar Nov 22 '22 10:11 devsprint

Seems to be done

vigoo avatar Jan 21 '23 13:01 vigoo