Skip to content

Commit ef194c4

Browse files
committed
Don't double-apply CORS header in POST /control-vectors
1 parent 0944805 commit ef194c4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

examples/server/server.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3201,8 +3201,6 @@ int main(int argc, char ** argv) {
32013201
};
32023202

32033203
const auto handle_set_control_vectors = [&ctx_server, &res_error, &handle_get_control_vectors](const httplib::Request & req, httplib::Response & res) {
3204-
res.set_header("Access-Control-Allow-Origin", req.get_header_value("Origin"));
3205-
32063204
json data = json::parse(req.body);
32073205
std::vector<llama_control_vector_load_info> vec_params;
32083206

@@ -3214,12 +3212,14 @@ int main(int argc, char ** argv) {
32143212
}
32153213
} else {
32163214
std::cerr << "No vectors passed\n";
3215+
res.set_header("Access-Control-Allow-Origin", req.get_header_value("Origin"));
32173216
res_error(res, format_error_response("No vectors passed", ERROR_TYPE_SERVER));
32183217
return;
32193218
}
32203219
const auto cvec = llama_control_vector_load(vec_params);
32213220
if (cvec.n_embd == -1) {
32223221
std::cerr << "Could not load control vector\n";
3222+
res.set_header("Access-Control-Allow-Origin", req.get_header_value("Origin"));
32233223
res_error(res, format_error_response("Could not load control vector", ERROR_TYPE_SERVER));
32243224
return;
32253225
}
@@ -3238,6 +3238,7 @@ int main(int argc, char ** argv) {
32383238
ctx_server.params.control_vector_layer_end);
32393239
if (err) {
32403240
std::cerr << "Could not apply control vector\n";
3241+
res.set_header("Access-Control-Allow-Origin", req.get_header_value("Origin"));
32413242
res_error(res, format_error_response("Could not apply control vector", ERROR_TYPE_SERVER));
32423243
return;
32433244
}

0 commit comments

Comments
 (0)