Skip to content

Commit

Permalink
Fix Content-Type header in request builder
Browse files Browse the repository at this point in the history
  • Loading branch information
royshil committed Mar 26, 2024
1 parent 2f0806d commit 237903f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/request-data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,10 @@ struct request_data_handler_response request_data_handler(url_source_request_dat
textStr.c_str());

// if one of the headers is Content-Type application/json, make sure the text is JSONified
std::regex header_regex("content-type",
std::regex_constants::icase);
for (auto header : request_data->headers) {
// check if the header is Content-Type case insensitive using regex
std::regex header_regex(
"content-type",
std::regex_constants::icase);
if (std::regex_search(header.first, header_regex) &&
header.second == "application/json") {
nlohmann::json tmp = text;
Expand Down
6 changes: 3 additions & 3 deletions src/ui/RequestBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ RequestBuilder::RequestBuilder(url_source_request_data *request_data,
if (index == 1 || index == 2 || index == 3) {
//OpenAI
ui->methodComboBox->setCurrentIndex(1);
addHeaders({{"Content-Type", "application/json "},
addHeaders({{"Content-Type", "application/json"},
{"Authorization", "Bearer $OPENAI_API_KEY"}},
ui->tableView_headers);
}
Expand Down Expand Up @@ -223,7 +223,7 @@ RequestBuilder::RequestBuilder(url_source_request_data *request_data,
/* --------------- 11Labs TTS --------------- */
/* ------------------------------------------- */
ui->methodComboBox->setCurrentIndex(1);
addHeaders({{"Content-Type", "application/json "},
addHeaders({{"Content-Type", "application/json"},
{"Accept", "application/json"},
{"xi-api-key", "$XI_API_KEY"}},
ui->tableView_headers);
Expand Down Expand Up @@ -254,7 +254,7 @@ RequestBuilder::RequestBuilder(url_source_request_data *request_data,
ui->urlLineEdit->setText("https://api-free.deepl.com/v2/translate");
addHeaders(
{
{"Content-Type", "application/json "},
{"Content-Type", "application/json"},
{"Authorization", "DeepL-Auth-Key $yourAuthKey"},
},
ui->tableView_headers);
Expand Down

0 comments on commit 237903f

Please sign in to comment.