Esempio n. 1
0
void ICACHE_FLASH_ATTR ssDiscCb(void *arg) {
    struct espconn *pespconn = (struct espconn *)arg;
    struct HttpConnection *c = getHttpConnection(pespconn);
    if (!c) return;
    ureq_close(&c->r);
    c->id = 0;
}
Esempio n. 2
0
int HttpUploader::upload(const StringBuffer& luid, InputStream* inputStream) 
{
    int status = 0;

    // safe checks
    if (!inputStream || !inputStream->getTotalSize()) {
        LOG.error("upload error: no data to transfer");
        return 1;
    }
    if (luid.empty() || syncUrl.empty()  || sourceURI.empty()) {
        LOG.error("upload error: some params are not set");
        return 2;
    }
    
    StringBuffer fullUrl = composeURL();
    URL url(fullUrl.c_str());
    HttpConnection* httpConnection = getHttpConnection();
   
    httpConnection->setCompression(false);
    status = httpConnection->open(url, HttpConnection::MethodPost);
    
    if (status) { 
        delete httpConnection;

        return status;
    }

    httpConnection->setKeepAlive(keepalive);
    httpConnection->setRequestChunkSize(maxRequestChunkSize);
   
    // Set headers (use basic auth)
    HttpAuthentication* auth = new BasicAuthentication(username, password);
    httpConnection->setAuthentication(auth);
    setRequestHeaders(luid, *httpConnection, *inputStream);
    
    // Send the HTTP request
    StringOutputStream response;
    status = httpConnection->request(*inputStream, response);
    LOG.debug("response returned = %s", response.getString().c_str());
    
    // Manage response headers
    if (useSessionID) {
        // Server returns the jsessionId in the Set-Cookie header, can be used for 
        // the subsequent calls of upload().
        StringBuffer hdr = httpConnection->getResponseHeader(HTTP_HEADER_SET_COOKIE);
        sessionID = httpConnection->parseJSessionId(hdr);
    }
    
    httpConnection->close();
    
    delete auth;
    delete httpConnection;
    return status;
}
Esempio n. 3
0
void ICACHE_FLASH_ATTR ssSentCb(void *arg) {
    struct espconn *pespconn = (struct espconn *)arg;
    struct HttpConnection *c = getHttpConnection(pespconn); 

    if (c->r.complete == 1) {
        espconn_disconnect(pespconn);
        return;
    }
    
    ureq_run(&c->r);
    espconn_sent(pespconn, c->r.response.data, c->r.len);
    if (c->r.len < 1024) {
        espconn_disconnect(pespconn);
    }

}