/*1* nghttp2 - HTTP/2 C Library2*3* Copyright (c) 2015 Tatsuhiro Tsujikawa4*5* Permission is hereby granted, free of charge, to any person obtaining6* a copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sublicense, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice shall be14* included in all copies or substantial portions of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,17* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND19* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE20* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION21* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION22* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.23*/24#ifndef NGHTTP2_HTTP_H25#define NGHTTP2_HTTP_H2627#ifdef HAVE_CONFIG_H28# include <config.h>29#endif /* HAVE_CONFIG_H */3031#include <nghttp2/nghttp2.h>32#include "nghttp2_session.h"33#include "nghttp2_stream.h"3435/*36* This function is called when HTTP header field |nv| in |frame| is37* received for |stream|. This function will validate |nv| against38* the current state of stream.39*40* This function returns 0 if it succeeds, or one of the following41* negative error codes:42*43* NGHTTP2_ERR_HTTP_HEADER44* Invalid HTTP header field was received.45* NGHTTP2_ERR_IGN_HTTP_HEADER46* Invalid HTTP header field was received but it can be treated as47* if it was not received because of compatibility reasons.48*/49int nghttp2_http_on_header(nghttp2_session *session, nghttp2_stream *stream,50nghttp2_frame *frame, nghttp2_hd_nv *nv,51int trailer);5253/*54* This function is called when request header is received. This55* function performs validation and returns 0 if it succeeds, or -1.56*/57int nghttp2_http_on_request_headers(nghttp2_stream *stream,58nghttp2_frame *frame);5960/*61* This function is called when response header is received. This62* function performs validation and returns 0 if it succeeds, or -1.63*/64int nghttp2_http_on_response_headers(nghttp2_stream *stream);6566/*67* This function is called trailer header (for both request and68* response) is received. This function performs validation and69* returns 0 if it succeeds, or -1.70*/71int nghttp2_http_on_trailer_headers(nghttp2_stream *stream,72nghttp2_frame *frame);7374/*75* This function is called when END_STREAM flag is seen in incoming76* frame. This function performs validation and returns 0 if it77* succeeds, or -1.78*/79int nghttp2_http_on_remote_end_stream(nghttp2_stream *stream);8081/*82* This function is called when chunk of data is received. This83* function performs validation and returns 0 if it succeeds, or -1.84*/85int nghttp2_http_on_data_chunk(nghttp2_stream *stream, size_t n);8687/*88* This function inspects header field in |frame| and records its89* method in stream->http_flags. If frame->hd.type is neither90* NGHTTP2_HEADERS nor NGHTTP2_PUSH_PROMISE, this function does91* nothing.92*/93void nghttp2_http_record_request_method(nghttp2_stream *stream,94nghttp2_frame *frame);9596/*97* RFC 8941 Structured Field Values.98*/99typedef enum nghttp2_sf_value_type {100NGHTTP2_SF_VALUE_TYPE_BOOLEAN,101NGHTTP2_SF_VALUE_TYPE_INTEGER,102NGHTTP2_SF_VALUE_TYPE_DECIMAL,103NGHTTP2_SF_VALUE_TYPE_STRING,104NGHTTP2_SF_VALUE_TYPE_TOKEN,105NGHTTP2_SF_VALUE_TYPE_BYTESEQ,106NGHTTP2_SF_VALUE_TYPE_INNER_LIST,107} nghttp2_sf_value_type;108109/*110* nghttp2_sf_value stores Structured Field Values item. For Inner111* List, only type is set to NGHTTP2_SF_VALUE_TYPE_INNER_LIST.112*/113typedef struct nghttp2_sf_value {114uint8_t type;115union {116int b;117int64_t i;118double d;119struct {120const uint8_t *base;121size_t len;122} s;123};124} nghttp2_sf_value;125126/*127* nghttp2_sf_parse_item parses the input sequence [|begin|, |end|)128* and stores the parsed an Item in |dest|. It returns the number of129* bytes consumed if it succeeds, or -1. This function is declared130* here for unit tests.131*/132ssize_t nghttp2_sf_parse_item(nghttp2_sf_value *dest, const uint8_t *begin,133const uint8_t *end);134135/*136* nghttp2_sf_parse_inner_list parses the input sequence [|begin|, |end|)137* and stores the parsed an Inner List in |dest|. It returns the number of138* bytes consumed if it succeeds, or -1. This function is declared139* here for unit tests.140*/141ssize_t nghttp2_sf_parse_inner_list(nghttp2_sf_value *dest,142const uint8_t *begin, const uint8_t *end);143144int nghttp2_http_parse_priority(nghttp2_extpri *dest, const uint8_t *value,145size_t valuelen);146147#endif /* NGHTTP2_HTTP_H */148149150