@@ -1623,13 +1623,20 @@ private HTTPServerRequestDelegate jsonMethodHandler(alias Func, size_t ridx, T)(
1623
1623
handleCors();
1624
1624
foreach (i, P; PTypes) {
1625
1625
static if (sroute.parameters[i].isOut) {
1626
- static assert (sroute.parameters[i].kind == ParameterKind.header);
1627
- static if (isInstanceOf! (Nullable, typeof (params[i]))) {
1628
- if (! params[i].isNull)
1626
+ static if (sroute.parameters[i].kind == ParameterKind.header) {
1627
+ static if (isInstanceOf! (Nullable, typeof (params[i]))) {
1628
+ if (! params[i].isNull)
1629
+ res.headers[route.parameters[i].fieldName] = to! string (params[i]);
1630
+ } else {
1629
1631
res.headers[route.parameters[i].fieldName] = to! string (params[i]);
1630
- } else {
1631
- res.headers[route.parameters[i].fieldName] = to! string (params[i]);
1632
- }
1632
+ }
1633
+ } else static if (sroute.parameters[i].kind == ParameterKind.status) {
1634
+ static if (is (typeof (params[i]) == HTTPStatus) || is (typeof (params[i]) == int ))
1635
+ res.statusCode = params[i];
1636
+ else static if (is (typeof (params[i]) == string ))
1637
+ res.statusPhrase = params[i];
1638
+ else static assert (false , " `@viaStatus` parameters must be of type `HTTPStats`/`int` or `string`" );
1639
+ } else static assert (false , " `out` parameters must be annotated with either `@viaHeader` or `@viaStatus`" );
1633
1640
}
1634
1641
}
1635
1642
}
@@ -1855,6 +1862,8 @@ private auto executeClientMethod(I, size_t ridx, ARGS...)
1855
1862
InetHeaderMap headers;
1856
1863
InetHeaderMap reqhdrs;
1857
1864
InetHeaderMap opthdrs;
1865
+ HTTPStatus status_code;
1866
+ string status_phrase;
1858
1867
1859
1868
string url_prefix;
1860
1869
@@ -1930,15 +1939,21 @@ private auto executeClientMethod(I, size_t ridx, ARGS...)
1930
1939
foreach (i, PT ; PTT ) {
1931
1940
enum sparam = sroute.parameters[i];
1932
1941
auto fieldname = route.parameters[i].fieldName;
1933
- static if (sparam.kind == ParameterKind.header ) {
1934
- static if (sparam.isOut ) {
1942
+ static if (sparam.isOut ) {
1943
+ static if (sparam.kind == ParameterKind.header ) {
1935
1944
static if (isInstanceOf! (Nullable, PT )) {
1936
1945
ARGS [i] = to! (TemplateArgsOf! PT )(
1937
1946
opthdrs.get (fieldname, null ));
1938
1947
} else {
1939
1948
if (auto ptr = fieldname in reqhdrs)
1940
1949
ARGS [i] = to! PT (* ptr);
1941
1950
}
1951
+ } else static if (sparam.kind == ParameterKind.status) {
1952
+ static if (is (PT == HTTPStatus) || is (PT == int )) {
1953
+ ARGS [i] = status_code;
1954
+ } else static if (is (PT == string )) {
1955
+ ARGS [i] = status_phrase;
1956
+ }
1942
1957
}
1943
1958
}
1944
1959
}
@@ -1964,6 +1979,8 @@ private auto executeClientMethod(I, size_t ridx, ARGS...)
1964
1979
auto ret = request(URL (intf.baseURL), request_filter, request_body_filter,
1965
1980
sroute.method, url, headers, query.data, body_, reqhdrs, opthdrs,
1966
1981
intf.settings.httpClientSettings);
1982
+ status_code = cast (HTTPStatus)ret.statusCode;
1983
+ status_phrase = ret.statusPhrase;
1967
1984
1968
1985
static if (is (RT == InputStream )) {
1969
1986
return ret.bodyReader.asInterface! InputStream ;
@@ -2438,7 +2455,7 @@ do {
2438
2455
static if (Attr.length != 1 ) {
2439
2456
if (hack) return " %s: Parameter '%s' cannot be %s"
2440
2457
.format(FuncId, PN [i], SC & PSC .out_ ? " out" : " ref" );
2441
- } else static if (Attr[0 ].origin != ParameterKind.header) {
2458
+ } else static if (Attr[0 ].origin != ParameterKind.header && Attr[ 0 ].origin != ParameterKind.status ) {
2442
2459
if (hack) return " %s: %s parameter '%s' cannot be %s"
2443
2460
.format(FuncId, Attr[0 ].origin, PN [i],
2444
2461
SC & PSC .out_ ? " out" : " ref" );
0 commit comments