-
-
Notifications
You must be signed in to change notification settings - Fork 706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Extend WebSession to support range requests. #2887
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,6 +138,12 @@ interface WebSession @0xa50711a14d35a8ce extends(Grain.UiSession) { | |
matchesNoneOf @7 :List(ETag); # If-None-Match | ||
} | ||
|
||
rangeHint @10 :Range; | ||
# Requests that the server returns a range of bytes from the document rather than the entire | ||
# document. If the server accepts the range hint, it will return a `content` response with | ||
# `statusCode` set to `partialContent`. However, the server is also free to ignore the | ||
# `rangeHint`. | ||
|
||
additionalHeaders @3 :List(Header); | ||
# Additional headers present in the request. Only whitelisted headers are | ||
# permitted. | ||
|
@@ -173,6 +179,7 @@ interface WebSession @0xa50711a14d35a8ce extends(Grain.UiSession) { | |
mimeType @0 :Text; | ||
content @1 :Data; | ||
encoding @2 :Text; # Content-Encoding header (optional). | ||
range @3 :Range; # Content-Range header (optional). | ||
} | ||
|
||
struct PutContent { | ||
|
@@ -181,6 +188,7 @@ interface WebSession @0xa50711a14d35a8ce extends(Grain.UiSession) { | |
mimeType @0 :Text; | ||
content @1 :Data; | ||
encoding @2 :Text; # Content-Encoding header (optional). | ||
range @3 :Range; # Content-Range header (optional). | ||
} | ||
|
||
struct ETag { | ||
|
@@ -190,6 +198,28 @@ interface WebSession @0xa50711a14d35a8ce extends(Grain.UiSession) { | |
# semantically equivalent | ||
} | ||
|
||
struct Range { | ||
# Specifies a range of bytes within a larger blob. Used for `Range` and `Content-Range` | ||
# headers. | ||
|
||
start @0 :UInt64; | ||
# Start point of the range, in bytes. | ||
|
||
end :union { | ||
# Endpoint of the range, in bytes. | ||
|
||
endOfContent @1 :Void; | ||
position @2 :UInt64; | ||
} | ||
|
||
fullSize :union { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can tell, this is only valid in responses. Maybe we should remove it, since we only currently use the Range struct in requests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh. It's been a long time since I wrote this, but I wonder if I had intended to include a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See the comment you wrote below -- looks like the idea was to just insist that the app returns the range that was actually asked for, so the supervisor only needs to check the status code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But how is the overall size communicated? I guess the final BTW, what makes you say that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was only thinking about GET requests. I guess I don't feel that strongly about this. |
||
# Size of the overall file (not just this range). | ||
|
||
unknown @3 :Void; | ||
bytes @4 :UInt64; | ||
} | ||
} | ||
|
||
struct Cookie { | ||
name @0 :Text; | ||
value @1 :Text; | ||
|
@@ -243,11 +273,22 @@ interface WebSession @0xa50711a14d35a8ce extends(Grain.UiSession) { | |
created @1 $httpStatus(id = 201, title = "Created"); | ||
accepted @2 $httpStatus(id = 202, title = "Accepted"); | ||
|
||
noContent @3 $httpStatus(id = 204, title = "No Content"); | ||
partialContent @4 $httpStatus(id = 206, title = "Partial Content"); | ||
multiStatus @5 $httpStatus(id = 207, title = "Multi-Status"); | ||
# Indicates that the server is only returning the range of bytes that the client requested | ||
# via `Context.rangeHint`. This status is only allowed when a `rangeHint` was present. | ||
# | ||
# (In traditional HTTP, the server could return an arbitrary range that has nothing to do | ||
# with the range the client requested. Since this is useless in practice and annoying to | ||
# check for, WebSession only allows the server to return exactly the range the client | ||
# wanted. If an http-bridge app returns a range that doesn't match what the client asked | ||
# for, sandstorm-http-bridge will throw an exception instead.) | ||
|
||
# This seems to fit better here than in the 3xx range | ||
# TODO(apibump): Only the three status codes above should actually be used. The status codes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/three/four/ |
||
# below this point actually represent special cases that are represented by using different | ||
# fields of the Response union. | ||
|
||
noContent @3 $httpStatus(id = 204, title = "No Content"); | ||
multiStatus @5 $httpStatus(id = 207, title = "Multi-Status"); | ||
notModified @6 $httpStatus(id = 304, title = "Not Modified"); | ||
|
||
# Not applicable: | ||
|
@@ -273,21 +314,24 @@ interface WebSession @0xa50711a14d35a8ce extends(Grain.UiSession) { | |
notAcceptable @4 $httpStatus(id = 406, title = "Not Acceptable"); | ||
conflict @5 $httpStatus(id = 409, title = "Conflict"); | ||
gone @6 $httpStatus(id = 410, title = "Gone"); | ||
preconditionFailed @11 $httpStatus(id = 412, title = "Precondition Failed"); | ||
requestEntityTooLarge @7 $httpStatus(id = 413, title = "Request Entity Too Large"); | ||
requestUriTooLong @8 $httpStatus(id = 414, title = "Request-URI Too Long"); | ||
unsupportedMediaType @9 $httpStatus(id = 415, title = "Unsupported Media Type"); | ||
rangeNotSatisfiable @13 $httpStatus(id = 416, title = "Range Not Satisfiable"); | ||
imATeapot @10 $httpStatus(id = 418, title = "I'm a teapot"); | ||
unprocessableEntity @12 $httpStatus(id = 422, title = "Unprocessable Entity"); | ||
|
||
preconditionFailed @11 $httpStatus(id = 412, title = "Precondition Failed"); | ||
# TODO(apibump): This enum value is deprecated. Use the union branch instead. | ||
|
||
# Not applicable: | ||
# 401 Unauthorized: We don't do HTTP authentication. | ||
# 402 Payment Required: LOL | ||
# 407 Proxy Authentication Required: Not a proxy. | ||
# 408 Request Timeout: Not possible; the entire request is provided with the call. | ||
# 411 Length Required: Request is framed using Cap'n Proto. | ||
# 412 Precondition Failed: If we implement preconditions, they should be handled | ||
# separately from errors. | ||
# 412 Precondition Failed: Preconditions are handled by a separate union branch. | ||
# TODO(apibump): Oops, 412 is actually defined above. It should be removed. | ||
# 416 Requested Range Not Satisfiable: Ranges not implemented (might be later). | ||
# 417 Expectation Failed: Like 412. | ||
# Others: Not standard. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit of a tangent, but: would it actually break anything to delete PutContent per the comment? the layout is exactly the same so it should be wire compatible. The type IDs are different, but it's hard for me to imagine that anything uses that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be wire-compatible, but not source-compatible. Some apps could have their builds broken. Maybe we don't care that much...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt very many apps actually use this directly, and for the ones that do it's a trivial fix. But probably doesn't make sense to change it as part of this patch.