Swift API parameter Constraints

Source: Internet
Author: User

When reading the dev guide, there are some constraints about the request parameters, but the distribution is scattered. I sorted it out this morning and did some verification. Now I am releasing the Po.

1) account, object, and container custom metadata Constraints
    1. Each request: the number of custom X-account/Object/container-meta-* entries <= 90;
    2. Each request: each value of the custom X-account/Object/container-meta, URL-encoded byte after UTF-8 <= 256 (one Chinese character counts 3 bytes );
    3. Each request: All <key + value> of the custom X-account/Object/container-meta, URL-encoded byte after UTF-8 <= 4096 (one Chinese character counts 3 bytes );
    4. No limit is found for the total amount of X-account/Object/container-meta. Although the official documents state that the metadata of objects and iner is a maximum of 90, it is found that only a maximum of 90 objects and iner are requested each time, and there is no limit on the total amount. At least, not found yet.
2) Container name Constraints
    1. It cannot contain '/' characters: You can add '/' At the end, which is automatically ignored and not included in the total length;
    2. Bytes <= 256 after URL-encoded of the UTF-8. Although the official documentation said that the length after URL encoding cannot be greater than 256, but it is found that the length is actually a UTF-8 byte, URL-encoded, one Chinese character (% XX) is counted as three bytes.
3) Object Name Constraints
    1. It cannot contain reserved characters. The official document says so, but does not say which are reserved characters, and the source code does not find -. -;
    2. Bytes <= 1024 after URL-encoded of the UTF-8. Although the official documentation said that the length after URL encoding cannot be greater than 1024, but it is found that the length is actually a UTF-8 byte, URL-encoded, one Chinese character (% XX) is counted as three bytes.
4) parameter (Marker, endmarker, and prefix) Constraints URL-encoded 5) Request Line Request Line <= 8192 bytes. This is the length after URL-encoded. A Chinese character (% XX) is counted 9 Bytes. The following is the source code constraints. py. Constraint value definition:
 #  : Max file size allowed for objects Max_file_size = constraints_conf_int ( '  Max_file_size  ' , 5368709122) #  5*1024*1024*1024 + 2  #  : Max length of the name of a key for metadata Max_meta_name_length = constraints_conf_int ( '  Max_meta_name_length  ' , 128 )  #  : Max length of the value of a key for metadata Max_meta_value_length = constraints_conf_int ( '  Max_meta_value_length ' , 256 )  #  : Max number of metadata items Max_meta_count = constraints_conf_int ( '  Max_meta_count  ' , 90 )  #  : Max overall size of metadata Max_meta_overall_size = constraints_conf_int ( '  Max_meta_overall_size  ' , 4096 ) #  : Max Object Name Length Max_object_name_length = constraints_conf_int ( '  Max_object_name_length  ' , 1024 )  #  : Max Object List length of a GET request for a container Container_listing_limit = constraints_conf_int ( '  Container_listing_limit  '  , 10000 ) #  : Max container list length of a GET request for an account Account_listing_limit = constraints_conf_int ( '  Account_listing_limit  ' , 10000 )  #  : Max Account Name Length Max_account_name_length = constraints_conf_int ( '  Max_account_name_length  ' , 256 )  # : Max container Name Length Max_container_name_length = constraints_conf_int ( '  Max_container_name_length  '  , 256 )  #  : Query string format = values to their corresponding Content-Type values Format2content_type = { '  Plain  ' : '  Text/plain  ' , '  JSON  ' : '  Application/JSON  '  ,  '  XML  ' : '  Application/XML  ' }

Determine whether the metadata is legal:

 Def  Check_metadata (req, target_type ): """  Check metadata sent in the request headers.: Param Req: request object: Param target_type: Str: One of: object, container, or account: indicates which type the target storage for the metadata is: raises httpbadrequest: Bad metadata  """  Prefix = '  X-% s-meta-  ' % Target_type.lower () meta_count = 0 meta_size = 0  For Key, Value In  Req. headers. iteritems ():  If   Not  Key. Lower (). startswith (prefix ):  Continue  Key = Key [Len (prefix):]  If   Not  Key:  Return Httpbadrequest (Body = '  Metadata name cannot be empty '  , Request = Req, content_type = '  Text/plain  '  ) Meta_count + = 1 Meta_size + = Len (key) + Len (value)  If Len (key)> Max_meta_name_length:  Return  Httpbadrequest (Body = ' Metadata name too long; max % d  ' % Max_meta_name_length, request = Req, content_type = '  Text/plain  '  )  Elif Len (value)> Max_meta_value_length:  Return  Httpbadrequest (Body = '  Metadata value too long; max % d ' % Max_meta_value_length, request = Req, content_type = '  Text/plain  '  )  Elif Meta_count> Max_meta_count:  Return  Httpbadrequest (Body = '  Too export metadata items; max % d  ' %Max_meta_count, request = Req, content_type = '  Text/plain  '  )  Elif Meta_size> Max_meta_overall_size:  Return  Httpbadrequest (Body = '  Total metadata too large; max % d  ' % Max_meta_overall_size, request = Req, content_type = '  Text/plain  '  )  Return None

Determine whether the data of the created object is valid:

 Def  Check_object_creation (req, object_name ):  """ Check to ensure that everything is alright about an object to be created.: Param Req: http request object: Param object_name: name of object to be created: raises httprequestentitytoolarge: the object is too large: raises httplengthrequered: missing Content-Length header and not a chunked request: raises httpbadrequest: Missing or bad Content-Type header, or bad metadata  """      If Req. content_length And Req. content_length> Max_file_size:  Return Httprequestentitytoolarge (Body = ' Your request is too large.  '  , Request = Req, content_type = '  Text/plain  '  )  If Req. content_length Is None And  \ Req. headers. Get (  ' Transfer-Encoding  ' )! = '  Chunked  '  :  Return Httplengthrequired (request = REQ)  If   '  X-copy-from  '   In Req. Headers And  Req. content_length: Return Httpbadrequest (Body = '  Copy requests require a zero byte body  '  , Request = Req, content_type = '  Text/plain  '  )  If Len (object_name)> Max_object_name_length:  Return Httpbadrequest (Body = ' Object Name Length of % d longer than % d  ' % (LEN (object_name), max_object_name_length), request = Req, content_type = '  Text/plain  '  )  If   '  Content-Type  '   Not   In  Req. headers: Return Httpbadrequest (request = req, content_type = '  Text/plain  '  , Body = '  NO content type  '  )  If   Not Check_utf8 (req. headers [ '  Content-Type  '  ]): Return Httpbadrequest (request = req, body = '  Invalid Content-Type  '  , Content_type = '  Text/plain  '  )  If   '  X-object-manifest  '   In  Req. headers: Value = Req. headers ['  X-object-manifest  '  ] Container = Prefix = None  Try  : Container, prefix = Value. Split ( '  /  ' , 1 )  Except  Valueerror:  Pass          If  Not Container Or   Not Prefix Or   '  ?  '   In Value Or   '  &  '   In Value Or  \ Prefix [0] = ' /  '  :  Return  Httpbadrequest (Request = Req, body = '  X-object-manifest must in the format container/prefix  '  )  Return Check_metadata (req, '  Object  ' )

 

In fact, during the test, I found that SWIFT is quite robust and will handle errors that violate all the constraints described above: reject the request, return the error code and cause of the response. Therefore, the idea that we intend to impose another constraint on the SDK layer is not that important, but will increase complexity and reduce SDK efficiency. Therefore, it is OK to add only business layer constraints, for example:
    1. '*' In X-account/Object/container-meta-* is the key value, ISO-8859-1 character set, which is a simple character such as English letters,-, _, space;
    2. You cannot directly create, access, or delete a iner with the suffix "_ segments;
    3. You cannot directly create, access, or delete a iner with the suffix "_ versions.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.