mirror of
https://github.com/abapGit/abapGit.git
synced 2025-05-02 04:36:49 +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
|
receive TYPE string VALUE 'receive', "#EC NOTEXT
|
||||||
upload TYPE string VALUE 'upload', "#EC NOTEXT
|
upload TYPE string VALUE 'upload', "#EC NOTEXT
|
||||||
END OF c_service.
|
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
|
CLASS-METHODS branch_list
|
||||||
IMPORTING iv_url TYPE string
|
IMPORTING iv_url TYPE string
|
||||||
|
@ -83,12 +89,19 @@ CLASS zcl_abapgit_git_transport IMPLEMENTATION.
|
||||||
METHOD branch_list.
|
METHOD branch_list.
|
||||||
|
|
||||||
DATA: lv_data TYPE string.
|
DATA: lv_data TYPE string.
|
||||||
|
DATA: lv_expected_content_type TYPE string.
|
||||||
|
|
||||||
eo_client = zcl_abapgit_http=>create_by_url(
|
eo_client = zcl_abapgit_http=>create_by_url(
|
||||||
iv_url = iv_url
|
iv_url = iv_url
|
||||||
iv_service = iv_service ).
|
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( ).
|
lv_data = eo_client->get_cdata( ).
|
||||||
|
|
||||||
CREATE OBJECT eo_branch_list
|
CREATE OBJECT eo_branch_list
|
||||||
|
|
|
@ -9,15 +9,17 @@ CLASS zcl_abapgit_http_client DEFINITION PUBLIC CREATE PUBLIC.
|
||||||
set_digest
|
set_digest
|
||||||
IMPORTING io_digest TYPE REF TO zcl_abapgit_http_digest,
|
IMPORTING io_digest TYPE REF TO zcl_abapgit_http_digest,
|
||||||
send_receive_close
|
send_receive_close
|
||||||
IMPORTING
|
IMPORTING iv_data TYPE xstring
|
||||||
iv_data TYPE xstring
|
RETURNING VALUE(rv_data) TYPE xstring
|
||||||
RETURNING
|
|
||||||
VALUE(rv_data) TYPE xstring
|
|
||||||
RAISING zcx_abapgit_exception,
|
RAISING zcx_abapgit_exception,
|
||||||
get_cdata
|
get_cdata
|
||||||
RETURNING VALUE(rv_value) TYPE string,
|
RETURNING VALUE(rv_value) TYPE string,
|
||||||
check_http_200
|
check_http_200
|
||||||
RAISING zcx_abapgit_exception,
|
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
|
send_receive
|
||||||
RAISING zcx_abapgit_exception,
|
RAISING zcx_abapgit_exception,
|
||||||
set_headers
|
set_headers
|
||||||
|
@ -33,7 +35,7 @@ ENDCLASS.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CLASS ZCL_ABAPGIT_HTTP_CLIENT IMPLEMENTATION.
|
CLASS zcl_abapgit_http_client IMPLEMENTATION.
|
||||||
|
|
||||||
|
|
||||||
METHOD check_http_200.
|
METHOD check_http_200.
|
||||||
|
@ -41,7 +43,6 @@ CLASS ZCL_ABAPGIT_HTTP_CLIENT IMPLEMENTATION.
|
||||||
DATA: lv_code TYPE i,
|
DATA: lv_code TYPE i,
|
||||||
lv_text TYPE string.
|
lv_text TYPE string.
|
||||||
|
|
||||||
|
|
||||||
mi_client->response->get_status(
|
mi_client->response->get_status(
|
||||||
IMPORTING
|
IMPORTING
|
||||||
code = lv_code ).
|
code = lv_code ).
|
||||||
|
@ -66,6 +67,29 @@ CLASS ZCL_ABAPGIT_HTTP_CLIENT IMPLEMENTATION.
|
||||||
ENDMETHOD. "http_200
|
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.
|
METHOD close.
|
||||||
mi_client->close( ).
|
mi_client->close( ).
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user