nrf-http2-server.cpp 21.5 KB
Newer Older
Rohan's avatar
Rohan committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this
 * file except in compliance with the License. You may obtain a copy of the
 * License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

/*! \file nrf_http2-server.cpp
 \brief
 \author  Tien-Thinh NGUYEN
 \company Eurecom
 \date 2020
 \email: tien-thinh.nguyen@eurecom.fr
 */

#include "nrf-http2-server.h"
#include <boost/algorithm/string.hpp>
#include <boost/thread.hpp>
#include <boost/thread/future.hpp>
Rohan's avatar
Rohan committed
34
#include <regex>
Rohan's avatar
Rohan committed
35
36
#include <nlohmann/json.hpp>
#include <string>
Rohan's avatar
Rohan committed
37
#include "string.hpp"
Rohan's avatar
Rohan committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

#include "logger.hpp"
#include "nrf_config.hpp"
#include "3gpp_29.500.h"
#include "mime_parser.hpp"

using namespace nghttp2::asio_http2;
using namespace nghttp2::asio_http2::server;
using namespace oai::nrf::model;

extern nrf_config nrf_cfg;

//------------------------------------------------------------------------------
void nrf_http2_server::start() {
  boost::system::error_code ec;

  Logger::nrf_app().info("HTTP2 server started");
  std::string nfInstanceID          = {};
  std::string subscriptionID        = {};
  SubscriptionData subscriptionData = {};

Rohan's avatar
Rohan committed
59
  // NF Instances (Store)
Rohan's avatar
Rohan committed
60
  server.handle(
Rohan's avatar
Rohan committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
      NNRF_NFM_BASE + nrf_cfg.sbi_api_version + "/nf-instances",
      [&](const request& request, const response& response) {
        request.on_data([&](const uint8_t* data, std::size_t len) {
          std::string msg((char*) data, len);
          try {
            // Retrieves a collection of NF Instances
            if (request.method().compare("GET") == 0) {
              std::string split_query = request.uri().raw_query;

              // Parse query paramaters
              std::string nfType =
                  util::get_query_param(split_query, "nf-type");
              std::string limit_nfs =
                  util::get_query_param(split_query.c_str(), "limit");

              Logger::nrf_sbi().debug(
                  "/nnrf-nfm/ query params - nfType: %s, limit_nfs: %s, ",
                  nfType.c_str(), limit_nfs.c_str());

              this->get_nf_instances_handler(nfType, limit_nfs, response);
            }
          } catch (nlohmann::detail::exception& e) {
            Logger::nrf_sbi().warn(
                "Can not parse the json data (error: %s)!", e.what());
            response.write_head(
                http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST);
            response.end();
            return;
          }
        });
      });

  // NF Instances ID (Document)
  server.handle(
      NNRF_NFM_BASE + nrf_cfg.sbi_api_version + NNRF_NFM_NF_INSTANCES,
Rohan's avatar
Rohan committed
96
97
98
99
100
      [&](const request& request, const response& response) {
        request.on_data([&](const uint8_t* data, std::size_t len) {
          std::string msg((char*) data, len);
          NFProfile nFProfile;
          try {
Rohan's avatar
Rohan committed
101
            // Register a new NF Instance
Rohan's avatar
Rohan committed
102
103
104
105
            if (request.method().compare("PUT") == 0 && len > 0) {
              nlohmann::json::parse(msg.c_str()).get_to(nFProfile);
              this->register_nf_instance_handler(nFProfile, response);
            }
Rohan's avatar
Rohan committed
106
            // Read the profile of a given NF Instance
Rohan's avatar
Rohan committed
107
108
109
110
            if (request.method().compare("GET") == 0) {
              std::vector<std::string> split_result;
              boost::split(
                  split_result, request.uri().path, boost::is_any_of("/"));
Rohan's avatar
Rohan committed
111
112
113
114
              if (split_result.size() == 5) {
                nfInstanceID = split_result[split_result.size() - 1].c_str();
                this->get_nf_instance_handler(nfInstanceID, response);
              }
Rohan's avatar
Rohan committed
115
            }
Rohan's avatar
Rohan committed
116
            // Update NF Instance profile
Rohan's avatar
Rohan committed
117
118
119
120
121
122
123
124
125
            if (request.method().compare("PATCH") == 0 && len > 0) {
              std::vector<PatchItem> patchItem;
              nlohmann::json::parse(msg.c_str()).get_to(patchItem);
              std::vector<std::string> split_result;
              boost::split(
                  split_result, request.uri().path, boost::is_any_of("/"));
              nfInstanceID = split_result[split_result.size() - 1].c_str();
              this->update_instance_handler(nfInstanceID, patchItem, response);
            }
Rohan's avatar
Rohan committed
126
            // Deregisters a given NF Instance
Rohan's avatar
Rohan committed
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
            if (request.method().compare("DELETE") == 0) {
              std::vector<std::string> split_result;
              boost::split(
                  split_result, request.uri().path, boost::is_any_of("/"));
              nfInstanceID = split_result[split_result.size() - 1].c_str();
              this->deregister_nf_instance_handler(nfInstanceID, response);
            }
          } catch (nlohmann::detail::exception& e) {
            Logger::nrf_sbi().warn(
                "Can not parse the json data (error: %s)!", e.what());
            response.write_head(
                http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST);
            response.end();
            return;
          }
        });
      });

Rohan's avatar
Rohan committed
145
  // Subscriptions  (Collection & ID Document)
Rohan's avatar
Rohan committed
146
147
148
149
150
151
  server.handle(
      NNRF_NFM_BASE + nrf_cfg.sbi_api_version + NNRF_NFM_STATUS_SUBSCRIBE_URL,
      [&](const request& request, const response& response) {
        request.on_data([&](const uint8_t* data, std::size_t len) {
          std::string msg((char*) data, len);
          try {
Rohan's avatar
Rohan committed
152
            // Create a new subscription
Rohan's avatar
Rohan committed
153
154
155
156
            if (request.method().compare("POST") == 0 && len > 0) {
              nlohmann::json::parse(msg.c_str()).get_to(subscriptionData);
              this->create_subscription_handler(subscriptionData, response);
            }
Rohan's avatar
Rohan committed
157
            // Updates a subscription
Rohan's avatar
Rohan committed
158
159
160
161
162
163
164
165
166
167
            if (request.method().compare("PATCH") == 0 && len > 0) {
              std::vector<PatchItem> patchItem;
              nlohmann::json::parse(msg.c_str()).get_to(patchItem);
              std::vector<std::string> split_result;
              boost::split(
                  split_result, request.uri().path, boost::is_any_of("/"));
              subscriptionID = split_result[split_result.size() - 1].c_str();
              this->update_subscription_handler(
                  subscriptionID, patchItem, response);
            }
Rohan's avatar
Rohan committed
168
            // Delete a subscription
Rohan's avatar
Rohan committed
169
170
171
172
173
174
175
            if (request.method().compare("DELETE") == 0) {
              std::vector<std::string> split_result;
              boost::split(
                  split_result, request.uri().path, boost::is_any_of("/"));
              subscriptionID = split_result[split_result.size() - 1].c_str();
              this->remove_subscription_handler(subscriptionID, response);
            }
Rohan's avatar
Rohan committed
176
177
178
179
180
181
182
183
184
185
          } catch (nlohmann::detail::exception& e) {
            Logger::nrf_sbi().warn(
                "Can not parse the json data (error: %s)!", e.what());
            response.write_head(
                http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST);
            response.end();
            return;
          }
        });
      });
Rohan's avatar
Rohan committed
186

Rohan's avatar
Rohan committed
187
  // NF Discovery (Store)
Rohan's avatar
Rohan committed
188
189
190
191
192
193
  server.handle(
      NNRF_DISC_BASE + nrf_cfg.sbi_api_version + "/nf-instances",
      [&](const request& request, const response& response) {
        request.on_data([&](const uint8_t* data, std::size_t len) {
          std::string msg((char*) data, len);
          try {
Rohan's avatar
Rohan committed
194
            // Search a collection of NF Instances
Rohan's avatar
Rohan committed
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
            if (request.method().compare("GET") == 0) {
              std::string split_query = request.uri().raw_query;

              // Parse query paramaters
              std::string nfTypeTarget =
                  util::get_query_param(split_query, "target-nf-type");
              std::string nfTypeReq = util::get_query_param(
                  split_query.c_str(), "requester-nf-type");
              std::string requester_nf_instance_id = util::get_query_param(
                  split_query.c_str(), "requester-nf-instance-id");
              std::string limit_nfs =
                  util::get_query_param(split_query.c_str(), "limit");
              // TODO: other query parameters

              Logger::nrf_sbi().debug(
                  "/nnrf-disc/ query params - nfTypeTarget: %s, nfTypeReq: %s, "
                  "requester-nf-instance-id: %s, limit_nfs %s",
                  nfTypeTarget.c_str(), nfTypeReq.c_str(),
                  requester_nf_instance_id.c_str(), limit_nfs.c_str());

              this->search_nf_instances_handler(
                  nfTypeTarget, nfTypeReq, requester_nf_instance_id, limit_nfs,
                  response);
            }
Rohan's avatar
Rohan committed
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
          } catch (nlohmann::detail::exception& e) {
            Logger::nrf_sbi().warn(
                "Can not parse the json data (error: %s)!", e.what());
            response.write_head(
                http_status_code_e::HTTP_STATUS_CODE_400_BAD_REQUEST);
            response.end();
            return;
          }
        });
      });

  if (server.listen_and_serve(ec, m_address, std::to_string(m_port))) {
    std::cerr << "HTTP Server error: " << ec.message() << std::endl;
  }
}

void nrf_http2_server::register_nf_instance_handler(
    const NFProfile& NFProfiledata, const response& response) {
  std::string nfInstanceID = {};
  nfInstanceID             = NFProfiledata.getNfInstanceId();
  Logger::nrf_sbi().info(
      "Got a request to register an NF instance/Update an NF instance, "
      "Instance ID: %s",
      nfInstanceID.c_str());
  int http_code                  = 0;
  ProblemDetails problem_details = {};
  nlohmann::json json_data       = {};
  std::string content_type       = "application/json";
  std::string json_format;

  m_nrf_app->handle_register_nf_instance(
      nfInstanceID, NFProfiledata, http_code, 2, problem_details);

  if ((http_code != HTTP_STATUS_CODE_200_OK) and
      (http_code != HTTP_STATUS_CODE_201_CREATED) and
      (http_code != HTTP_STATUS_CODE_202_ACCEPTED)) {
    to_json(json_data, problem_details);
    content_type = "application/problem+json";
  } else {
    std::shared_ptr<nrf_profile> profile =
        m_nrf_app->find_nf_profile(nfInstanceID);
    if (profile.get() != nullptr) {
      profile.get()->to_json(json_data);
    }
  }
  header_map h;
  h.emplace(
      "location", header_value{
                      m_address + NNRF_NFM_BASE + nrf_cfg.sbi_api_version +
                      "/nf-instances/" + nfInstanceID});
  h.emplace("content-type", header_value{content_type});
  response.write_head(http_code, h);
  response.end(json_data.dump().c_str());
};

void nrf_http2_server::get_nf_instance_handler(
    const std::string& nfInstanceID, const response& response) {
  Logger::nrf_sbi().info(
      "Got a request to retrieve the profile of a given NF Instance, Instance "
      "ID: %s",
      nfInstanceID.c_str());
  int http_code                        = 0;
  ProblemDetails problem_details       = {};
  nlohmann::json json_data             = {};
  std::string content_type             = "application/json";
  std::shared_ptr<nrf_profile> profile = {};

  m_nrf_app->handle_get_nf_instance(
      nfInstanceID, profile, http_code, 2, problem_details);

  if (http_code != HTTP_STATUS_CODE_200_OK) {
    to_json(json_data, problem_details);
    content_type = "application/problem+json";
  } else {
    profile.get()->to_json(json_data);
  }

  header_map h;
  h.emplace(
      "location", header_value{
                      m_address + NNRF_NFM_BASE + nrf_cfg.sbi_api_version +
                      "/nf-instances/" + nfInstanceID});
  h.emplace("content-type", header_value{content_type});
  response.write_head(http_code, h);
  response.end(json_data.dump().c_str());
}

void nrf_http2_server::get_nf_instances_handler(
Rohan's avatar
Rohan committed
307
    const std::string& nf_type, const std::string& limit_nfs,
Rohan's avatar
Rohan committed
308
    const response& response) {
Rohan's avatar
Rohan committed
309
310
311
  Logger::nrf_sbi().info(
      "Got a request to retrieve  a collection of NF Instances");

Rohan's avatar
Rohan committed
312
313
314
  std::string nfType = {};
  if (!nf_type.empty()) {
    nfType = nf_type;
Rohan's avatar
Rohan committed
315
    Logger::nrf_sbi().debug("\tNF type:  %s", nfType.c_str());
Rohan's avatar
Rohan committed
316
  }
Rohan's avatar
Rohan committed
317

Rohan's avatar
Rohan committed
318
319
320
321
322
323
324
  uint32_t limit_Nfs = 0;
  if (!limit_nfs.empty()) {
    limit_Nfs = stoi(limit_nfs);
    Logger::nrf_sbi().debug(
        "\tMaximum number of NFProfiles to be returned in the response: %d",
        limit_Nfs);
  }
Rohan's avatar
Rohan committed
325
326
327
328
329
330
331
332
333

  int http_code                        = 0;
  ProblemDetails problem_details       = {};
  nlohmann::json json_data             = {};
  std::string content_type             = "application/json";
  std::shared_ptr<nrf_profile> profile = {};
  std::vector<std::string> uris        = {};

  m_nrf_app->handle_get_nf_instances(
Rohan's avatar
Rohan committed
334
      nfType, uris, limit_Nfs, http_code, 2, problem_details);
Rohan's avatar
Rohan committed
335
336
337
338
339
340
341
342
343
344
345
346

  if (http_code != HTTP_STATUS_CODE_200_OK) {
    to_json(json_data, problem_details);
    content_type = "application/problem+json";
  } else {
    profile.get()->to_json(json_data);
  }

  header_map h;
  h.emplace(
      "location", header_value{
                      m_address + NNRF_NFM_BASE + nrf_cfg.sbi_api_version +
Rohan's avatar
Rohan committed
347
                      "/nf-instances/"});
Rohan's avatar
Rohan committed
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
  h.emplace("content-type", header_value{content_type});
  response.write_head(http_code, h);
  response.end();
}

void nrf_http2_server::update_instance_handler(
    const std::string& nfInstanceID, const std::vector<PatchItem>& patchItem,
    const response& response) {
  Logger::nrf_sbi().info("");
  Logger::nrf_sbi().info(
      "Got a request to update an NF instance, Instance ID: %s",
      nfInstanceID.c_str());

  int http_code                  = 0;
  ProblemDetails problem_details = {};
  m_nrf_app->handle_update_nf_instance(
      nfInstanceID, patchItem, http_code, 2, problem_details);

  nlohmann::json json_data = {};
  std::string content_type = "application/json";

  std::shared_ptr<nrf_profile> profile =
      m_nrf_app->find_nf_profile(nfInstanceID);

  if ((http_code != HTTP_STATUS_CODE_200_OK) and
      (http_code != HTTP_STATUS_CODE_204_NO_CONTENT)) {
    to_json(json_data, problem_details);
    content_type = "application/problem+json";
  } else if (http_code == HTTP_STATUS_CODE_200_OK) {
    if (profile.get() != nullptr)
      // convert the profile to Json
      profile.get()->to_json(json_data);
  }

  Logger::nrf_sbi().debug("Json data: %s", json_data.dump().c_str());
  header_map h;
  h.emplace(
      "location", header_value{
                      m_address + NNRF_NFM_BASE + nrf_cfg.sbi_api_version +
                      "/nf-instances/" + nfInstanceID});
  h.emplace("content-type", header_value{content_type});
  response.write_head(http_code, h);
  response.end(json_data.dump().c_str());
}

void nrf_http2_server::deregister_nf_instance_handler(
    const std::string& nfInstanceID, const response& response) {
  Logger::nrf_sbi().info(
      "Got a request to de-register a given NF Instance, Instance ID: %s",
      nfInstanceID.c_str());

  int http_code                  = 0;
  ProblemDetails problem_details = {};
  nlohmann::json json_data       = {};
  std::string content_type       = "application/json";

  m_nrf_app->handle_deregister_nf_instance(
      nfInstanceID, http_code, 2, problem_details);

  header_map h;
  h.emplace(
      "location", header_value{
                      m_address + NNRF_NFM_BASE + nrf_cfg.sbi_api_version +
                      "/nf-instances/" + nfInstanceID});
  h.emplace("content-type", header_value{content_type});
  response.write_head(http_code, h);
  response.end();
};

void nrf_http2_server::create_subscription_handler(
    const SubscriptionData& subscriptionData, const response& response) {
  Logger::nrf_sbi().info("Got a request to create a new subscription");
  int http_code                  = 0;
  ProblemDetails problem_details = {};
  std::string sub_id;
  nlohmann::json json_sub  = {};
  nlohmann::json json_data = {};
  std::string content_type = "application/json";

  Logger::nrf_sbi().debug("Subscription data %s", json_sub.dump().c_str());
  m_nrf_app->handle_create_subscription(
      subscriptionData, sub_id, http_code, 2, problem_details);

  if (http_code != HTTP_STATUS_CODE_201_CREATED) {
    to_json(json_data, problem_details);
    content_type = "application/problem+json";
  } else {
    to_json(json_data, subscriptionData);
    json_data["subscriptionId"] = sub_id;
  }

  header_map h;
  h.emplace(
      "location", header_value{
                      m_address + NNRF_NFM_BASE + nrf_cfg.sbi_api_version +
                      NNRF_NFM_STATUS_SUBSCRIBE_URL});
  h.emplace("content-type", header_value{content_type});
  response.write_head(http_code, h);
  response.end(json_data.dump().c_str());
};

void nrf_http2_server::update_subscription_handler(
    const std::string& subscriptionID, const std::vector<PatchItem>& patchItem,
    const response& response) {
  Logger::nrf_sbi().info(
      "Got a request to update of subscription to NF instances, subscription "
      "ID %s",
      subscriptionID.c_str());

  int http_code                  = 0;
  ProblemDetails problem_details = {};
  nlohmann::json json_data       = {};
  std::string content_type       = "application/json";

  m_nrf_app->handle_update_subscription(
      subscriptionID, patchItem, http_code, 1, problem_details);

  // TODO: (section 5.2.2.5.6, Update of Subscription to NF Instances,
  // 3GPP TS 29.510 V16.0.0 (2019-06)) if the NRF accepts the extension
  // of the lifetime of the subscription, but it assigns a validity time
  // different than the value suggested by the NF Service Consumer, a
  // "200 OK" response code shall be returned
  header_map h;
  h.emplace("content-type", header_value{content_type});

  if (http_code != HTTP_STATUS_CODE_204_NO_CONTENT) {
    to_json(json_data, problem_details);
    response.write_head(http_code, h);
    response.end(json_data.dump().c_str());
  } else {
    response.write_head(http_code, h);
    response.end();
  }
}

void nrf_http2_server::remove_subscription_handler(
    const std::string& subscriptionID, const response& response) {
  Logger::nrf_sbi().info(
      "Got a request to remove an existing subscription, subscription ID %s",
      subscriptionID.c_str());
  int http_code                  = 0;
  ProblemDetails problem_details = {};
  nlohmann::json json_data       = {};
  std::string content_type       = "application/json";

  m_nrf_app->handle_remove_subscription(
      subscriptionID, http_code, 2, problem_details);

  header_map h;
  h.emplace("content-type", header_value{content_type});

  if (http_code != HTTP_STATUS_CODE_204_NO_CONTENT) {
    to_json(json_data, problem_details);
    response.write_head(http_code, h);
    response.end(json_data.dump().c_str());
  } else {
    response.write_head(http_code, h);
    response.end();
  }
}

void nrf_http2_server::search_nf_instances_handler(
Rohan's avatar
Rohan committed
510
511
512
    const std::string& target_nf_type, const std::string& requester_nf_type,
    const std::string& requester_nf_instance_id, const std::string& limit_nfs,
    const response& response) {
Rohan's avatar
Rohan committed
513
514
515
  Logger::nrf_sbi().info(
      "Got a request to discover the set of NF instances that satisfies a "
      "number of input query parameters");
Rohan's avatar
Rohan committed
516

Rohan's avatar
Rohan committed
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
  std::string target_nfType = {};
  if (!target_nf_type.empty()) {
    target_nfType = target_nf_type;
    Logger::nrf_sbi().debug("\tTarget NF type:  %s", target_nfType.c_str());
  }

  std::string requester_nfType = {};
  if (!requester_nf_type.empty()) {
    requester_nfType = requester_nf_type;
    Logger::nrf_sbi().debug(
        "\tRequested NF type:  %s", requester_nfType.c_str());
  }

  std::string requester_nfInstance_id = {};
  if (!requester_nf_instance_id.empty()) {
    requester_nfInstance_id = requester_nf_instance_id;
    Logger::nrf_sbi().debug(
        "\tRequested NF instance id:  %s", requester_nf_instance_id.c_str());
  }

  uint32_t limit_Nfs = 0;
  if (!limit_nfs.empty()) {
    limit_Nfs = stoi(limit_nfs);
    Logger::nrf_sbi().debug(
        "\tMaximum number of NFProfiles to be returned in the response: %d",
        limit_Nfs);
  }
Rohan's avatar
Rohan committed
544
545
546
547
548
549
550

  // TODO: other query parameters

  int http_code                  = 0;
  ProblemDetails problem_details = {};
  std::string search_id          = {};
  m_nrf_app->handle_search_nf_instances(
Rohan's avatar
Rohan committed
551
552
      target_nfType, requester_nfType, requester_nfInstance_id, limit_Nfs,
      search_id, http_code, 2, problem_details);
Rohan's avatar
Rohan committed
553
554
555
556
557
558
559
560
561
562
563
564
565

  nlohmann::json json_data = {};
  std::string content_type = "application/json";

  std::shared_ptr<nrf_search_result> search_result = {};
  m_nrf_app->find_search_result(search_id, search_result);

  if (http_code != HTTP_STATUS_CODE_200_OK) {
    to_json(json_data, problem_details);
    content_type = "application/problem+json";
  } else {
    // convert the profile to Json
    if (search_result != nullptr)
Rohan's avatar
Rohan committed
566
      search_result.get()->to_json(json_data, limit_Nfs);
Rohan's avatar
Rohan committed
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
  }

  // TODO: applying client restrictions in terms of the number of
  // instances to be returned (i.e. "limit" or "max-
  // payload-size" query parameters) .

  Logger::nrf_sbi().debug("Json data: %s", json_data.dump().c_str());

  header_map h;
  h.emplace("content-type", header_value{content_type});
  response.write_head(http_code, h);
  response.end(json_data.dump().c_str());
}

void nrf_http2_server::access_token_request_handler(
    const SubscriptionData& subscriptionData, const response& response) {}

//------------------------------------------------------------------------------
void nrf_http2_server::stop() {
  server.stop();
}