export go_write_headers
(threadIndex C.uintptr_t, status C.int, headers *C.zend_llist)
| 551 | |
| 552 | //export go_write_headers |
| 553 | func go_write_headers(threadIndex C.uintptr_t, status C.int, headers *C.zend_llist) C.bool { |
| 554 | thread := phpThreads[threadIndex] |
| 555 | fc := thread.frankenPHPContext() |
| 556 | if fc == nil { |
| 557 | return C.bool(false) |
| 558 | } |
| 559 | |
| 560 | if fc.isDone { |
| 561 | return C.bool(false) |
| 562 | } |
| 563 | |
| 564 | if fc.responseWriter == nil { |
| 565 | // probably starting a worker script, pretend we wrote headers so PHP still calls ub_write |
| 566 | return C.bool(true) |
| 567 | } |
| 568 | |
| 569 | current := headers.head |
| 570 | for current != nil { |
| 571 | h := (*C.sapi_header_struct)(unsafe.Pointer(&(current.data))) |
| 572 | |
| 573 | addHeader(thread.context(), fc, h) |
| 574 | current = current.next |
| 575 | } |
| 576 | |
| 577 | goStatus := int(status) |
| 578 | |
| 579 | // go panics on invalid status code |
| 580 | // https://github.com/golang/go/blob/9b8742f2e79438b9442afa4c0a0139d3937ea33f/src/net/http/server.go#L1162 |
| 581 | if goStatus < 100 || goStatus > 999 { |
| 582 | ctx := thread.context() |
| 583 | |
| 584 | if globalLogger.Enabled(ctx, slog.LevelWarn) { |
| 585 | globalLogger.LogAttrs(ctx, slog.LevelWarn, "Invalid response status code", slog.Int("status_code", goStatus)) |
| 586 | } |
| 587 | |
| 588 | goStatus = 500 |
| 589 | } |
| 590 | |
| 591 | fc.responseWriter.WriteHeader(goStatus) |
| 592 | |
| 593 | if goStatus < 200 { |
| 594 | // Clear headers, it's not automatically done by ResponseWriter.WriteHeader() for 1xx responses |
| 595 | h := fc.responseWriter.Header() |
| 596 | for k := range h { |
| 597 | delete(h, k) |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | return C.bool(true) |
| 602 | } |
| 603 | |
| 604 | //export go_sapi_flush |
| 605 | func go_sapi_flush(threadIndex C.uintptr_t) bool { |
nothing calls this directly
no test coverage detected