}
}
+/**
+ * RFC8187 (RFC5987) HTTP Header non-ASCII field encoding
+ */
+void
+htsbuf_append_and_escape_rfc8187(htsbuf_queue_t *hq, const char *s)
+{
+ const char *c = s;
+ const char *e = s + strlen(s);
+ char C;
+ if(e == s)
+ return;
+
+ while(1) {
+ const char *esc;
+ char buf[4];
+ C = *c++;
+
+ /* RFC 8187, section 3.2.1, attr-char */
+ if((C >= '0' && C <= '9') ||
+ (C >= 'a' && C <= 'z') ||
+ (C >= 'A' && C <= 'Z') ||
+ C == '!' ||
+ C == '#' ||
+ C == '$' ||
+ C == '&' ||
+ C == '+' ||
+ C == '-' ||
+ C == '.' ||
+ C == '^' ||
+ C == '_' ||
+ C == '`' ||
+ C == '|' ||
+ C == '~') {
+ esc = NULL;
+ } else {
+ static const char hexchars[16] = "0123456789ABCDEF";
+ buf[0] = '%';
+ buf[1] = hexchars[(C >> 4) & 0xf];
+ buf[2] = hexchars[C & 0xf];
+ buf[3] = 0;
+ esc = buf;
+ }
+
+ if(esc != NULL) {
+ htsbuf_append(hq, s, c - s - 1);
+ htsbuf_append_str(hq, esc);
+ s = c;
+ }
+
+ if(c == e) {
+ htsbuf_append(hq, s, c - s);
+ break;
+ }
+ }
+}
/**
*
void htsbuf_append_and_escape_url(htsbuf_queue_t *hq, const char *s);
+void htsbuf_append_and_escape_rfc8187(htsbuf_queue_t *hq, const char *s);
+
void htsbuf_append_and_escape_jsonstr(htsbuf_queue_t *hq, const char *s);
void htsbuf_dump_raw_stderr(htsbuf_queue_t *hq);
return HTTP_STATUS_INTERNAL;
}
htsbuf_queue_init(&q, 0);
- htsbuf_append_and_escape_url(&q, basename);
+ htsbuf_append_and_escape_rfc8187(&q, basename);
str = htsbuf_to_string(&q);
r = 50 + strlen(str0) + strlen(str);
disposition = alloca(r);