A kind of method of accelerating HTTP on IOS
Technical field
The present invention relates to HTTP and accelerate, especially, on IOS, by flow, guide with protocol conversion and accelerate the method for HTTP.
Background technology
The method of current acceleration HTTP, is generally to adopt APN to carry out the HTTP Proxy of standard, and content is compressed to reach the effect of acceleration, such as flow at full speed.The defect of this speed technology has: be 1. only that the content of request is compressed in agency service, can cause like this picture category resource fuzzy; 2. such agent skill group, can only arrange agency and the handle packet of having no way can not be optimized the agent skill group of standard in client.
The patent of invention that for example application number is 201310362191.1, disclose a kind of HTTP and uploaded accelerated method, the HTTP upload request for meeting certain condition, can reduce the response time, improve response speed, also can alleviate the pressure of CDN service node simultaneously.Its technical scheme is: upload configuration is carried out in source station; User uploads static data by upload configuration; Content delivery network node receives request; The whether applicable acceleration function of uploading of the request that content delivery network node judgement receives; If ask the inapplicable acceleration function of uploading, upload data to source station, receive the response that source station is returned, and send response to user; If request is applicable, upload acceleration function, after user data upload completes, to user, send response, and save the data in local cache, and in any time thereafter, the data in local cache are synchronized to source station.This patent of invention need to be carried out secondary development on software, and it realizes complicated.
The patent of invention that for example application number is 200910127106.7 again, the HTTP that discloses a kind of dialogue-based high-speed cache accelerates, and its method comprises: receive the first HTML (Hypertext Markup Language) (HTTP) packet; Based on HTTP packet, create the first session; And be the first conversation establishing session cache entry; Receive the 2nd HTTP packet; Carry out session cache searching to identify mating of the 2nd HTTP packet and session cache entries; And mate to create the second http session based on the 2nd HTTP packet and session cache entries.This patent of invention needs the support of hardware, and cannot directly realize by software.
Summary of the invention
Therefore, for above-mentioned problem, the present invention proposes a kind of method of accelerating HTTP on IOS, solve that IOS is upper thisly to be only had agency service end and cause content compression distortion and the too poor problem of standard agency agreement efficiency without the agent skill group of client, do not need in addition software to carry out secondary development, do not need the support of hardware, only by agency, can realize and accelerate HTTP yet.
In order to solve the problems of the technologies described above, thinking of the present invention is first, to set up local agent service, and guide HTTP flow to local agent service; Local agent service is processed content, and the http protocol of standard is converted into the agreement that performance is higher (such as spdy, utp).When app starts, call the function of sdk, lookup process address at this time, finds the address of this function, and then replacement function address, can allow app call the function of own realization.The method of finishing interflow amount guiding and protocol conversion is provided, and one side can get packet and content is optimized to process and prevent from can standard agreement being optimized distortion and being raised the efficiency on the other hand.
Concrete, a kind of method of accelerating HTTP on IOS of the present invention, has disclosed IOS and above in conjunction with flow guiding and protocol conversion, has accelerated the method for HTTP, and the method comprises:
Step 1: set up local agent service;
Step 2: the application software that produces HTTP flow is designated as to HTTP_APP, when this HTTP_APP initiates HTTP request, first HTTP request is forwarded to local agent service;
Step 3: first local agent service is converted to the data of HTTP request the data of the higher protocol formats of performance such as spdy protocol format or utp protocol format, then sends to the data after conversion the proxy server of far-end;
Step 4: the proxy server of far-end is resolved the data that receive, if spdy protocol format resolves according to spdy agreement it, and is reduced into former HTTP data; If utp protocol format resolves according to utp agreement it, and be reduced into former HTTP data; Then the former HTTP data after reduction are sent to destination address;
Step 5: destination address is resolved the former HTTP data of receiving, and export HTTP result data, by remote agent's server, this HTTP result data is converted to the data of the higher protocol formats of performance such as spdy protocol format or utp protocol format, http protocol is converted to spdy agreement or utp agreement; By spdy agreement or utp agreement, the result data after conversion being sent to local agent afterwards serves;
Step 6: local agent service reception to data resolve, if spdy protocol format resolves according to spdy agreement it, and be reduced into former HTTP result data; If utp protocol format resolves according to utp agreement it, and be reduced into former HTTP result data; Then the former HTTP result data after reduction is sent to user side.
Further, set up local agent service and comprise following content: structure proxy function, this proxy function realizes all functions that primary HTTP API obtains system overall situation agency's function (function SCDynamicStoreCopyProxies), after this proxy function is set up, by primary HTTP API Calls, realize agency; This proxy function is returned to the structure that comprises proxy information, and this proxy information at least comprises proxy, proxy port; Obtain the process address of HTTP_APP, and search the mirror image head of HTTP_APP in the middle of internal memory, find the function (function name is SCDynamicStoreCopyProxies) of the proxy information that obtains current network, by the function address in the address replacing structure proxy function of this function; Then create local agent service thread.
Further, HTTP_APP initiates HTTP request, first to HTTP, preliminary treatment is carried out in request, and then send, this preliminary treatment comprises if process: whether first this HTTP request detects the domain name that this HTTP request will access identical with the domain name of HTTP_APP, if both are not identical, the domain name that HTTP request will be accessed changes the domain name of HTTP_APP into; Whether the authorized agency's row (a line after stem <headers>) that then detects HTTP request is empty, if be not empty, is changed into blank line, and then this HTTP request is sent.By above-mentioned setting, can safeguard the validity of HTTP request, when avoiding follow-up authorized agency, occur that agency makes mistakes, and cause the method not use, and then cause cannot using of HTTP_APP.
The present invention passes through above-mentioned steps, the foundation of serving by local agent, the data of HTTP_APP transmission are all converted to the data of the higher protocol formats of performance such as spdy protocol format or utp protocol format, thereby greatly accelerated reception and the transmission of HTTP, solved that IOS is upper thisly to be only had agency service end and cause content compression distortion and the too poor problem of standard agency agreement efficiency without the agent skill group of client; In addition, the situation that the present invention also makes mistakes to authorized agency arranges, and greatly reduces the generation of the situation that HTTP_APP cannot use because local agent service makes mistakes; Meanwhile, the present invention only needs to set up a local agent service authorized agency, does not need software to carry out extra exploitation, greatly alleviated developer's burden, and do not need the support of hardware, only by agency, can realize and accelerate HTTP, there is good practicality.
Embodiment
Now in conjunction with embodiment, the present invention is further described.
As a concrete example, the SDK the invention provides based on ios platform supplies the application software HTTP_APP of the generation HTTP flow of IOS to call, and it relates to client and service end.On content compression and protocol optimization, need to accomplish that client and service end coordinate.Wherein, this SDK possesses following two large functions: (1) guiding HTTP flow is to local agent.(2) http protocol of standard is converted into the agreement that performance is higher, content is processed simultaneously.
Wherein, guiding HTTP flow is to local agent, and the service of model local agent, is comprised of following steps:
Step 1: first create a local agent thread, and return to IP address and the port (127.0.0.1:port) of local agent, be kept in memory variable;
Step 2: the imageheader mirror image head of searching APP, finding name is the function address of " SCDynamicStoreCopyProxies " (function: the agency who returns to current network arranges), this address is replaced with to the IP address that this function of SQL my_SCDynamicStoreCopyProxies(returns to local agent, it realizes the function that SCDynamicStoreCopyProxies function is identical, and is only that its agent address is different) address;
When step 3:APP calls my_SCDynamicStoreCopyProxies function, this function first calls primary SCDynamicStoreCopyProxies function, the agency who obtains current network arranges, then the local agent IP address getting by step 1 and port (127.0.0.1:port) are replaced current network and are acted on behalf of IP and the port in arranging, and return to by reaching local agent setting after replacing the function that call on upper strata, with this, reach and replace the object that current network agency arranges.
The http protocol of standard is converted into the agreement that performance is higher and content is processed to play the object of accelerating HTTP, by following steps, formed:
Step 1: the application software that produces HTTP flow is designated as to HTTP_APP, when this HTTP_APP initiates HTTP request, first HTTP request is forwarded to local agent service;
Step 2: first local agent service changes into corresponding protocol format (the higher protocol format of performance) by the HTTP request of receiving, and is forwarded to the proxy server of far-end.General, can use two kinds of agreements to be optimized: (1) spdy agreement, local agent and remote agent establish spdysession, HTTP request is changed into spdy agreement and send to remote agent.This agreement can reduce tcp establishment of connection, improves the concurrent number of request.(2) utp agreement, is used udp agreement, in application layer, realizes the effect that overtime re-transmission reaches tcp agreement.Can reduce the tcp agreement establishment of connection time and improve the efficiency of overtime re-transmission;
Step 3: the proxy server of far-end is resolved the data that receive, if spdy protocol format resolves according to spdy agreement it, and is reduced into former HTTP data; If utp protocol format resolves according to utp agreement it, and be reduced into former HTTP data; Then the former HTTP data after reduction are sent to destination address; Meanwhile, the proxy server of far-end also can be optimized former HTTP data, such as for picture format transformation, unpressed content is compressed.In client, carrying out contrary operation (decompression), is transparent thereby reach HTTP_APP; Then the data after processing are sent to the proxy server of far-end;
Step 4: destination address is resolved the former HTTP data of receiving, and export HTTP result data, by remote agent's server, this HTTP result data is converted to the data of the higher protocol formats of performance such as spdy protocol format or utp protocol format, http protocol is converted to spdy agreement or utp agreement; By spdy agreement or utp agreement, the result data after conversion being sent to local agent afterwards serves;
Step 5: local agent service reception to data resolve, if spdy protocol format resolves according to spdy agreement it, and be reduced into former HTTP result data; If utp protocol format resolves according to utp agreement it, and be reduced into former HTTP result data; Then the former HTTP result data after reduction is sent to user side.
In addition, when HTTP_APP initiates HTTP request, first to HTTP, preliminary treatment is carried out in request, and then send, this preliminary treatment comprises if process: whether first this HTTP request detects the domain name that this HTTP request will access identical with the domain name of HTTP_APP, if both are not identical, the domain name that HTTP request will be accessed changes the domain name of HTTP_APP into; Whether the authorized agency's row (a line after stem <headers>) that then detects HTTP request is empty, if be not empty, is changed into blank line, and then this HTTP request is sent.By above-mentioned setting, can safeguard the validity of HTTP request, when avoiding follow-up authorized agency, occur that agency makes mistakes, and cause the method not use, and then cause cannot using of HTTP_APP.
Although specifically show and introduced the present invention in conjunction with preferred embodiment; but those skilled in the art should be understood that; within not departing from the spirit and scope of the present invention that appended claims limits; can make a variety of changes the present invention in the form and details, be protection scope of the present invention.