nxt_php_sapi.c (421:b57f61ecf2ec) nxt_php_sapi.c (431:5817734dd9b9)
1
2/*
3 * Copyright (C) Max Romanov
4 * Copyright (C) Valentin V. Bartenev
5 * Copyright (C) NGINX, Inc.
6 */
7
8#include "php.h"

--- 491 unchanged lines hidden (view full) ---

500 size_t len;
501 u_char *status, buf[64];
502 nxt_int_t rc;
503 nxt_php_run_ctx_t *ctx;
504 sapi_header_struct *h;
505 zend_llist_position zpos;
506
507 static const u_char default_repsonse[]
1
2/*
3 * Copyright (C) Max Romanov
4 * Copyright (C) Valentin V. Bartenev
5 * Copyright (C) NGINX, Inc.
6 */
7
8#include "php.h"

--- 491 unchanged lines hidden (view full) ---

500 size_t len;
501 u_char *status, buf[64];
502 nxt_int_t rc;
503 nxt_php_run_ctx_t *ctx;
504 sapi_header_struct *h;
505 zend_llist_position zpos;
506
507 static const u_char default_repsonse[]
508 = "HTTP/1.1 200 OK\r\n"
509 "Server: unit/" NXT_VERSION "\r\n"
510 "Content-Type: text/html; charset=UTF-8\r\n"
511 "Connection: close\r\n"
508 = "Status: 200\r\n"
512 "\r\n";
513
509 "\r\n";
510
514 static const u_char default_headers[]
515 = "Server: unit/" NXT_VERSION "\r\n"
516 "Connection: close\r\n";
517
518 static const u_char http_11[] = "HTTP/1.1 ";
511 static const u_char status_200[] = "Status: 200";
519 static const u_char cr_lf[] = "\r\n";
512 static const u_char cr_lf[] = "\r\n";
520 static const u_char _200_ok[] = "200 OK";
521
522 ctx = SG(server_context);
523
524#define RC(S) \
525 do { \
526 rc = (S); \
527 if (nxt_slow_path(rc != NXT_OK)) { \
528 goto fail; \

--- 5 unchanged lines hidden (view full) ---

534 1, 0));
535 return SAPI_HEADER_SENT_SUCCESSFULLY;
536 }
537
538 if (SG(sapi_headers).http_status_line) {
539 status = (u_char *) SG(sapi_headers).http_status_line;
540 len = nxt_strlen(status);
541
513
514 ctx = SG(server_context);
515
516#define RC(S) \
517 do { \
518 rc = (S); \
519 if (nxt_slow_path(rc != NXT_OK)) { \
520 goto fail; \

--- 5 unchanged lines hidden (view full) ---

526 1, 0));
527 return SAPI_HEADER_SENT_SUCCESSFULLY;
528 }
529
530 if (SG(sapi_headers).http_status_line) {
531 status = (u_char *) SG(sapi_headers).http_status_line;
532 len = nxt_strlen(status);
533
542 RC(nxt_php_write(ctx, status, len, 0, 0));
534 if (len < 12) {
535 goto fail;
536 }
543
537
538 RC(nxt_php_write(ctx, status_200, sizeof(status_200) - 4, 0, 0));
539 RC(nxt_php_write(ctx, status + 9, 3, 0, 0));
540
544 } else if (SG(sapi_headers).http_response_code) {
545 status = nxt_sprintf(buf, buf + sizeof(buf), "%03d",
546 SG(sapi_headers).http_response_code);
547 len = status - buf;
548
541 } else if (SG(sapi_headers).http_response_code) {
542 status = nxt_sprintf(buf, buf + sizeof(buf), "%03d",
543 SG(sapi_headers).http_response_code);
544 len = status - buf;
545
549 RC(nxt_php_write(ctx, http_11, sizeof(http_11) - 1, 0, 0));
546 RC(nxt_php_write(ctx, status_200, sizeof(status_200) - 4, 0, 0));
550 RC(nxt_php_write(ctx, buf, len, 0, 0));
551
552 } else {
547 RC(nxt_php_write(ctx, buf, len, 0, 0));
548
549 } else {
553 RC(nxt_php_write(ctx, http_11, sizeof(http_11) - 1, 0, 0));
554 RC(nxt_php_write(ctx, _200_ok, sizeof(_200_ok) - 1, 0, 0));
550 RC(nxt_php_write(ctx, status_200, sizeof(status_200) - 1, 0, 0));
555 }
556
557 RC(nxt_php_write(ctx, cr_lf, sizeof(cr_lf) - 1, 0, 0));
551 }
552
553 RC(nxt_php_write(ctx, cr_lf, sizeof(cr_lf) - 1, 0, 0));
558 RC(nxt_php_write(ctx, default_headers, sizeof(default_headers) - 1, 0, 0));
559
560 h = zend_llist_get_first_ex(&sapi_headers->headers, &zpos);
561
562 while (h) {
563 RC(nxt_php_write(ctx, (u_char *) h->header, h->header_len, 0, 0));
564 RC(nxt_php_write(ctx, cr_lf, sizeof(cr_lf) - 1, 0, 0));
565
566 h = zend_llist_get_next_ex(&sapi_headers->headers, &zpos);

--- 193 unchanged lines hidden ---
554
555 h = zend_llist_get_first_ex(&sapi_headers->headers, &zpos);
556
557 while (h) {
558 RC(nxt_php_write(ctx, (u_char *) h->header, h->header_len, 0, 0));
559 RC(nxt_php_write(ctx, cr_lf, sizeof(cr_lf) - 1, 0, 0));
560
561 h = zend_llist_get_next_ex(&sapi_headers->headers, &zpos);

--- 193 unchanged lines hidden ---