Improve headers inputs in zio.http.api to operate on structured data
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
Added https://github.com/zio/zio-http/pull/1551 for acceptCharset
Added #1552 for CacheControl
Created #1576 for Origin.
Created #1581 for Accept.
Added #1593 for Allow
Added https://github.com/zio/zio-http/pull/1632 for Connection
Added #1630 for Accept-Language
Added https://github.com/zio/zio-http/pull/1640 for Host
Added https://github.com/zio/zio-http/pull/1644 for Expires
Added https://github.com/zio/zio-http/pull/1645 for AccessControlMaxAge
Added https://github.com/zio/zio-http/pull/1648 for Content-Encoding
Is anyone looking into Server header?
Added https://github.com/zio/zio-http/pull/1674 for server header
I'm working on Authorization header. I'll submit a PR soon.
Any individual item above will count for a ticket in the ZIO Hackathon 2022, for those of you participating.
I'd like to work on accessControlAllowMethods
I can take retryAfter
Working on location
I'd like to work on warning
i can take transferEncoding
I'll work on acceptRanges, ifRange and expect
I am working on all content related stuff for #1703
acceptControlAllowCrdentials #1803
Seems to be done