1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef IOS_WEB_NET_REQUEST_GROUP_UTIL_H_
6 #define IOS_WEB_NET_REQUEST_GROUP_UTIL_H_
12 // Request group IDs are internally used by the web layer to associate network
13 // requests to RequestTracker instances, and in turn, to WebState instances.
14 // The ID can be added to the user-agent string by UIWebView in most cases and
15 // then extracted by the network layer.
16 // However, when using non-standard schemes, UIWebView does not add the
17 // "User-Agent" HTTP header to the requests. The workaround for this case is to
18 // add the ID directly in the URL of the main request (which is the only request
19 // accessible from the UIWebView delegate).
23 // Generates a request-group ID.
24 NSString
* GenerateNewRequestGroupID();
26 // Extracts the requestGroupID embedded in a User-Agent string or nil if a
27 // requestGroupID cannot be located.
28 NSString
* ExtractRequestGroupIDFromUserAgent(NSString
* user_agent
);
30 // Returns a new user agent, which is the result of the encoding of
31 // |request_group_id| in |base_user_agent|. The request group ID can be later
32 // extracted with ExtractRequestGroupIDFromUserAgent().
33 // If request_group_id is nil, returns base_user_agent.
34 NSString
* AddRequestGroupIDToUserAgent(NSString
* base_user_agent
,
35 NSString
* request_group_id
);
37 // Extracts the requestGroupID embedded in a NSURL or nil if a requestGroupID
39 NSString
* ExtractRequestGroupIDFromURL(NSURL
* url
);
41 // Returns a new user agent, which is the result of the encoding of
42 // |request_group_id| in |base_url|. The request group ID can be later extracted
43 // with ExtractRequestGroupIDFromURL().
44 NSURL
* AddRequestGroupIDToURL(NSURL
* base_url
, NSString
* request_group_id
);
46 // Extracts the request group ID from |request| by retrieving it from the
47 // user-agent if possible, and from the parent URL otherwise.
48 // The ID can only be retrived from the parent URL if its scheme is
49 // |application_scheme|.
50 // The reason why the |application_scheme| case is different is because
51 // UIWebView does not provide a "User-Agent" HTTP header for these requests.
52 // The ID is then encoded in the URL of the main request, and thus sub-requests
53 // have to look in their parent URL for the ID.
54 NSString
* ExtractRequestGroupIDFromRequest(NSURLRequest
* request
,
55 NSString
* application_scheme
);
59 #endif // IOS_WEB_NET_REQUEST_GROUP_UTIL_H_