Skip to content

Commit 5ea5d8f

Browse files
Jake ChampionJakeChampion
authored andcommitted
Set the host-provided response statusText based upon the provided status code
Currently there is no way to retrieve the reason-phrase (status text) for the host-provided response. Until such a way exists, we can use the definition mapping from IANA https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
1 parent 46f5790 commit 5ea5d8f

File tree

8 files changed

+274
-79
lines changed

8 files changed

+274
-79
lines changed

.vscode/c_cpp_properties.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"name": "sm-wasi",
55
"includePath": [
66
"${workspaceFolder}/c-dependencies/spidermonkey/debug/include",
7-
"/opt/wasi-sdk/share/wasi-sysroot/include/"
7+
"/opt/wasi-sdk/share/wasi-sysroot/include/",
8+
"${workspaceFolder}/c-dependencies/js-compute-runtime"
89
],
910
"defines": [
1011
"__wasi__"

c-dependencies/js-compute-runtime/js-compute-builtins.cpp

Lines changed: 196 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4726,6 +4726,199 @@ JSString *status_message(JSObject *obj) {
47264726
return JS::GetReservedSlot(obj, Slots::StatusMessage).toString();
47274727
}
47284728

4729+
// TODO(jake): Remove this when the reason phrase host-call is implemented
4730+
void set_status_message_from_code(JSContext *cx, JSObject *obj, uint16_t code) {
4731+
auto phrase = "";
4732+
4733+
switch (code) {
4734+
case 100: // 100 Continue - https://tools.ietf.org/html/rfc7231#section-6.2.1
4735+
phrase = "Continue";
4736+
break;
4737+
case 101: // 101 Switching Protocols - https://tools.ietf.org/html/rfc7231#section-6.2.2
4738+
phrase = "Switching Protocols";
4739+
break;
4740+
case 102: // 102 Processing - https://tools.ietf.org/html/rfc2518
4741+
phrase = "Processing";
4742+
break;
4743+
case 200: // 200 OK - https://tools.ietf.org/html/rfc7231#section-6.3.1
4744+
phrase = "OK";
4745+
break;
4746+
case 201: // 201 Created - https://tools.ietf.org/html/rfc7231#section-6.3.2
4747+
phrase = "Created";
4748+
break;
4749+
case 202: // 202 Accepted - https://tools.ietf.org/html/rfc7231#section-6.3.3
4750+
phrase = "Accepted";
4751+
break;
4752+
case 203: // 203 Non-Authoritative Information - https://tools.ietf.org/html/rfc7231#section-6.3.4
4753+
phrase = "Non Authoritative Information";
4754+
break;
4755+
case 204: // 204 No Content - https://tools.ietf.org/html/rfc7231#section-6.3.5
4756+
phrase = "No Content";
4757+
break;
4758+
case 205: // 205 Reset Content - https://tools.ietf.org/html/rfc7231#section-6.3.6
4759+
phrase = "Reset Content";
4760+
break;
4761+
case 206: // 206 Partial Content - https://tools.ietf.org/html/rfc7233#section-4.1
4762+
phrase = "Partial Content";
4763+
break;
4764+
case 207: // 207 Multi-Status - https://tools.ietf.org/html/rfc4918
4765+
phrase = "Multi-Status";
4766+
break;
4767+
case 208: // 208 Already Reported - https://tools.ietf.org/html/rfc5842
4768+
phrase = "Already Reported";
4769+
break;
4770+
case 226: // 226 IM Used - https://tools.ietf.org/html/rfc3229
4771+
phrase = "IM Used";
4772+
break;
4773+
case 300: // 300 Multiple Choices - https://tools.ietf.org/html/rfc7231#section-6.4.1
4774+
phrase = "Multiple Choices";
4775+
break;
4776+
case 301: // 301 Moved Permanently - https://tools.ietf.org/html/rfc7231#section-6.4.2
4777+
phrase = "Moved Permanently";
4778+
break;
4779+
case 302: // 302 Found - https://tools.ietf.org/html/rfc7231#section-6.4.3
4780+
phrase = "Found";
4781+
break;
4782+
case 303: // 303 See Other - https://tools.ietf.org/html/rfc7231#section-6.4.4
4783+
phrase = "See Other";
4784+
break;
4785+
case 304: // 304 Not Modified - https://tools.ietf.org/html/rfc7232#section-4.1
4786+
phrase = "Not Modified";
4787+
break;
4788+
case 305: // 305 Use Proxy - https://tools.ietf.org/html/rfc7231#section-6.4.5
4789+
phrase = "Use Proxy";
4790+
break;
4791+
case 307: // 307 Temporary Redirect - https://tools.ietf.org/html/rfc7231#section-6.4.7
4792+
phrase = "Temporary Redirect";
4793+
break;
4794+
case 308: // 308 Permanent Redirect - https://tools.ietf.org/html/rfc7238
4795+
phrase = "Permanent Redirect";
4796+
break;
4797+
case 400: // 400 Bad Request - https://tools.ietf.org/html/rfc7231#section-6.5.1
4798+
phrase = "Bad Request";
4799+
break;
4800+
case 401: // 401 Unauthorized - https://tools.ietf.org/html/rfc7235#section-3.1
4801+
phrase = "Unauthorized";
4802+
break;
4803+
case 402: // 402 Payment Required - https://tools.ietf.org/html/rfc7231#section-6.5.2
4804+
phrase = "Payment Required";
4805+
break;
4806+
case 403: // 403 Forbidden - https://tools.ietf.org/html/rfc7231#section-6.5.3
4807+
phrase = "Forbidden";
4808+
break;
4809+
case 404: // 404 Not Found - https://tools.ietf.org/html/rfc7231#section-6.5.4
4810+
phrase = "Not Found";
4811+
break;
4812+
case 405: // 405 Method Not Allowed - https://tools.ietf.org/html/rfc7231#section-6.5.5
4813+
phrase = "Method Not Allowed";
4814+
break;
4815+
case 406: // 406 Not Acceptable - https://tools.ietf.org/html/rfc7231#section-6.5.6
4816+
phrase = "Not Acceptable";
4817+
break;
4818+
case 407: // 407 Proxy Authentication Required - https://tools.ietf.org/html/rfc7235#section-3.2
4819+
phrase = "Proxy Authentication Required";
4820+
break;
4821+
case 408: // 408 Request Timeout - https://tools.ietf.org/html/rfc7231#section-6.5.7
4822+
phrase = "Request Timeout";
4823+
break;
4824+
case 409: // 409 Conflict - https://tools.ietf.org/html/rfc7231#section-6.5.8
4825+
phrase = "Conflict";
4826+
break;
4827+
case 410: // 410 Gone - https://tools.ietf.org/html/rfc7231#section-6.5.9
4828+
phrase = "Gone";
4829+
break;
4830+
case 411: // 411 Length Required - https://tools.ietf.org/html/rfc7231#section-6.5.10
4831+
phrase = "Length Required";
4832+
break;
4833+
case 412: // 412 Precondition Failed - https://tools.ietf.org/html/rfc7232#section-4.2
4834+
phrase = "Precondition Failed";
4835+
break;
4836+
case 413: // 413 Payload Too Large - https://tools.ietf.org/html/rfc7231#section-6.5.11
4837+
phrase = "Payload Too Large";
4838+
break;
4839+
case 414: // 414 URI Too Long - https://tools.ietf.org/html/rfc7231#section-6.5.12
4840+
phrase = "URI Too Long";
4841+
break;
4842+
case 415: // 415 Unsupported Media Type - https://tools.ietf.org/html/rfc7231#section-6.5.13
4843+
phrase = "Unsupported Media Type";
4844+
break;
4845+
case 416: // 416 Range Not Satisfiable - https://tools.ietf.org/html/rfc7233#section-4.4
4846+
phrase = "Range Not Satisfiable";
4847+
break;
4848+
case 417: // 417 Expectation Failed - https://tools.ietf.org/html/rfc7231#section-6.5.14
4849+
phrase = "Expectation Failed";
4850+
break;
4851+
case 418: // 418 I'm a teapot - https://tools.ietf.org/html/rfc2324
4852+
phrase = "I'm a teapot";
4853+
break;
4854+
case 421: // 421 Misdirected Request - http://tools.ietf.org/html/rfc7540#section-9.1.2
4855+
phrase = "Misdirected Request";
4856+
break;
4857+
case 422: // 422 Unprocessable Entity - https://tools.ietf.org/html/rfc4918
4858+
phrase = "Unprocessable Entity";
4859+
break;
4860+
case 423: // 423 Locked - https://tools.ietf.org/html/rfc4918
4861+
phrase = "Locked";
4862+
break;
4863+
case 424: // 424 Failed Dependency - https://tools.ietf.org/html/rfc4918
4864+
phrase = "Failed Dependency";
4865+
break;
4866+
case 426: // 426 Upgrade Required - https://tools.ietf.org/html/rfc7231#section-6.5.15
4867+
phrase = "Upgrade Required";
4868+
break;
4869+
case 428: // 428 Precondition Required - https://tools.ietf.org/html/rfc6585
4870+
phrase = "Precondition Required";
4871+
break;
4872+
case 429: // 429 Too Many Requests - https://tools.ietf.org/html/rfc6585
4873+
phrase = "Too Many Requests";
4874+
break;
4875+
case 431: // 431 Request Header Fields Too Large - https://tools.ietf.org/html/rfc6585
4876+
phrase = "Request Header Fields Too Large";
4877+
break;
4878+
case 451: // 451 Unavailable For Legal Reasons - http://tools.ietf.org/html/rfc7725
4879+
phrase = "Unavailable For Legal Reasons";
4880+
break;
4881+
case 500: // 500 Internal Server Error - https://tools.ietf.org/html/rfc7231#section-6.6.1
4882+
phrase = "Internal Server Error";
4883+
break;
4884+
case 501: // 501 Not Implemented - https://tools.ietf.org/html/rfc7231#section-6.6.2
4885+
phrase = "Not Implemented";
4886+
break;
4887+
case 502: // 502 Bad Gateway - https://tools.ietf.org/html/rfc7231#section-6.6.3
4888+
phrase = "Bad Gateway";
4889+
break;
4890+
case 503: // 503 Service Unavailable - https://tools.ietf.org/html/rfc7231#section-6.6.4
4891+
phrase = "Service Unavailable";
4892+
break;
4893+
case 504: // 504 Gateway Timeout - https://tools.ietf.org/html/rfc7231#section-6.6.5
4894+
phrase = "Gateway Timeout";
4895+
break;
4896+
case 505: // 505 HTTP Version Not Supported - https://tools.ietf.org/html/rfc7231#section-6.6.6
4897+
phrase = "HTTP Version Not Supported";
4898+
break;
4899+
case 506: // 506 Variant Also Negotiates - https://tools.ietf.org/html/rfc2295
4900+
phrase = "Variant Also Negotiates";
4901+
break;
4902+
case 507: // 507 Insufficient Storage - https://tools.ietf.org/html/rfc4918
4903+
phrase = "Insufficient Storage";
4904+
break;
4905+
case 508: // 508 Loop Detected - https://tools.ietf.org/html/rfc5842
4906+
phrase = "Loop Detected";
4907+
break;
4908+
case 510: // 510 Not Extended - https://tools.ietf.org/html/rfc2774
4909+
phrase = "Not Extended";
4910+
break;
4911+
case 511: // 511 Network Authentication Required - https://tools.ietf.org/html/rfc6585
4912+
phrase = "Network Authentication Required";
4913+
break;
4914+
default:
4915+
phrase = "";
4916+
break;
4917+
}
4918+
JS::SetReservedSlot(obj, Slots::StatusMessage,
4919+
JS::StringValue(JS_NewStringCopyN(cx, phrase, strlen(phrase))));
4920+
}
4921+
47294922
const unsigned ctor_length = 1;
47304923

47314924
bool check_receiver(JSContext *cx, HandleValue receiver, const char *method_name);
@@ -4817,7 +5010,7 @@ const JSPropertySpec properties[] = {JS_PSG("type", type_get, JSPROP_ENUMERATE),
48175010
JS_PSG("url", url_get, JSPROP_ENUMERATE),
48185011
JS_PSG("status", status_get, JSPROP_ENUMERATE),
48195012
JS_PSG("ok", ok_get, JSPROP_ENUMERATE),
4820-
JS_PSG("statusText", statusText_get, 0),
5013+
JS_PSG("statusText", statusText_get, JSPROP_ENUMERATE),
48215014
JS_PSG("version", version_get, JSPROP_ENUMERATE),
48225015
JS_PSG("headers", headers_get, JSPROP_ENUMERATE),
48235016
JS_PSG("body", body_get, JSPROP_ENUMERATE),
@@ -4998,7 +5191,8 @@ JSObject *create(JSContext *cx, HandleObject response, ResponseHandle response_h
49985191
return nullptr;
49995192

50005193
JS::SetReservedSlot(response, Slots::Status, JS::Int32Value(status));
5001-
JS::SetReservedSlot(response, Slots::StatusMessage, JS_GetEmptyStringValue(cx));
5194+
set_status_message_from_code(cx, response, status);
5195+
50025196
if (!(status == 204 || status == 205 || status == 304)) {
50035197
JS::SetReservedSlot(response, Slots::HasBody, JS::TrueValue());
50045198
}
Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,122 @@
11
{
22
"RequestCache \"default\" mode with an If-Modified-Since header (following a request without additional headers) is treated similarly to \"no-store\" with Etag and stale response": {
3-
"status": 1
3+
"status": 0
44
},
55
"RequestCache \"default\" mode with an If-Modified-Since header (following a request without additional headers) is treated similarly to \"no-store\" with Last-Modified and stale response": {
6-
"status": 1
6+
"status": 0
77
},
88
"RequestCache \"default\" mode with an If-Modified-Since header (following a request without additional headers) is treated similarly to \"no-store\" with Etag and fresh response": {
9-
"status": 1
9+
"status": 0
1010
},
1111
"RequestCache \"default\" mode with an If-Modified-Since header (following a request without additional headers) is treated similarly to \"no-store\" with Last-Modified and fresh response": {
12-
"status": 1
12+
"status": 0
1313
},
1414
"RequestCache \"default\" mode with an If-Modified-Since header is treated similarly to \"no-store\" with Etag and stale response": {
15-
"status": 1
15+
"status": 0
1616
},
1717
"RequestCache \"default\" mode with an If-Modified-Since header is treated similarly to \"no-store\" with Last-Modified and stale response": {
18-
"status": 1
18+
"status": 0
1919
},
2020
"RequestCache \"default\" mode with an If-Modified-Since header is treated similarly to \"no-store\" with Etag and fresh response": {
21-
"status": 1
21+
"status": 0
2222
},
2323
"RequestCache \"default\" mode with an If-Modified-Since header is treated similarly to \"no-store\" with Last-Modified and fresh response": {
24-
"status": 1
24+
"status": 0
2525
},
2626
"RequestCache \"default\" mode with an If-None-Match header (following a request without additional headers) is treated similarly to \"no-store\" with Etag and stale response": {
27-
"status": 1
27+
"status": 0
2828
},
2929
"RequestCache \"default\" mode with an If-None-Match header (following a request without additional headers) is treated similarly to \"no-store\" with Last-Modified and stale response": {
30-
"status": 1
30+
"status": 0
3131
},
3232
"RequestCache \"default\" mode with an If-None-Match header (following a request without additional headers) is treated similarly to \"no-store\" with Etag and fresh response": {
33-
"status": 1
33+
"status": 0
3434
},
3535
"RequestCache \"default\" mode with an If-None-Match header (following a request without additional headers) is treated similarly to \"no-store\" with Last-Modified and fresh response": {
36-
"status": 1
36+
"status": 0
3737
},
3838
"RequestCache \"default\" mode with an If-None-Match header is treated similarly to \"no-store\" with Etag and stale response": {
39-
"status": 1
39+
"status": 0
4040
},
4141
"RequestCache \"default\" mode with an If-None-Match header is treated similarly to \"no-store\" with Last-Modified and stale response": {
42-
"status": 1
42+
"status": 0
4343
},
4444
"RequestCache \"default\" mode with an If-None-Match header is treated similarly to \"no-store\" with Etag and fresh response": {
45-
"status": 1
45+
"status": 0
4646
},
4747
"RequestCache \"default\" mode with an If-None-Match header is treated similarly to \"no-store\" with Last-Modified and fresh response": {
48-
"status": 1
48+
"status": 0
4949
},
5050
"RequestCache \"default\" mode with an If-Unmodified-Since header (following a request without additional headers) is treated similarly to \"no-store\" with Etag and stale response": {
51-
"status": 1
51+
"status": 0
5252
},
5353
"RequestCache \"default\" mode with an If-Unmodified-Since header (following a request without additional headers) is treated similarly to \"no-store\" with Last-Modified and stale response": {
54-
"status": 1
54+
"status": 0
5555
},
5656
"RequestCache \"default\" mode with an If-Unmodified-Since header (following a request without additional headers) is treated similarly to \"no-store\" with Etag and fresh response": {
57-
"status": 1
57+
"status": 0
5858
},
5959
"RequestCache \"default\" mode with an If-Unmodified-Since header (following a request without additional headers) is treated similarly to \"no-store\" with Last-Modified and fresh response": {
60-
"status": 1
60+
"status": 0
6161
},
6262
"RequestCache \"default\" mode with an If-Unmodified-Since header is treated similarly to \"no-store\" with Etag and stale response": {
63-
"status": 1
63+
"status": 0
6464
},
6565
"RequestCache \"default\" mode with an If-Unmodified-Since header is treated similarly to \"no-store\" with Last-Modified and stale response": {
66-
"status": 1
66+
"status": 0
6767
},
6868
"RequestCache \"default\" mode with an If-Unmodified-Since header is treated similarly to \"no-store\" with Etag and fresh response": {
69-
"status": 1
69+
"status": 0
7070
},
7171
"RequestCache \"default\" mode with an If-Unmodified-Since header is treated similarly to \"no-store\" with Last-Modified and fresh response": {
72-
"status": 1
72+
"status": 0
7373
},
7474
"RequestCache \"default\" mode with an If-Match header (following a request without additional headers) is treated similarly to \"no-store\" with Etag and stale response": {
75-
"status": 1
75+
"status": 0
7676
},
7777
"RequestCache \"default\" mode with an If-Match header (following a request without additional headers) is treated similarly to \"no-store\" with Last-Modified and stale response": {
78-
"status": 1
78+
"status": 0
7979
},
8080
"RequestCache \"default\" mode with an If-Match header (following a request without additional headers) is treated similarly to \"no-store\" with Etag and fresh response": {
81-
"status": 1
81+
"status": 0
8282
},
8383
"RequestCache \"default\" mode with an If-Match header (following a request without additional headers) is treated similarly to \"no-store\" with Last-Modified and fresh response": {
84-
"status": 1
84+
"status": 0
8585
},
8686
"RequestCache \"default\" mode with an If-Match header is treated similarly to \"no-store\" with Etag and stale response": {
87-
"status": 1
87+
"status": 0
8888
},
8989
"RequestCache \"default\" mode with an If-Match header is treated similarly to \"no-store\" with Last-Modified and stale response": {
90-
"status": 1
90+
"status": 0
9191
},
9292
"RequestCache \"default\" mode with an If-Match header is treated similarly to \"no-store\" with Etag and fresh response": {
93-
"status": 1
93+
"status": 0
9494
},
9595
"RequestCache \"default\" mode with an If-Match header is treated similarly to \"no-store\" with Last-Modified and fresh response": {
96-
"status": 1
96+
"status": 0
9797
},
9898
"RequestCache \"default\" mode with an If-Range header (following a request without additional headers) is treated similarly to \"no-store\" with Etag and stale response": {
99-
"status": 1
99+
"status": 0
100100
},
101101
"RequestCache \"default\" mode with an If-Range header (following a request without additional headers) is treated similarly to \"no-store\" with Last-Modified and stale response": {
102-
"status": 1
102+
"status": 0
103103
},
104104
"RequestCache \"default\" mode with an If-Range header (following a request without additional headers) is treated similarly to \"no-store\" with Etag and fresh response": {
105-
"status": 1
105+
"status": 0
106106
},
107107
"RequestCache \"default\" mode with an If-Range header (following a request without additional headers) is treated similarly to \"no-store\" with Last-Modified and fresh response": {
108-
"status": 1
108+
"status": 0
109109
},
110110
"RequestCache \"default\" mode with an If-Range header is treated similarly to \"no-store\" with Etag and stale response": {
111-
"status": 1
111+
"status": 0
112112
},
113113
"RequestCache \"default\" mode with an If-Range header is treated similarly to \"no-store\" with Last-Modified and stale response": {
114-
"status": 1
114+
"status": 0
115115
},
116116
"RequestCache \"default\" mode with an If-Range header is treated similarly to \"no-store\" with Etag and fresh response": {
117-
"status": 1
117+
"status": 0
118118
},
119119
"RequestCache \"default\" mode with an If-Range header is treated similarly to \"no-store\" with Last-Modified and fresh response": {
120-
"status": 1
120+
"status": 0
121121
}
122122
}

0 commit comments

Comments
 (0)