Branch: Tag:

2000-08-04

2000-08-04 20:10:26 by Johan Sundström <oyasumi@gmail.com>

Protocols.HTTP now sends host headers.

Rev: lib/modules/Protocols.pmod/HTTP.pmod/module.pmod:1.14

45:   //! query variables is sent as a post request instead of a get.   //!    - object get_url(string url,void|mapping query_variables, void|mapping request_headers) + object get_url(string url, +  void|mapping query_variables, +  void|mapping request_headers)   {    object con=master()->resolv("Protocols")["HTTP"]["Query"]();   
65:    error("Protocols.HTTP can't handle %O or any other protocol than HTTP\n",    prot);    -  if (query_variables) +  if (query_variables && sizeof(query_variables))    {    if (search(query,"?")!=-1)    query+="&"+http_encode_query(query_variables);
75:       con->sync_request(host,port,    "GET /"+query+" HTTP/1.0", -  (["user-agent": -  "Mozilla/4.0 compatible (Pike HTTP client)"]) | request_headers); +  ([ +  "user-agent":"Mozilla/4.0 compatible (Pike HTTP client)", +  "host":host +  ]) | request_headers);       if (!con->ok) return 0;    return con;   }    - object put_url(string url, void|string file, void|mapping query_variables, + object put_url(string url, +  void|string file, +  void|mapping query_variables,    void|mapping request_headers)   {    object con=master()->resolv("Protocols")["HTTP"]["Query"]();
103:    error("Protocols.HTTP can't handle %O or any other protocol than HTTP\n",    prot);    -  if (query_variables) +  if (query_variables && sizeof(query_variables))    {    if (search(query,"?")!=-1)    query+="&"+http_encode_query(query_variables);
111:    query+="?"+http_encode_query(query_variables);    }    -  con->sync_request(host,port, +  con->sync_request(host, port,    "PUT /"+query+" HTTP/1.0",    ([ -  "user-agent": -  "Mozilla/4.0 compatible (Pike HTTP client)" +  "user-agent":"Mozilla/4.0 compatible (Pike HTTP client)", +  "host":host    ]) | request_headers,    file);   
123:    return con;   }    - object delete_url(string url, void|mapping query_variables, + object delete_url(string url, +  void|mapping query_variables,    void|mapping request_headers)   {    object con=master()->resolv("Protocols")["HTTP"]["Query"]();
144:    error("Protocols.HTTP can't handle %O or any other protocol than HTTP\n",    prot);    -  if (query_variables) +  if (query_variables && sizeof(query_variables))    {    if (search(query,"?")!=-1)    query+="&"+http_encode_query(query_variables);
154:       con->sync_request(host,port,    "DELETE /"+query+" HTTP/1.0", -  (["user-agent": -  "Mozilla/4.0 compatible (Pike HTTP client)"]) | +  ([ +  "user-agent":"Mozilla/4.0 compatible (Pike HTTP client)", +  "host":host +  ]) |    request_headers);       if (!con->ok) return 0;
196:       con->sync_request(host,port,    "POST /"+query+" HTTP/1.0", -  (["user-agent": -  "Mozilla/4.0 compatible (Pike HTTP client)"]) | +  ([ +  "user-agent":"Mozilla/4.0 compatible (Pike HTTP client)", +  "host":host +  ]) |    request_headers |    (["content-type":    "application/x-www-form-urlencoded"]),
207:    return con;   }    - array(string) post_url_nice(string url,mapping query_variables, void|mapping request_headers) + array(string) post_url_nice(string url, +  mapping query_variables, +  void|mapping request_headers)   {    object c=post_url(url,query_variables, request_headers);    return c && ({c->headers["content-type"],c->data()});   }    - string post_url_data(string url,mapping query_variables, void|mapping request_headers) + string post_url_data(string url, +  mapping query_variables, +  void|mapping request_headers)   {    object z=post_url(url,query_variables, request_headers);    return z && z->data();