summaryrefslogtreecommitdiff
path: root/src/libtipidee/tipidee_response_file.c
blob: 0cbe8f4571bd8fc514f60994a4869149b1c491f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* ISC license. */

#include <stddef.h>

#include <skalibs/types.h>
#include <skalibs/buffer.h>

#include <tipidee/conf.h>
#include <tipidee/method.h>
#include <tipidee/rql.h>
#include <tipidee/response.h>
#include <tipidee/util.h>

size_t tipidee_response_file (buffer *b, tipidee_rql const *rql, unsigned int status, char const *reason, struct stat const *st, char const *ct, uint32_t options, tain const *stamp)
{
  char fmt[128] ;
  size_t n = tipidee_response_status(b, rql, status, reason) ;
  n += tipidee_response_header_common_put(b, options & 1, stamp) ;
  if (options & 2)
  {
    size_t l = tipidee_response_header_lastmodified(fmt, 128, st) ;
    if (l) n += buffer_putnoflush(b, fmt, l) ;
  }
  n += buffer_putsnoflush(b, "Content-Type: ") ;
  n += buffer_putsnoflush(b, ct) ;
  n += buffer_putsnoflush(b, "\r\nContent-Length: ") ;
  fmt[uint64_fmt(fmt, st->st_size)] = 0 ;
  n += buffer_putsnoflush(b, fmt) ;
  n += buffer_putnoflush(b, "\r\n\r\n", 4) ;
  return n ;
}