mirror of
https://github.com/abapGit/abapGit.git
synced 2025-05-01 12:20:51 +08:00
add smart response checks for ref discovery (#1942)
* add smart response checks for ref discovery Added content-type check and content regex check for reference discovery see https://github.com/schacon/igithub/blob/master/http-protocol.txt * move ref check constants to TRANSPORT class the check constants - content regex and responce Content-Type - don't have to be global right now so moved from zif_abapgit_definitionsto zcl_abapgit_git_transport * PP and activate
This commit is contained in:
parent
d21bbb6caa
commit
ab1fce00fe
|
@ -33,6 +33,12 @@ CLASS zcl_abapgit_git_transport DEFINITION
|
|||
receive TYPE string VALUE 'receive', "#EC NOTEXT
|
||||
upload TYPE string VALUE 'upload', "#EC NOTEXT
|
||||
END OF c_service.
|
||||
CONSTANTS: BEGIN OF c_smart_response_check,
|
||||
BEGIN OF get_refs,
|
||||
content_regex TYPE string VALUE '^[0-9a-f]{4}#',
|
||||
content_type TYPE string VALUE 'application/x-git-<service>-pack-advertisement',
|
||||
END OF get_refs,
|
||||
END OF c_smart_response_check.
|
||||
|
||||
CLASS-METHODS branch_list
|
||||
IMPORTING iv_url TYPE string
|
||||
|
@ -83,12 +89,19 @@ CLASS zcl_abapgit_git_transport IMPLEMENTATION.
|
|||
METHOD branch_list.
|
||||
|
||||
DATA: lv_data TYPE string.
|
||||
|
||||
DATA: lv_expected_content_type TYPE string.
|
||||
|
||||
eo_client = zcl_abapgit_http=>create_by_url(
|
||||
iv_url = iv_url
|
||||
iv_service = iv_service ).
|
||||
|
||||
lv_expected_content_type = c_smart_response_check-get_refs-content_type.
|
||||
REPLACE '<service>' IN lv_expected_content_type WITH iv_service.
|
||||
|
||||
eo_client->check_smart_response(
|
||||
iv_expected_content_type = lv_expected_content_type
|
||||
iv_content_regex = c_smart_response_check-get_refs-content_regex ).
|
||||
|
||||
lv_data = eo_client->get_cdata( ).
|
||||
|
||||
CREATE OBJECT eo_branch_list
|
||||
|
|
|
@ -9,15 +9,17 @@ CLASS zcl_abapgit_http_client DEFINITION PUBLIC CREATE PUBLIC.
|
|||
set_digest
|
||||
IMPORTING io_digest TYPE REF TO zcl_abapgit_http_digest,
|
||||
send_receive_close
|
||||
IMPORTING
|
||||
iv_data TYPE xstring
|
||||
RETURNING
|
||||
VALUE(rv_data) TYPE xstring
|
||||
IMPORTING iv_data TYPE xstring
|
||||
RETURNING VALUE(rv_data) TYPE xstring
|
||||
RAISING zcx_abapgit_exception,
|
||||
get_cdata
|
||||
RETURNING VALUE(rv_value) TYPE string,
|
||||
check_http_200
|
||||
RAISING zcx_abapgit_exception,
|
||||
check_smart_response
|
||||
IMPORTING iv_expected_content_type TYPE string
|
||||
iv_content_regex TYPE string
|
||||
RAISING zcx_abapgit_exception,
|
||||
send_receive
|
||||
RAISING zcx_abapgit_exception,
|
||||
set_headers
|
||||
|
@ -33,7 +35,7 @@ ENDCLASS.
|
|||
|
||||
|
||||
|
||||
CLASS ZCL_ABAPGIT_HTTP_CLIENT IMPLEMENTATION.
|
||||
CLASS zcl_abapgit_http_client IMPLEMENTATION.
|
||||
|
||||
|
||||
METHOD check_http_200.
|
||||
|
@ -41,7 +43,6 @@ CLASS ZCL_ABAPGIT_HTTP_CLIENT IMPLEMENTATION.
|
|||
DATA: lv_code TYPE i,
|
||||
lv_text TYPE string.
|
||||
|
||||
|
||||
mi_client->response->get_status(
|
||||
IMPORTING
|
||||
code = lv_code ).
|
||||
|
@ -66,6 +67,29 @@ CLASS ZCL_ABAPGIT_HTTP_CLIENT IMPLEMENTATION.
|
|||
ENDMETHOD. "http_200
|
||||
|
||||
|
||||
METHOD check_smart_response.
|
||||
|
||||
DATA: lv_content_type TYPE string.
|
||||
DATA: lv_data TYPE string.
|
||||
|
||||
IF iv_expected_content_type IS NOT INITIAL.
|
||||
lv_content_type = mi_client->response->get_content_type( ).
|
||||
IF lv_content_type <> iv_expected_content_type.
|
||||
zcx_abapgit_exception=>raise( 'Wrong Content-Type sent by server - no fallback to the dumb protocol!' ).
|
||||
ENDIF.
|
||||
ENDIF.
|
||||
|
||||
IF iv_content_regex IS NOT INITIAL.
|
||||
lv_data = mi_client->response->get_cdata( ).
|
||||
FIND REGEX iv_content_regex IN lv_data.
|
||||
IF sy-subrc <> 0.
|
||||
zcx_abapgit_exception=>raise( 'Wrong Content sent by server' ).
|
||||
ENDIF.
|
||||
ENDIF.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD close.
|
||||
mi_client->close( ).
|
||||
ENDMETHOD.
|
||||
|
|
Loading…
Reference in New Issue
Block a user