@@ -434,17 +434,17 @@ void http_hdr_describe(HdrHeapObjImpl *obj, bool recurse = true);
434434
435435bool http_hdr_version_set (HTTPHdrImpl *hh, const HTTPVersion &ver);
436436
437- const char * http_hdr_method_get (HTTPHdrImpl *hh, int *length );
438- void http_hdr_method_set (HdrHeap *heap, HTTPHdrImpl *hh, const char *method, int16_t method_wks_idx, int method_length,
439- bool must_copy);
437+ std::string_view http_hdr_method_get (HTTPHdrImpl *hh);
438+ void http_hdr_method_set (HdrHeap *heap, HTTPHdrImpl *hh, const char *method, int16_t method_wks_idx, int method_length,
439+ bool must_copy);
440440
441441void http_hdr_url_set (HdrHeap *heap, HTTPHdrImpl *hh, URLImpl *url);
442442
443443// HTTPStatus http_hdr_status_get (HTTPHdrImpl *hh);
444- void http_hdr_status_set (HTTPHdrImpl *hh, HTTPStatus status);
445- const char * http_hdr_reason_get (HTTPHdrImpl *hh, int *length );
446- void http_hdr_reason_set (HdrHeap *heap, HTTPHdrImpl *hh, const char *value, int length, bool must_copy);
447- const char *http_hdr_reason_lookup (unsigned status);
444+ void http_hdr_status_set (HTTPHdrImpl *hh, HTTPStatus status);
445+ std::string_view http_hdr_reason_get (HTTPHdrImpl *hh);
446+ void http_hdr_reason_set (HdrHeap *heap, HTTPHdrImpl *hh, const char *value, int length, bool must_copy);
447+ const char *http_hdr_reason_lookup (unsigned status);
448448
449449void http_parser_init (HTTPParser *parser);
450450void http_parser_clear (HTTPParser *parser);
@@ -516,9 +516,9 @@ class HTTPHdr : public MIMEHdr
516516 HTTPVersion version_get () const ;
517517 void version_set (HTTPVersion version);
518518
519- const char * method_get (int *length );
520- int method_get_wksidx () const ;
521- void method_set (const char *value, int length);
519+ std::string_view method_get ();
520+ int method_get_wksidx () const ;
521+ void method_set (const char *value, int length);
522522
523523 URL *url_create (URL *url);
524524
@@ -561,31 +561,28 @@ class HTTPHdr : public MIMEHdr
561561
562562 /* * Get the URL path.
563563 This is a reference, not allocated.
564- @return A pointer to the path or @c NULL if there is no valid URL.
564+ @return A string_view to the path or an empty string_view if there is no valid URL.
565565 */
566- const char *path_get (int *length // /< Storage for path length.
567- );
566+ std::string_view path_get ();
568567
569568 /* * Get the URL query.
570569 This is a reference, not allocated.
571- @return A pointer to the query or @c NULL if there is no valid URL.
570+ @return A string_view to the query or an empty string_view if there is no valid URL.
572571 */
573- const char *query_get (int *length // /< Storage for query length.
574- );
572+ std::string_view query_get ();
575573
576574 /* * Get the URL fragment.
577575 This is a reference, not allocated.
578- @return A pointer to the fragment or @c NULL if there is no valid URL.
576+ @return A string_view to the fragment or an empty string_view if there is no valid URL.
579577 */
580- const char *fragment_get (int *length // /< Storage for fragment length.
581- );
578+ std::string_view fragment_get ();
582579
583580 /* * Get the target host name.
584581 The length is returned in @a length if non-NULL.
585582 @note The results are cached so this is fast after the first call.
586- @return A pointer to the host name.
583+ @return A string_view to the host name.
587584 */
588- const char * host_get (int *length = nullptr ) const ;
585+ std::string_view host_get () const ;
589586
590587 /* * Get the target port.
591588 If the target port is not found then it is adjusted to the
@@ -597,12 +594,11 @@ class HTTPHdr : public MIMEHdr
597594
598595 /* * Get the URL scheme.
599596 This is a reference, not allocated.
600- @return A pointer to the scheme or @c NULL if there is no valid URL.
597+ @return A string_view to the scheme or an empty string_view if there is no valid URL.
601598 */
602- const char *scheme_get (int *length // /< Storage for path length.
603- );
604- void url_set (URL *url);
605- void url_set (const char *str, int length);
599+ std::string_view scheme_get ();
600+ void url_set (URL *url);
601+ void url_set (const char *str, int length);
606602
607603 // / Check location of target host.
608604 // / @return @c true if the host was in the URL, @c false otherwise.
@@ -627,8 +623,8 @@ class HTTPHdr : public MIMEHdr
627623 HTTPStatus status_get () const ;
628624 void status_set (HTTPStatus status);
629625
630- const char * reason_get (int *length );
631- void reason_set (const char *value, int length);
626+ std::string_view reason_get ();
627+ void reason_set (const char *value, int length);
632628
633629 void mark_early_data (bool flag = true ) const ;
634630 bool is_early_data () const ;
@@ -774,21 +770,19 @@ HTTPHdr::_test_and_fill_target_cache() const
774770/* -------------------------------------------------------------------------
775771 -------------------------------------------------------------------------*/
776772
777- inline const char *
778- HTTPHdr::host_get (int *length ) const
773+ inline std::string_view
774+ HTTPHdr::host_get () const
779775{
780776 this ->_test_and_fill_target_cache ();
781777 if (m_target_in_url) {
782- return url_get ()->host_get (length);
778+ int length;
779+ auto host{url_get ()->host_get (&length)};
780+ return std::string_view{host, static_cast <std::string_view::size_type>(length)};
783781 } else if (m_host_mime) {
784- if (length)
785- *length = m_host_length;
786- return m_host_mime->m_ptr_value ;
782+ return std::string_view{m_host_mime->m_ptr_value , static_cast <std::string_view::size_type>(m_host_length)};
787783 }
788784
789- if (length)
790- *length = 0 ;
791- return nullptr ;
785+ return std::string_view{};
792786}
793787
794788/* -------------------------------------------------------------------------
@@ -948,13 +942,13 @@ HTTPHdr::version_set(HTTPVersion version)
948942/* -------------------------------------------------------------------------
949943 -------------------------------------------------------------------------*/
950944
951- inline const char *
952- HTTPHdr::method_get (int *length )
945+ inline std::string_view
946+ HTTPHdr::method_get ()
953947{
954948 ink_assert (valid ());
955949 ink_assert (m_http->m_polarity == HTTP_TYPE_REQUEST );
956950
957- return http_hdr_method_get (m_http, length );
951+ return http_hdr_method_get (m_http);
958952}
959953
960954inline int
@@ -1099,13 +1093,13 @@ HTTPHdr::status_set(HTTPStatus status)
10991093/* -------------------------------------------------------------------------
11001094 -------------------------------------------------------------------------*/
11011095
1102- inline const char *
1103- HTTPHdr::reason_get (int *length )
1096+ inline std::string_view
1097+ HTTPHdr::reason_get ()
11041098{
11051099 ink_assert (valid ());
11061100 ink_assert (m_http->m_polarity == HTTP_TYPE_RESPONSE );
11071101
1108- return http_hdr_reason_get (m_http, length );
1102+ return http_hdr_reason_get (m_http);
11091103}
11101104
11111105/* -------------------------------------------------------------------------
@@ -1201,32 +1195,52 @@ HTTPHdr::url_string_get_ref(int *length)
12011195 return this ->url_string_get (USE_HDR_HEAP_MAGIC , length);
12021196}
12031197
1204- inline const char *
1205- HTTPHdr::path_get (int *length )
1198+ inline std::string_view
1199+ HTTPHdr::path_get ()
12061200{
12071201 URL *url = this ->url_get ();
1208- return url ? url->path_get (length) : nullptr ;
1202+ if (url) {
1203+ int length;
1204+ auto path{url->path_get (&length)};
1205+ return std::string_view{path, static_cast <std::string_view::size_type>(length)};
1206+ }
1207+ return std::string_view{};
12091208}
12101209
1211- inline const char *
1212- HTTPHdr::query_get (int *length )
1210+ inline std::string_view
1211+ HTTPHdr::query_get ()
12131212{
12141213 URL *url = this ->url_get ();
1215- return url ? url->query_get (length) : nullptr ;
1214+ if (url) {
1215+ int length;
1216+ auto query{url->query_get (&length)};
1217+ return std::string_view{query, static_cast <std::string_view::size_type>(length)};
1218+ }
1219+ return std::string_view{};
12161220}
12171221
1218- inline const char *
1219- HTTPHdr::fragment_get (int *length )
1222+ inline std::string_view
1223+ HTTPHdr::fragment_get ()
12201224{
12211225 URL *url = this ->url_get ();
1222- return url ? url->fragment_get (length) : nullptr ;
1226+ if (url) {
1227+ int length;
1228+ auto fragment{url->fragment_get (&length)};
1229+ return std::string_view{fragment, static_cast <std::string_view::size_type>(length)};
1230+ }
1231+ return std::string_view{};
12231232}
12241233
1225- inline const char *
1226- HTTPHdr::scheme_get (int *length )
1234+ inline std::string_view
1235+ HTTPHdr::scheme_get ()
12271236{
12281237 URL *url = this ->url_get ();
1229- return url ? url->scheme_get (length) : nullptr ;
1238+ if (url) {
1239+ int length;
1240+ auto scheme{url->scheme_get (&length)};
1241+ return std::string_view{scheme, static_cast <std::string_view::size_type>(length)};
1242+ }
1243+ return std::string_view{};
12301244}
12311245
12321246/* -------------------------------------------------------------------------
0 commit comments