Skip to content

Commit 2506fed

Browse files
committed
Don't double-apply CORS header in POST /control-vectors
1 parent 80508e1 commit 2506fed

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
@@ -3202,8 +3202,6 @@ int main(int argc, char ** argv) {
32023202
};
32033203

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

@@ -3215,12 +3213,14 @@ int main(int argc, char ** argv) {
32153213
}
32163214
} else {
32173215
std::cerr << "No vectors passed\n";
3216+
res.set_header("Access-Control-Allow-Origin", req.get_header_value("Origin"));
32183217
res_error(res, format_error_response("No vectors passed", ERROR_TYPE_SERVER));
32193218
return;
32203219
}
32213220
const auto cvec = llama_control_vector_load(vec_params);
32223221
if (cvec.n_embd == -1) {
32233222
std::cerr << "Could not load control vector\n";
3223+
res.set_header("Access-Control-Allow-Origin", req.get_header_value("Origin"));
32243224
res_error(res, format_error_response("Could not load control vector", ERROR_TYPE_SERVER));
32253225
return;
32263226
}
@@ -3239,6 +3239,7 @@ int main(int argc, char ** argv) {
32393239
ctx_server.params.control_vector_layer_end);
32403240
if (err) {
32413241
std::cerr << "Could not apply control vector\n";
3242+
res.set_header("Access-Control-Allow-Origin", req.get_header_value("Origin"));
32423243
res_error(res, format_error_response("Could not apply control vector", ERROR_TYPE_SERVER));
32433244
return;
32443245
}

0 commit comments

Comments
 (0)