@@ -191,6 +191,7 @@ static inline void get_v2_qs_map(const req_info& info,
191191 * compute a request's signature
192192 */
193193bool rgw_create_s3_canonical_header (const DoutPrefixProvider *dpp,
194+ RGWOpType op_type,
194195 const req_info& info,
195196 utime_t * const header_time,
196197 std::string& dest,
@@ -253,7 +254,8 @@ bool rgw_create_s3_canonical_header(const DoutPrefixProvider *dpp,
253254 request_uri = info.effective_uri ;
254255 }
255256
256- rgw_create_s3_canonical_header (dpp, info.method , content_md5, content_type,
257+ auto method = rgw::auth::s3::get_canonical_method (dpp, op_type, info);
258+ rgw_create_s3_canonical_header (dpp, method.c_str (), content_md5, content_type,
257259 date.c_str (), meta_map, qs_map,
258260 request_uri.c_str (), sub_resources, dest);
259261 return true ;
@@ -704,35 +706,6 @@ std::string gen_v4_canonical_qs(const req_info& info, bool is_non_s3_op)
704706 return canonical_qs;
705707}
706708
707- std::string get_v4_canonical_method (const req_state* s)
708- {
709- /* If this is a OPTIONS request we need to compute the v4 signature for the
710- * intended HTTP method and not the OPTIONS request itself. */
711- if (s->op_type == RGW_OP_OPTIONS_CORS) {
712- const char *cors_method = s->info .env ->get (" HTTP_ACCESS_CONTROL_REQUEST_METHOD" );
713-
714- if (cors_method) {
715- /* Validate request method passed in access-control-request-method is valid. */
716- auto cors_flags = get_cors_method_flags (cors_method);
717- if (!cors_flags) {
718- ldpp_dout (s, 1 ) << " invalid access-control-request-method header = "
719- << cors_method << dendl;
720- throw -EINVAL;
721- }
722-
723- ldpp_dout (s, 10 ) << " canonical req method = " << cors_method
724- << " , due to access-control-request-method header" << dendl;
725- return cors_method;
726- } else {
727- ldpp_dout (s, 1 ) << " invalid http options req missing "
728- << " access-control-request-method header" << dendl;
729- throw -EINVAL;
730- }
731- }
732-
733- return s->info .method ;
734- }
735-
736709boost::optional<std::string>
737710get_v4_canonical_headers (const req_info& info,
738711 const std::string_view& signedheaders,
@@ -1740,4 +1713,32 @@ AWSv4ComplSingle::create(const req_state* const s,
17401713 return std::make_shared<AWSv4ComplSingle>(s);
17411714}
17421715
1716+ std::string get_canonical_method (const DoutPrefixProvider *dpp, RGWOpType op_type, const req_info& info)
1717+ {
1718+ /* If this is a OPTIONS request we need to compute the v4 signature for the
1719+ * intended HTTP method and not the OPTIONS request itself. */
1720+ if (op_type == RGW_OP_OPTIONS_CORS) {
1721+ const char *cors_method = info.env ->get (" HTTP_ACCESS_CONTROL_REQUEST_METHOD" );
1722+
1723+ if (cors_method) {
1724+ /* Validate request method passed in access-control-request-method is valid. */
1725+ auto cors_flags = get_cors_method_flags (cors_method);
1726+ if (!cors_flags) {
1727+ ldpp_dout (dpp, 1 ) << " invalid access-control-request-method header = "
1728+ << cors_method << dendl;
1729+ throw -EINVAL;
1730+ }
1731+
1732+ ldpp_dout (dpp, 10 ) << " canonical req method = " << cors_method
1733+ << " , due to access-control-request-method header" << dendl;
1734+ return cors_method;
1735+ } else {
1736+ ldpp_dout (dpp, 1 ) << " invalid http options req missing "
1737+ << " access-control-request-method header" << dendl;
1738+ throw -EINVAL;
1739+ }
1740+ }
1741+
1742+ return info.method ;
1743+ }
17431744} // namespace rgw::auth::s3
0 commit comments