mirror of
https://github.com/jorisvink/kore
synced 2025-03-09 04:29:02 -04:00
Add http_response_close() to the C API.
This is the same as http_response() except it will automatically close the connection after the response is sent. This is a bit easier than setting CONN_CLOSE_EMPTY yourself manually.
This commit is contained in:
parent
b77d727f72
commit
eb0b8f21e3
@ -357,6 +357,8 @@ int http_body_digest(struct http_request *, char *, size_t);
|
||||
int http_redirect_add(struct kore_domain *,
|
||||
const char *, int, const char *);
|
||||
void http_response(struct http_request *, int, const void *, size_t);
|
||||
void http_response_close(struct http_request *, int,
|
||||
const void *, size_t);
|
||||
void http_response_fileref(struct http_request *, int,
|
||||
struct kore_fileref *);
|
||||
void http_serveable(struct http_request *, const void *,
|
||||
|
33
src/http.c
33
src/http.c
@ -580,21 +580,44 @@ http_serveable(struct http_request *req, const void *data, size_t len,
|
||||
}
|
||||
|
||||
void
|
||||
http_response(struct http_request *req, int status, const void *d, size_t l)
|
||||
http_response(struct http_request *req, int code, const void *d, size_t l)
|
||||
{
|
||||
if (req->owner == NULL)
|
||||
return;
|
||||
|
||||
kore_debug("http_response(%p, %d, %p, %zu)", req, status, d, l);
|
||||
kore_debug("%s(%p, %d, %p, %zu)", __func__, req, code, d, l);
|
||||
|
||||
req->status = code;
|
||||
|
||||
req->status = status;
|
||||
switch (req->owner->proto) {
|
||||
case CONN_PROTO_HTTP:
|
||||
case CONN_PROTO_WEBSOCKET:
|
||||
http_response_normal(req, req->owner, status, d, l);
|
||||
http_response_normal(req, req->owner, code, d, l);
|
||||
break;
|
||||
default:
|
||||
fatal("http_response() bad proto %d", req->owner->proto);
|
||||
fatal("%s: bad proto %d", __func__, req->owner->proto);
|
||||
/* NOTREACHED. */
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
http_response_close(struct http_request *req, int code, const void *d, size_t l)
|
||||
{
|
||||
if (req->owner == NULL)
|
||||
return;
|
||||
|
||||
kore_debug("%s(%p, %d, %p, %zu)", __func__, req, code, d, l);
|
||||
|
||||
req->status = code;
|
||||
req->owner->flags |= CONN_CLOSE_EMPTY;
|
||||
|
||||
switch (req->owner->proto) {
|
||||
case CONN_PROTO_HTTP:
|
||||
case CONN_PROTO_WEBSOCKET:
|
||||
http_response_normal(req, req->owner, code, d, l);
|
||||
break;
|
||||
default:
|
||||
fatal("%s: bad proto %d", __func__, req->owner->proto);
|
||||
/* NOTREACHED. */
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user