Skip to content

Commit

Permalink
* src/ne_basic.c, * src/ne_basic.h (ne_putbuf): New function.
Browse files Browse the repository at this point in the history
* test/basic (put): New test case.
  • Loading branch information
notroj committed Nov 11, 2023
1 parent 715cee8 commit 18e4ad4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/ne_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,29 @@ int ne_put(ne_session *sess, const char *uri, int fd)
return ret;
}

int ne_putbuf(ne_session *sess, const char *path,
const char *buf, size_t buflen)
{
ne_request *req = ne_request_create(sess, "PUT", path);
int ret;

#ifdef NE_HAVE_DAV
ne_lock_using_resource(req, path, 0);
ne_lock_using_parent(req, path);
#endif

ne_set_request_body_buffer(req, buf, buflen);

ret = ne_request_dispatch(req);

if (ret == NE_OK && ne_get_status(req)->klass != 2)
ret = NE_ERROR;

ne_request_destroy(req);

return ret;
}

/* Dispatch a GET request REQ, writing the response body to FD fd. If
* RANGE is non-NULL, then it is the value of the Range request
* header, e.g. "bytes=1-5". Returns an NE_* error code. */
Expand Down
5 changes: 5 additions & 0 deletions src/ne_basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ int ne_get(ne_session *sess, const char *path, int fd);
* body to submit from 'fd'. */
int ne_put(ne_session *sess, const char *path, int fd);

/* Perform a PUT request on resource at 'path', including the entity
* body 'buf' of length 'buflen'. */
int ne_putbuf(ne_session *sess, const char *path,
const char *buf, size_t buflen);

#define NE_DEPTH_ZERO (0)
#define NE_DEPTH_ONE (1)
#define NE_DEPTH_INFINITE (2)
Expand Down
1 change: 1 addition & 0 deletions src/neon.vers
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ NEON_0_32 {

NEON_0_33 {
ne_add_interim_handler;
ne_putbuf;
};
14 changes: 14 additions & 0 deletions test/basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,19 @@ static int options2(void)
return OK;
}

static int put(void)
{
ne_session *sess;

CALL(make_session(&sess, single_serve_string, "HTTP/1.1 204 OK\r\n"
"Content-Length: 200\r\n"
"\r\n"));

ONREQ(ne_putbuf(sess, "/foo", "foobar", 6));

return destroy_and_wait(sess);
}

ne_test tests[] = {
T(lookup_localhost),
T(content_type),
Expand All @@ -323,6 +336,7 @@ ne_test tests[] = {
T(dav_capabilities),
T(get),
T(options2),
T(put),
T(NULL)
};

0 comments on commit 18e4ad4

Please sign in to comment.