comparison src/http/ngx_http_spdy.c @ 5687:6642690698f1

SPDY: improved ngx_http_spdy_state_protocol_error(). Now ngx_http_spdy_state_protocol_error() is able to close stream, so there is no need in a separate call for this. Also fixed zero status code in logs for some cases.
author Valentin Bartenev <vbart@nginx.com>
date Wed, 30 Apr 2014 20:33:58 +0400
parents 5cf537731218
children 86232c95623d
comparison
equal deleted inserted replaced
5686:5cf537731218 5687:6642690698f1
1039 z = inflateSetDictionary(&sc->zstream_in, ngx_http_spdy_dict, 1039 z = inflateSetDictionary(&sc->zstream_in, ngx_http_spdy_dict,
1040 sizeof(ngx_http_spdy_dict)); 1040 sizeof(ngx_http_spdy_dict));
1041 if (z != Z_OK) { 1041 if (z != Z_OK) {
1042 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, 1042 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
1043 "spdy inflateSetDictionary() failed: %d", z); 1043 "spdy inflateSetDictionary() failed: %d", z);
1044 ngx_http_spdy_close_stream(sc->stream, 0); 1044
1045 return ngx_http_spdy_state_protocol_error(sc); 1045 return ngx_http_spdy_state_protocol_error(sc);
1046 } 1046 }
1047 1047
1048 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 1048 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1049 "spdy inflateSetDictionary(): %d", z); 1049 "spdy inflateSetDictionary(): %d", z);
1053 } 1053 }
1054 1054
1055 if (z != Z_OK) { 1055 if (z != Z_OK) {
1056 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, 1056 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
1057 "spdy inflate() failed: %d", z); 1057 "spdy inflate() failed: %d", z);
1058 ngx_http_spdy_close_stream(sc->stream, 0); 1058
1059 return ngx_http_spdy_state_protocol_error(sc); 1059 return ngx_http_spdy_state_protocol_error(sc);
1060 } 1060 }
1061 1061
1062 ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 1062 ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1063 "spdy inflate out: ni:%p no:%p ai:%ud ao:%ud rc:%d", 1063 "spdy inflate out: ni:%p no:%p ai:%ud ao:%ud rc:%d",
1076 1076
1077 if (complete) { 1077 if (complete) {
1078 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, 1078 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
1079 "client sent SYN_STREAM frame " 1079 "client sent SYN_STREAM frame "
1080 "with invalid HEADERS block"); 1080 "with invalid HEADERS block");
1081 ngx_http_spdy_close_stream(sc->stream, NGX_HTTP_BAD_REQUEST); 1081
1082 return ngx_http_spdy_state_protocol_error(sc); 1082 return ngx_http_spdy_state_protocol_error(sc);
1083 } 1083 }
1084 1084
1085 return ngx_http_spdy_state_save(sc, pos, end, 1085 return ngx_http_spdy_state_save(sc, pos, end,
1086 ngx_http_spdy_state_headers); 1086 ngx_http_spdy_state_headers);
1157 z = inflate(&sc->zstream_in, Z_NO_FLUSH); 1157 z = inflate(&sc->zstream_in, Z_NO_FLUSH);
1158 1158
1159 if (z != Z_OK) { 1159 if (z != Z_OK) {
1160 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, 1160 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
1161 "spdy inflate() failed: %d", z); 1161 "spdy inflate() failed: %d", z);
1162 ngx_http_spdy_close_stream(sc->stream, 0); 1162
1163 return ngx_http_spdy_state_protocol_error(sc); 1163 return ngx_http_spdy_state_protocol_error(sc);
1164 } 1164 }
1165 1165
1166 sc->length -= sc->zstream_in.next_in - pos; 1166 sc->length -= sc->zstream_in.next_in - pos;
1167 pos = sc->zstream_in.next_in; 1167 pos = sc->zstream_in.next_in;
1173 1173
1174 if (complete) { 1174 if (complete) {
1175 /* TODO: improve error message */ 1175 /* TODO: improve error message */
1176 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 1176 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1177 "spdy again while last chunk"); 1177 "spdy again while last chunk");
1178 ngx_http_spdy_close_stream(sc->stream, 0); 1178
1179 return ngx_http_spdy_state_protocol_error(sc); 1179 return ngx_http_spdy_state_protocol_error(sc);
1180 } 1180 }
1181 1181
1182 return ngx_http_spdy_state_save(sc, pos, end, 1182 return ngx_http_spdy_state_save(sc, pos, end,
1183 ngx_http_spdy_state_headers); 1183 ngx_http_spdy_state_headers);
1194 1194
1195 default: /* NGX_HTTP_PARSE_INVALID_HEADER */ 1195 default: /* NGX_HTTP_PARSE_INVALID_HEADER */
1196 1196
1197 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, 1197 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
1198 "client sent invalid HEADERS spdy frame"); 1198 "client sent invalid HEADERS spdy frame");
1199 ngx_http_spdy_close_stream(sc->stream, NGX_HTTP_BAD_REQUEST); 1199
1200 return ngx_http_spdy_state_protocol_error(sc); 1200 return ngx_http_spdy_state_protocol_error(sc);
1201 } 1201 }
1202 1202
1203 /* a header line has been parsed successfully */ 1203 /* a header line has been parsed successfully */
1204 1204
1206 1206
1207 if (rc != NGX_OK) { 1207 if (rc != NGX_OK) {
1208 if (rc == NGX_HTTP_PARSE_INVALID_HEADER) { 1208 if (rc == NGX_HTTP_PARSE_INVALID_HEADER) {
1209 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, 1209 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
1210 "client sent invalid HEADERS spdy frame"); 1210 "client sent invalid HEADERS spdy frame");
1211 ngx_http_spdy_close_stream(sc->stream, NGX_HTTP_BAD_REQUEST); 1211
1212 return ngx_http_spdy_state_protocol_error(sc); 1212 return ngx_http_spdy_state_protocol_error(sc);
1213 } 1213 }
1214 1214
1215 if (rc == NGX_HTTP_PARSE_INVALID_REQUEST) { 1215 if (rc == NGX_HTTP_PARSE_INVALID_REQUEST) {
1216 ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST); 1216 ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
1222 1222
1223 if (buf->pos != buf->last || sc->zstream_in.avail_in) { 1223 if (buf->pos != buf->last || sc->zstream_in.avail_in) {
1224 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, 1224 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
1225 "client sent SYN_STREAM frame " 1225 "client sent SYN_STREAM frame "
1226 "with invalid HEADERS block"); 1226 "with invalid HEADERS block");
1227 ngx_http_spdy_close_stream(sc->stream, NGX_HTTP_BAD_REQUEST); 1227
1228 return ngx_http_spdy_state_protocol_error(sc); 1228 return ngx_http_spdy_state_protocol_error(sc);
1229 } 1229 }
1230 1230
1231 if (!complete) { 1231 if (!complete) {
1232 return ngx_http_spdy_state_save(sc, pos, end, 1232 return ngx_http_spdy_state_save(sc, pos, end,
1892 static u_char * 1892 static u_char *
1893 ngx_http_spdy_state_complete(ngx_http_spdy_connection_t *sc, u_char *pos, 1893 ngx_http_spdy_state_complete(ngx_http_spdy_connection_t *sc, u_char *pos,
1894 u_char *end) 1894 u_char *end)
1895 { 1895 {
1896 sc->handler = ngx_http_spdy_state_head; 1896 sc->handler = ngx_http_spdy_state_head;
1897 sc->stream = NULL;
1898
1897 return pos; 1899 return pos;
1898 } 1900 }
1899 1901
1900 1902
1901 static u_char * 1903 static u_char *
1927 ngx_http_spdy_state_protocol_error(ngx_http_spdy_connection_t *sc) 1929 ngx_http_spdy_state_protocol_error(ngx_http_spdy_connection_t *sc)
1928 { 1930 {
1929 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, sc->connection->log, 0, 1931 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, sc->connection->log, 0,
1930 "spdy state protocol error"); 1932 "spdy state protocol error");
1931 1933
1932 /* TODO */ 1934 if (sc->stream) {
1935 ngx_http_spdy_close_stream(sc->stream, NGX_HTTP_BAD_REQUEST);
1936 }
1937
1933 ngx_http_spdy_finalize_connection(sc, NGX_HTTP_CLIENT_CLOSED_REQUEST); 1938 ngx_http_spdy_finalize_connection(sc, NGX_HTTP_CLIENT_CLOSED_REQUEST);
1939
1934 return NULL; 1940 return NULL;
1935 } 1941 }
1936 1942
1937 1943
1938 static u_char * 1944 static u_char *