Skip to content
http.c 34.4 KiB
Newer Older
      add_bufferf(req_buffer, "\r\n");
      /* set the upload size to the progress meter */
      Curl_pgrsSetUploadSize(data, data->set.infilesize);
Daniel Stenberg's avatar
Daniel Stenberg committed

      /* this sends the buffer and frees all the buffer resources */
      result = add_buffer_send(req_buffer, conn->firstsocket, conn,
        failf(data, "Failed sending POST request");
      else
        /* prepare for transfer */
        result = Curl_Transfer(conn, conn->firstsocket, -1, TRUE,
                               &http->readbytecount,
                               conn->firstsocket,
                               &http->writebytecount);
Daniel Stenberg's avatar
Daniel Stenberg committed
      if(result)
        return result;
    case HTTPREQ_POST:
      /* this is the simple POST, using x-www-form-urlencoded style */
      if(!conn->bits.upload_chunky) {
        /* We only set Content-Length and allow a custom Content-Length if
           we don't upload data chunked, as RFC2616 forbids us to set both
           kinds of headers (Transfer-Encoding: chunked and Content-Length) */

        if(!checkheaders(data, "Content-Length:"))
          /* we allow replacing this header, although it isn't very wise to
             actually set your own */
          add_bufferf(req_buffer,
                      "Content-Length: %d\r\n",
                      data->set.postfieldsize?
                      data->set.postfieldsize:
                      (data->set.postfields?strlen(data->set.postfields):0) );
      }
      if(!checkheaders(data, "Content-Type:"))
        add_bufferf(req_buffer,
                    "Content-Type: application/x-www-form-urlencoded\r\n");

      add_buffer(req_buffer, "\r\n", 2);

      /* and here comes the actual data */
      if(data->set.postfieldsize && data->set.postfields) {
        add_buffer(req_buffer, data->set.postfields,
                   data->set.postfieldsize);
      else if(data->set.postfields)
        add_bufferf(req_buffer,
                    "%s",
                    data->set.postfields );

      /* issue the request */
      result = add_buffer_send(req_buffer, conn->firstsocket, conn,
                               &data->info.request_size);

      if(result)
        failf(data, "Failed sending HTTP POST request");
          Curl_Transfer(conn, conn->firstsocket, -1, TRUE,
                        &http->readbytecount,
                        data->set.postfields?-1:conn->firstsocket,
                        data->set.postfields?NULL:&http->writebytecount);
      break;
      /* issue the request */
      result = add_buffer_send(req_buffer, conn->firstsocket, conn,
      if(result)
        failf(data, "Failed sending HTTP request");
      else
        /* HTTP GET/HEAD download: */
        result = Curl_Transfer(conn, conn->firstsocket, -1, TRUE,
                               &http->readbytecount,
Daniel Stenberg's avatar
Daniel Stenberg committed
    if(result)
      return result;
  } while (0); /* this is just a left-over from the multiple document download
                  attempts */

  return CURLE_OK;

/*
 * local variables:
 * eval: (load-file "../curl-mode.el")
 * end:
 * vim600: fdm=marker
 * vim: et sw=2 ts=2 sts=2 tw=78