Apache HTTPD
h2_headers.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <assert.h>
18#include <stdio.h>
19
20#include <apr_strings.h>
21
22#include <httpd.h>
23#include <http_core.h>
24#include <http_log.h>
25#include <util_time.h>
26
27#include <nghttp2/nghttp2.h>
28
29#include "h2_private.h"
30#include "h2_protocol.h"
31#include "h2_config.h"
32#include "h2_util.h"
33#include "h2_request.h"
34#include "h2_headers.h"
35
36#if !AP_HAS_RESPONSE_BUCKETS
37
38static int is_unsafe(server_rec *s)
39{
40 core_server_config *conf = ap_get_core_module_config(s->module_config);
42}
43
48
49static apr_status_t bucket_read(apr_bucket *b, const char **str,
51{
52 (void)b;
53 (void)block;
54 *str = NULL;
55 *len = 0;
56 return APR_SUCCESS;
57}
58
60{
62
63 br = apr_bucket_alloc(sizeof(*br), b->list);
64 br->headers = r;
65
66 b = apr_bucket_shared_make(b, br, 0, 0);
68 b->length = 0;
69
70 return b;
71}
72
84
86{
88 return ((h2_bucket_headers *)b->data)->headers;
89 }
90 return NULL;
91}
92
93static void bucket_destroy(void *data)
94{
96
99 }
100}
101
110
117
118
120 const apr_table_t *notes, apr_off_t raw_bytes,
122{
123 h2_headers *headers = apr_pcalloc(pool, sizeof(h2_headers));
124 headers->status = status;
125 headers->headers = (headers_in? apr_table_clone(pool, headers_in)
126 : apr_table_make(pool, 5));
127 headers->notes = (notes? apr_table_clone(pool, notes)
128 : apr_table_make(pool, 5));
129 return headers;
130}
131
132static int add_header_lengths(void *ctx, const char *name, const char *value)
133{
135 *plen += strlen(name) + strlen(value);
136 return 1;
137}
138
140{
141 apr_size_t len = 0;
143 return len;
144}
145
151
153 const apr_table_t *header, apr_pool_t *pool)
154{
155 h2_headers *headers = h2_headers_create(status, header, r->notes, 0, pool);
157 "h2_headers_rcreate(%ld): status=%d",
158 (long)r->connection->id, status);
159 if (headers->status == HTTP_FORBIDDEN) {
161 for (r_prev = r; r_prev != NULL; r_prev = r_prev->prev) {
162 const char *cause = apr_table_get(r_prev->notes, "ssl-renegotiate-forbidden");
163 if (cause) {
164 /* This request triggered a TLS renegotiation that is not allowed
165 * in HTTP/2. Tell the client that it should use HTTP/1.1 for this.
166 */
168 APLOGNO(10399)
169 "h2_headers(%ld): renegotiate forbidden, cause: %s",
170 (long)r->connection->id, cause);
172 break;
173 }
174 }
175 }
176 if (is_unsafe(r->server)) {
178 }
180 apr_table_setn(headers->notes, H2_PUSH_MODE_NOTE, "0");
181 }
182 return headers;
183}
184
186{
187 return h2_headers_create(h->status, h->headers, h->notes, h->raw_bytes, pool);
188}
189
191{
192 return h2_headers_create(h->status, h->headers, h->notes, h->raw_bytes, pool);
193}
194
196 const h2_request *req, apr_pool_t *pool)
197{
198 h2_headers *headers;
199 char *date;
200
201 headers = apr_pcalloc(pool, sizeof(h2_headers));
202 headers->status = (type >= 200 && type < 600)? type : 500;
203 headers->headers = apr_table_make(pool, 5);
204 headers->notes = apr_table_make(pool, 5);
205
208 apr_table_setn(headers->headers, "Date", date);
209 apr_table_setn(headers->headers, "Server", ap_get_server_banner());
210
211 return headers;
212}
213
215{
216 return headers->status >= 200;
217}
218
219#endif /* !AP_HAS_RESPONSE_BUCKETS */
const char apr_size_t len
Definition ap_regex.h:187
APR Strings library.
request_rec * r
const char * ap_get_server_banner(void)
Definition core.c:3593
#define ap_get_core_module_config(v)
Definition http_core.h:383
#define APLOGNO(n)
Definition http_log.h:117
#define ap_log_rerror
Definition http_log.h:454
#define APLOG_MARK
Definition http_log.h:283
#define APLOG_TRACE1
Definition http_log.h:72
#define APLOG_DEBUG
Definition http_log.h:71
apr_status_t ap_recent_rfc822_date(char *date_str, apr_time_t t)
Definition util_time.c:282
#define APR_BUCKET_INIT(e)
apr_read_type_e
Definition apr_buckets.h:57
apr_brigade_flush void * ctx
#define HTTP_FORBIDDEN
Definition httpd.h:511
apr_size_t size
const char int apr_pool_t * pool
Definition apr_cstr.h:84
const apr_array_header_t * list
Definition apr_cstr.h:105
const char * value
Definition apr_env.h:51
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
void * data
int type
const apr_hash_t * h
Definition apr_hash.h:97
apr_pool_t * b
Definition apr_pools.h:529
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
const char * s
Definition apr_strings.h:95
int int status
#define APR_RFC822_DATE_LEN
Definition apr_time.h:186
#define H2_ERR_HTTP_1_1_REQUIRED
Definition h2.h:71
#define H2_PUSH_MODE_NOTE
Definition h2.h:200
#define H2_HDR_CONFORMANCE_UNSAFE
Definition h2.h:199
#define H2_HDR_CONFORMANCE
Definition h2.h:198
int h2_config_rgeti(request_rec *r, h2_config_var_t var)
Definition h2_config.c:527
int h2_config_sgeti(server_rec *s, h2_config_var_t var)
Definition h2_config.c:506
@ H2_CONF_PUSH
Definition h2_config.h:38
h2_headers * h2_headers_copy(apr_pool_t *pool, h2_headers *h)
Definition h2_headers.c:185
static int is_unsafe(server_rec *s)
Definition h2_headers.c:38
static void bucket_destroy(void *data)
Definition h2_headers.c:93
apr_bucket * h2_bucket_headers_clone(apr_bucket *b, apr_pool_t *pool, apr_bucket_alloc_t *list)
Definition h2_headers.c:111
h2_headers * h2_headers_die(apr_status_t type, const h2_request *req, apr_pool_t *pool)
Definition h2_headers.c:195
int h2_headers_are_final_response(h2_headers *headers)
Definition h2_headers.c:214
h2_headers * h2_headers_clone(apr_pool_t *pool, h2_headers *h)
Definition h2_headers.c:190
apr_size_t h2_headers_length(h2_headers *headers)
Definition h2_headers.c:139
static int add_header_lengths(void *ctx, const char *name, const char *value)
Definition h2_headers.c:132
h2_headers * h2_bucket_headers_get(apr_bucket *b)
Definition h2_headers.c:85
static apr_status_t bucket_read(apr_bucket *b, const char **str, apr_size_t *len, apr_read_type_e block)
Definition h2_headers.c:49
const apr_bucket_type_t h2_bucket_type_headers
Definition h2_headers.c:102
apr_size_t h2_bucket_headers_headers_length(apr_bucket *b)
Definition h2_headers.c:146
h2_headers * h2_headers_rcreate(request_rec *r, int status, const apr_table_t *header, apr_pool_t *pool)
Definition h2_headers.c:152
h2_headers * h2_headers_create(int status, const apr_table_t *headers_in, const apr_table_t *notes, apr_off_t raw_bytes, apr_pool_t *pool)
Definition h2_headers.c:119
apr_bucket * h2_bucket_headers_make(apr_bucket *b, h2_headers *r)
Definition h2_headers.c:59
apr_bucket * h2_bucket_headers_create(apr_bucket_alloc_t *list, h2_headers *r)
Definition h2_headers.c:73
#define H2_BUCKET_IS_HEADERS(e)
Definition h2_headers.h:37
CORE HTTP Daemon.
#define AP_HTTP_CONFORMANCE_UNSAFE
Definition http_core.h:746
Apache Logging library.
HTTP Daemon routines.
return NULL
Definition mod_so.c:359
char * name
long id
Definition httpd.h:1187
apr_bucket_refcount refcount
Definition h2_headers.c:45
h2_headers * headers
Definition h2_headers.c:46
apr_table_t * headers
Definition h2_headers.h:29
apr_table_t * notes
Definition h2_headers.h:30
apr_time_t request_time
Definition h2.h:177
A structure that represents the current request.
Definition httpd.h:845
request_rec * prev
Definition httpd.h:856
apr_table_t * notes
Definition httpd.h:985
conn_rec * connection
Definition httpd.h:849
server_rec * server
Definition httpd.h:851
A structure to store information for each virtual server.
Definition httpd.h:1322
#define str
Apache date-time handling functions.