Repository navigation
feat(sip): keep a Status-Line's custom reason phrase as Response::wire_reason - #191
Merged
yeoleobun merged 1 commit intoOct 8, 2026
Merged
Conversation
…e_reason A response such as "SIP/2.0 403 Caller Origination Number is Invalid" parsed to StatusCode::Forbidden and the phrase was dropped: it was not kept anywhere in the parsed Response. Parsed responses now keep a phrase that differs from the standard text of a known code in the new Response::wire_reason field. The standard phrase (compared case-insensitively), an empty phrase, an unknown code (StatusCode::Other already keeps its phrase) and every locally built response leave it None. Display and to_bytes still write the standard phrase, so nothing changes on the wire.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #190.
Problem
parse_response_line(src/sip/parser.rs:103) passes the Status-Line's reason phrase toStatusCode::try_from((code, reason)), which keeps it only for an unknown code (StatusCode::Other,src/sip/status_code.rs:330). For a known code the phrase is dropped, soSIP/2.0 403 Caller Origination Number is Invalidbecomes aResponsewithStatusCode::Forbiddenand nothing else. Far ends often explain a refusal only in that phrase (RFC 3261 §7.2, §21: the phrase is a textual description, the listed ones are only recommendations), and an application has no way to read it:Response::reason_phrase()returns the Reason header, and theMessageInspectorhooks see the already parsed message.Change
A new public field on
Response:parse_response_linesets it;Default,make_responseand the dialog's response builder setNone. The rest of the diff iswire_reason: Nonein the existingResponse { .. }literals (2 insrc, 23 in tests). About 25 lines of library code; the rest is tests.Contract
status_codewire_reason403 Caller Origination Number is InvalidForbiddenSome("Caller Origination Number is Invalid")503 \tOverloaded Try LaterServiceUnavailableSome("Overloaded Try Later")(trimmed)403 Forbidden,486 busy here(standard text, any case)None404,404(no phrase)None499 Odd Thing(unknown code)Other(499, "Odd Thing")as beforeNoneResponse::default()NoneUnchanged on purpose:
Displayandto_bytesstill write the standard text, so a response that is forwarded or rebuilt from a received one sends exactly what it sent before.StatusCodeand its equality:Forbiddenis stillForbiddenwhatever the phrase.Points to note:
TryFromforSipMessage/Responsegoes throughparse_response_line, so the field is set the same way for all of them.ResponsederivesPartialEq, so two parsed responses that differ only in a custom phrase now compare unequal. Nothing in the library compares whole responses (retransmission matching compares status and body).Response { .. }literals that do not use..Default::default(), as addingCredential::auth_usernamedid. A private field with an accessor would break every outside literal, so a public field is the smaller change.reason_phraseis taken by the method that reads the Reason header, so this useswire_reason. Happy to rename it (for examplestatus_line_reason).Tests
src/sip/parser.rs:a_custom_reason_phrase_is_kept_beside_the_standard_code: the 403 above keepsForbiddenand the phrase,to_string()andto_bytes()still start withSIP/2.0 403 Forbidden, and surrounding spaces and tabs are trimmed.the_standard_phrase_or_none_keeps_no_wire_reason: standard text, a case variant, no phrase, an empty phrase, an unknown code (its phrase still inStatusCode::Other) andResponse::default()giveNone.On
main(2dfa0d1) the phrase is not in the parsed message at all; a probe asserting it appears in theDebugorDisplayoutput fails:Checks
cargo test --features bench: 412 lib tests passed, 0 failed (410 onmainplus the 2 new ones), and 65 doc tests passed. Plaincargo testpasses too.cargo check --no-default-features --features platform-embassy: the same output as onmain.cargo clippy --features bench --all-targets: the same output as onmain, none in the changed code. (Onmainit stops at aclippy::never_looperror, unrelated to this PR; with-A clippy::never_loopthe warnings are the same as onmain.)rustfmt --checkon the changed files: clean.