direct_client gen_headers is inconsistent

Bug #1757250 reported by clayg
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Object Storage (swift)
New
Wishlist
Unassigned

Bug Description

consumers of direct_client should be able to reliably over-ride the user-agent header and set x-timestamp

We should replace gen_headers with a more useful utility and make sure all direct_client methods accept the headers kwarg

Something like this:

    def prepare_headers(headers, ensure_ts=True):
        """
        Get the headers ready for a request. All requests should have a User-Agent
        string, but if one is passed in don't over-write it. Not all requests will
        need an X-Timestamp, but if one is passed in do not over-write it.

        :param headers: dict or None, base for HTTP headers
        :param ensure_ts: boolean, should be True for any "unsafe" HTTP request

        :returns: HeaderKeyDict based on headers and ready for the request
        """
        hdrs_out = HeaderKeyDict(headers) if headers else HeaderKeyDict()
        if ensure_ts and 'x-timestamp' not in hdrs_out:
            hdrs_out['X-Timestamp'] = Timestamp.now().internal
        if 'user-agent' not in hdrs_out:
            hdrs_out['User-Agent'] = 'direct-client %s' % os.getpid()
        return hdrs_out

... and all the tests that go with it

Revision history for this message
Tim Burke (1-tim-z) wrote :

> make sure all direct_client methods accept the headers kwarg

At time of writing (around 2.19.0), the following methods need this:

- direct_get_account
- direct_head_container

Separately, do we not have direct_head_account or direct_post_account functions?

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to swift (master)

Reviewed: https://review.openstack.org/603261
Committed: https://git.openstack.org/cgit/openstack/swift/commit/?id=c8e3b996aed7707c222db35640adc9860b2c8839
Submitter: Zuul
Branch: master

commit c8e3b996aed7707c222db35640adc9860b2c8839
Author: FatemaKhalid <email address hidden>
Date: Tue Sep 18 02:36:33 2018 +0200

    Enabling direct_client users to overwrite X-Timestamp

    Changing gen_headers to set User-Agent if not already added
    and set x-timestamp by default if it's not already set nor
    it's requested not to be put.

    Change-Id: Ied073778cf5d34ddcb2f5af59d5b762e51c9b11f
    Partial-Bug: 1757250

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.